------- Comment #13 from steven at gcc dot gnu dot org 2008-01-12 14:34 ------- Re. comment #7, "Assignment to sum should be moved before if..."
This is called code hoisting, and it is not performed in GCC except with -Os. See bug 24001, bug 33315, and other reports about the same issue in Bugzilla. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21676