So, an optimizing compiler would see that pretty much everything is dead code it would assign 0 to the return register and done.
gcc-trunk at -O3 for x64 will vectorize the loops but there's no register pressure, so the register allocator wasn't taxed much.
No niche optimization pass to convert to using Gauss's shortcut - https://physicsdb.com/sum-natural-numbers/
wow. wonder if there's much use for that optimization pattern.
edit: clang discussion https://stackoverflow.com/questions/74417624/how-does-clang-...
So, an optimizing compiler would see that pretty much everything is dead code it would assign 0 to the return register and done.