The only way of reordering those statements is if the compiler can unambiguously detect that reordering the statements cannot change the observable effects.
Some compilers do get a bit too aggressive with their optimisation, and break this rule.