More carefully check assignments of registers.
Replace long if-else-if with two short ifs.