Optimal program execution reversal