Improve register allocation by splitting register optimize into two distinct functions