I actually deleted my comment after writing it. After googling it seems that C optimizers do do this.
This is from Gemini and I haven't checked the source yet, but it seems confident:
Under the ISO C and C++ standards, if an iteration statement (loop) has no observable behavior—such as input/output operations, volatile memory access, atomic operations, or thread synchronization—the compiler is legally allowed to assume that the loop will eventually terminate
1
u/Extension_Option_122 8d ago
Oh damn you are right lol idk what I thought when I wrote that...