http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59845
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- >(constant folding problem within loop?) No it is doing the following: if (n>=1) { i = 1; while (true) { if (n%i == 0) { printf("\n%d", i); i++; if (n/2 < i) break; } else { i++; if (n/2 < i) break; } } } Notice the load from n is not pulled out of the loop and that is because the compiler thinks n escapes via scanf.