On Monday your boss comes into your office and says “I need file A on my desk by Thursday and file B on my desk on Friday”. He first describes the things that he wants in file A and how he thinks you should do those and then describes the things he wants in file B.
In the mind of your boss, you will first do the things for file A, place that file on his desk on Thursday, then get to work on file B and finish that on Friday. But you realize that it would make more sense to start work on file B earlier – before file A even. There’s no reason your boss has to know – all he cares about is receiving A on Thursday and B on Friday. You also realize that the way he suggested can be improved, so you take a slightly different approach to producing the required information.
In this analogy, the boss is some C++ code and you are the compiler. It is legal for the compiler to rearrange operations (work on the files in another order) as long as the observable behavior (putting files on the desk of the boss) is the same. Similarly, the compiler is free to do any transformations (using a different approach than the one described by the boss) on the code that preserve the observable behavior.
In particular, “as if the program was executed as written” means “as if you did the work exactly as your boss instructed you to” (even if you did something different).