Of course it's not really Visual Basic that does the optimization.
It's C2.EXE, the second pass of the C++ compiler. VB invokes this
program with different options to produce different optimizations.
You can see exactly how this process works and even change it
using a technique I first saw described in Advanced Visual Basic
5, the Mandelbrot Set, 1997. The author, Peter Morris, renames
the real C2.EXE to a different name and replaces it with his own
C2.EXE, which writes all the command lines it gets from VB to a
log file and then passes the same command line on to the real
renamed C2.EXE. By studying the log file, you can see exactly
what VB is doing when you set different optimizations. It turns
out that VB generates a temporary intermediate file (probably the
same kind generated by the first pass C1.EXE of the C++
compiler) and passes the name of that file to C2 for compilation.