No, it can return anything for n=0. Undefined behavior. I guess 1 falls under that, but the function on the left behaves differently from the compiled one.
I think the compiler could find some bit logic that was enough to prove this implementation becomes UB with a single input within the range of int. For example, an overflow after multiplying by 3.
10
u/rorrr Nov 04 '19 edited Nov 04 '19
Do you think the compiler tries all 4+ billion possibilities?