Refactor optimize

Refactoring of visitors in optimize.c to simplify (perhaps) and remove boiler plate code. A lot of the visitors uses the exact same code pattern to optimize and check for errors.

In commit baef3a1 a fail compilation test fails but the change should provide a more correct solution. Both lhs and rhs should be checked for errors in a "foo || bar" expression.
This change is an effect of baef3a1. I made fairly many commits to ensure each change did not affect the tests. Though this one did and when I looked at the output the change seemed give a more true and correct output. I made a comment about it in the commit message.