Undefined behavior in C is a reading error
yodaiken.com
yodaiken.com
Or you can opt into using an optimizing compiler (-O2). But when optimization passes ignore the possibility of undefined behavior with unpredictable results (as explicitly allowed by the standard), you get, well, unpredictable results.
Nowadays compilers even offer the "terminating a translation or execution" variant that the standard proposes (-fsanitize=undefined,address). So really, the choice is up to you.
But what people really want is of course: keep the undefined behavior that my program happens to use predictable, but given that constraint, optimize as much as possible (=exploit all the other undefined behavior).
Example: inlining functions is an acceptable optimization, because of course I'm not intentionally using out-of-bounds pointers to grab the return address from the stack.
(But I may be wrong for C. I only know this is true for Rust. I'm pretty sure though the reason it's true for Rust has to do with the steps that happen in llvm, and thus would probably also be true for c).
Actually it was to re-write UNIX kernel, small but very relevant distinction.