In theory a good optimizing compiler should see that some code doesn&#x27;t depend on anything external and do it, but I&#x27;m not sure to what extent they do.  GCC with higher optimization settings does do some pretty crazy stuff, so I would expect it to figure out something like in the example code pretty easily.