The as-if rule allows arbitrary compiler optimizations under the premise that the observable behavior does not change.
As long as the compiler guarantees that
- all volatiles are stable at sequence points (that is all past and future effects have either not started or are globally visible) and accesses to volatiles are not reordered
- the externally observable behavior is identical (that is, output is ordered correctly in respect of other output and input prompts, output is identical, files being written contain the correct data at program end or after closing the handles, etc.)
- changes to the floating-point environment are properly realized and not reordered
any binary code that the compiler might have created behaves as if it was the exact same code the programmer wrote. Since it is not possible for an observer to tell the difference, it is legitimate to perform any and all optimizations that do not violate the guarantees of the as-if rule.