The corrected example merely repeats the originally reported bug.
Certainly won’t be the first time that an optimizer produced incorrect results. Delphi-6 had a similar bug, too, that vexed me for a time. It is almost a general rule-of-thumb that, if calling any function that modifies one of its inputs, do not assign the result back to the same variable. Optimizers like to remove “unnecessary” loads and stores, and they like to re-order things, and it becomes a gray area. Just put the result down someplace else.