No idea about your code (I don't do C, so haven't looked at it) - but your requirement appears to be just a simple remote control application, similar to IR remote control (just without the 38KHz carrier. It's dead simple to do, and takes very little memory - there are assembler examples for Sony SIRC's in my tutorials, and I've used them as the basis of many different remote control types, with and without carrier.
If you're generating long code, then you're doing something badly wrong!.