codegen: fix unsound mark_volatile_vars implementation (#57131)
The previous implementation was incorrect, leading to failing to mark
variables correctly. The new implementation is more conservative. This
simple analysis assumes that inference has normally run or that
performance doesn't matter for a particular block of code.
Fixes #56996