nothing is optimized away, it's just not executed - e.g. the program including semantics of the language is just designed such that it is not executed.
e.g. for Rust/tokio printing B is skipped, because the process exits and cancels the future before the task can print B