> You can't really do loop unrolling and constant folding as some suggest because the number of iterations is determined at run time.
Huh?
Huh?
>NUMBER = atoi(argv[1]);
argv is populated at runtime based on what the OS passed you.
But you are right if you meant that my statement is too strong: you can't do arbitrary loop unrolling. You can jump to a loop that's unrolled once if the number is even, etc.
There are certainly also optimizers that will just output the input without any loop, but that's beyond anything I would expect of a current production compiler.
s = i = atoi(argv[1]);
Now the loop is gone.Edit: This will still happen even if you're doing other stuff in there. GCC will attempt to inline and optimize like this. If it is impossible then you will see a loop with most of the stuff factored out of it.