Hard
A Collatz loop called with zero
For n = 0 the loop body maps 0 to 0, so the abstract machine never leaves the loop. Compiled as C++20 with -O2, what does this program do?
main.cpp
#include <cstdio>
bool reachesOne(unsigned long n) {
while (n != 1) {
n = (n % 2) ? 3 * n + 1 : n / 2;
}
return true;
}
int main() {
std::printf("%d\n", reachesOne(0));
}31 of 44 in Compilers