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.
Aha, ok. No problem I'll just revert commit 513cbe2. I though those printf were "forgotten" since they are not surrounded with DEBUG ifdefs. Perhaps such a change would be preferred? Though it will be hard to enable a specific printf with such a solution.