https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64294
--- Comment #9 from Sebastian Andrzej Siewior <gcc at breakpoint dot cc> --- I added the complete function including its callers. $ gcc -g -o petite petite.c -Wall -O2 $ ./petite 447=> 5 452=> 5 447=> 5 452=> 5 447=> 0 452=> 0 Segmentation fault --- $ gcc -g -o petite petite.c -Wall -O1 $ ./petite 447=> -12 ->1 ---- As you see the value in line 447 is different in -O2 vs -O1. And with -O2 it continues with 0 to start the loop. I have to run now, maybe I have later some time to figure out why the value in line 447 is different in -O2 vs -O1.