The two transactions:
a) https://etherscan.io/tx/0x9227f7b00bf2c98a7e16eb5ab90c04df5b49698297ee7f52c765d5218af395ad
b) https://etherscan.io/tx/0x1af76244391e06c375e8511f4140191fb874362b238aa9b6fdacc072e35cd778
are exactly the same but as you can see TX (a) failed as it used up all its available gas. The limit was set to 53,356. The second TX (b) is exactly the same but gas limit was set to 160,000 and the transaction succeeded. Although it used only 38,368 gas which is less than the limit of TX (a). But before I get answers like "some instructions take a different amount of gas depending on XYZ" I checked the execution of the contracts:
a) https://etherscan.io/vmtrace?txhash=0x9227f7b00bf2c98a7e16eb5ab90c04df5b49698297ee7f52c765d5218af395ad
b) https://etherscan.io/vmtrace?txhash=0x1af76244391e06c375e8511f4140191fb874362b238aa9b6fdacc072e35cd778
They seem to be doing the exact same thing with the exact same amounts of gas used. So why did the first transaction fail? And why does is say there's only 31700 gas to start with on TX (a)?