BF Interpreter not working

I wrote an optimizing brainf**k compiler and it works for simple
programs, but fails for complicated programs that i’ve tested in other
interpreters. I’ve tested it extensively in IRB and can’t seem to find
any flaws. Any suggestions?

(The source code is attached)