1. A method for code optimization, comprising: disassembling object code that has been compiled and linked; analyzing the disassembled code so as to identify a first function in the code, the first function including store and restore instructions with respect to one or more non-volatile registers and further including a call instruction to a second function that is performed infrequently when the first function is run; identifying one or more volatile registers unused in the first function; and modifying the code so as to replace each reference in the first function to at least one of the non-volatile registers with a reference to a corresponding one of the unused volatile registers, and so as to eliminate at least one pair of the store and restore instructions in the first function with respect to the at least one of the non-volatile registers while storing the corresponding one of the volatile registers before the call instruction to the second function and restoring the corresponding one of the volatile registers after the call instruction to the second function.