Unexpected result when compiler optimizations were enabled.
Description
The interpolation algorithm implemented in C works fine in debug configurations, but failed to generate the correct output when compiler optimizations were enabled with -O2.
Demo
Using lena32.bmp as input for simplicity, 2x magnification.
Debug

Release

With -O2, only the last row, which is the first row to be generated, was correct. The rest of the image was blank.
Possible causes
It's clear that the optimizations introduced unexpected behaviors to the algorithm. After some searching, the absence of the volatile keyword might be to blame. Refer to How to Use C's volatile Keyword for more info.
It's been verified that using volatile keyword in every declaration related to loops could fix the problem. Whether it is necessary or not is not tested yet.