Because the machine code generated may now be totally different. The kinds of optimization a compiler can perform are really, really extreme.
But assuming Im doing something wrong (I admit it have to be my fault), how can adding message boxes to the code make it work fine(make it behavior tottaly differently)?
Look for uninitialized variables (initialize everything at the point of definition, always, no exceptions). Add lots of asserts that remain enabled in release mode. Put them around the code you believe is misbehaving.