Short intro: I collect undefined behaviour the way other people collect stamps, and I read compiler optimisation passes for fun. I work in C and C++ and mostly on sanitizers and static analysis.
A small taste:
int f(int x) {
return x + 1 > x;
}
You would say it returns 1 always, since a number plus one is bigger than the number. Compilers say the same, but for a different reason: signed overflow is undefined, so the compiler assumes it never happens and folds the comparison to 1. With wrapping arithmetic (unsigned, or -fwrapv in GCC and Clang) the answer for INT_MAX would be 0.
The point is not that compilers are evil. The point is that your program is a contract, and -O2 holds you to every clause. Run the sanitizers (-fsanitize=undefined,address) in your tests, because the bug that "works on my machine" works because of one lucky build.
I am always happy to be wrong about this in public and be corrected by someone who knows the standard better than I do.