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.
Perhaps the subject line in the commit message should not have contained the word "refactor". I have not seen a pattern in the git log of a best practice. It was a refactoring, but it had the effect of altering the test leading to a fix... Maybe. If the change actually is a fix. I might be all wrong here.