Created attachment 31231 [details] code demonstrating the issue Attached is a code which shows different results when compiled with -O2 (wrong) or -O1 (right). Initially it was -O2 -funroll-loops which triggered the issue, but after reducing the code further I managed to get the same result with -O1 vs -O2 without any additional options. Tested with debian gcc 4.7.2-5 x86-65 (wheezy), confirmed with 4.8.1-10 (debian/testing, also 64bits). 32bit code is not affected. The code does not have any preprocessor directives. I tried to reduce it further but it is a bit fragile - for example, removing a single call to free() makes the code generated to be correct.
-fno-strict-aliasing fixes it.
Not a bug then. 4.7 is obsolete anyway at this point.