> The compiler is legally allowed to replace the null dereference with code that sends your porn collection to your mother, and set the reference to 42.
No, but they may optimize out assigning to the reference at all, since assigning to it requires dereferencing a provably null pointer, which means that any future code is effectively meaningless.