Flatten boolean branches and double negation