C++ operates on an abstract machine. That abstract machine’s behaviour, when defined, is translated into actual machine code.
Your code runs into a few problems.
The biggest is that all loops in C++ are guaranteed to either perform an I/O-like operation, synchronize, or end.
The second problem is that, barring synchronization, intermediate states are undetectable.
So both of your program segments can be compiled down to:
bool b = true;
by a compliant C++ compiler.
(Now, as your loops never actually terminate, compilers are free to do even stranger things.)
Optimization in C++ depends on writing code the compiler can understand to optimize. The steps you write in C++ cannot be assumed to correspond 1:1 with generated machine code. That error is common and leads to both bugs in C++ code and optimization failures.
Basically, you are asking how tall a cake dough recipe is. It is a category error, where you know cake has a height, and are mistaking a recipe for cake dough as having the properties of a cake.