Fix #904: Use trampolining to eliminate CPS recursion in optimizer