The interesting question is: Has someone "harcoded" a clever optimisation specifically for Collatz conjecture? Or did the general optimisation techniques figure this out of their own?
clang appears to correctly detect that `collatz` only directly defines a result for `1`, and any other input expands to yet another recursive call to `collatz` (the parameter is irrelevant). To avoid infinite recursion, `collatz` must eventually be called with the value 1, so that's what clang concludes.
The optimisation seems to be wrong; clang returns a constant 1, which assumes that the function is never called with n=0. Which is true for the Collatz conjecture (it starts at 1), but surely clang has no right to assume that n≥1?
https://en.cppreference.com/w/cpp/language/memory_model
https://en.cppreference.com/w/cpp/language/ub#Infinite_loop_...