Alexey Neyman wrote: > The problem is that with -O2, the second conditional gets optimized > away. However, such optimization results in a misbehavior for the > minimum number representable in 32 bits, 0x80000000. The option which > triggers this optimization is -ftree-vrp. Signed integer overflow is undefined in ISO C. If v = INT_MIN then v = -v is undefined, and hence the compiler can assume this won't occur and optimize away the test since a conformant program does not invoke undefined behavior. Yes, there is some debate around the legitimacy of this optimization because "traditional" C has more or less held that signed integer overflow is perfectly defined on all two's compliment machines (i.e. everywhere.) But the standard leaves it undefined and so gcc is within its right to do this optimization, so say the language lawyers. You may be interested in the options -fno-strict-overflow, -fwrapv, and -Wstrict-overflow. Brian