Implement XOR reassociation. It is based on following rules: