// File: /workspace/github_cpp_makefile_star2_O3/pgrouchy[P]NoiseWorld/mathNet.cpp
// Function: Tree::reduceEqn()
void Tree::reduceEqn() {
    if (!this->isTerminal) {
        switch ((int)this->myVal) {
            case ADD: {
                this->leftTree->reduceEqn();
                this->rightTree->reduceEqn();
                if ((this->leftTree->isConstant) && (this->rightTree->isConstant)) { // reduce the addition of two constants to a single constant
                    this->myVal = this->leftTree->myVal + this->rightTree->myVal;
                    this->isConstant = true;
                    this->isTerminal = true;
                    delete this->leftTree;
                    delete this->rightTree;
                    this->leftTree = NULL;
                    this->rightTree = NULL;
                } else if (this->leftTree->isEqual(this->rightTree)) { // reduce the addition of two equal trees to 2x a single copy of that tree
                    this->myVal = MULTIPLY;
                    this->rightTree->myVal = 2.0;
                    this->rightTree->isConstant = true;
                    this->rightTree->isTerminal = true;
                    delete this->rightTree->leftTree;
                    this->rightTree->leftTree = NULL;
                    delete this->rightTree->rightTree;
                    this->rightTree->rightTree = NULL;
                }
                break;
            }
            case SUBTRACT: {
                this->leftTree->reduceEqn();
                this->rightTree->reduceEqn();
                if ((this->leftTree->isConstant) && (this->rightTree->isConstant)) { // reduce the subtraction of two constants to a single constant
                    this->myVal = this->leftTree->myVal - this->rightTree->myVal;
                    this->isConstant = true;
                    this->isTerminal = true;
                    delete this->leftTree;
                    delete this->rightTree;
                    this->leftTree = NULL;
                    this->rightTree = NULL;
                } else if (this->leftTree->isEqual(this->rightTree)) { // reduce the subtraction of two equal trees to 0
                    this->myVal = 0.0;
                    this->isConstant = true;
                    this->isTerminal = true;
                    delete this->leftTree;
                    delete this->rightTree;
                    this->leftTree = NULL;
                    this->rightTree = NULL;
                }
                break;
            }
            case MULTIPLY: {
                this->leftTree->reduceEqn();
                this->rightTree->reduceEqn();
                if ((this->leftTree->isConstant) && (this->rightTree->isConstant)) { // reduce the multiplication of two constants to a single constant
                    this->myVal = this->leftTree->myVal * this->rightTree->myVal;
                    this->isConstant = true;
                    this->isTerminal = true;
                    delete this->leftTree;
                    delete this->rightTree;
                    this->leftTree = NULL;
                    this->rightTree = NULL;
                } else if ((this->leftTree->isConstant) && ((int)this->leftTree->myVal == 0)) { // reduce the multiplication of a subtree by 0 to 0 (i.e., delete the subtree)
                    this->myVal = 0.0;
                    this->isConstant = true;
                    this->isTerminal = true;
                    delete this->leftTree;
                    delete this->rightTree;
                    this->leftTree = NULL;
                    this->rightTree = NULL;
                } else if ((this->rightTree->isConstant) && ((int)this->rightTree->myVal == 0)) { // reduce the multiplication of a subtree by 0 to 0 (i.e., delete the subtree)
                    this->myVal = 0.0;
                    this->isConstant = true;
                    this->isTerminal = true;
                    delete this->leftTree;
                    delete this->rightTree;
                    this->leftTree = NULL;
                    this->rightTree = NULL;
                }
                break;
            }
            case DIVIDE: {
                this->leftTree->reduceEqn();
                this->rightTree->reduceEqn();
                if ((this->leftTree->isConstant) && (this->rightTree->isConstant)) { // reduce the division of two constants to a single constant
                    if ((int)this->rightTree->myVal != 0) { // skip any division-by-zero operations, such agents will be selected to die after initial evaluation of EMM (see island.cpp)
                        this->myVal = this->leftTree->myVal / this->rightTree->myVal;
                        this->isConstant = true;
                        this->isTerminal = true;
                        delete this->leftTree;
                        delete this->rightTree;
                        this->leftTree = NULL;
                        this->rightTree = NULL;
                    }
                } else if ((this->leftTree->isConstant) && ((int)this->leftTree->myVal == 0)) { // reduce the division of 0 by a subtree to 0
                    this->myVal = 0.0;
                    this->isConstant = true;
                    this->isTerminal = true;
                    delete this->leftTree;
                    delete this->rightTree;
                    this->leftTree = NULL;
                    this->rightTree = NULL;
                }
                break;
            }
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
cmpl $0x0, 0x18(%rdi)
je 0x6707
popq %rbx
popq %r14
popq %r15
retq
movq %rdi, %rbx
cvttsd2si 0x20(%rdi), %eax
cmpl $0x3, %eax
ja 0x6701
leaq 0x4c09(%rip), %rcx      # 0xb324
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rbx), %rdi
callq 0x66f6
movq 0x8(%rbx), %rdi
callq 0x66f6
movq (%rbx), %r15
movq 0x8(%rbx), %r14
cmpl $0x0, 0x1c(%r15)
je 0x6858
cmpl $0x0, 0x1c(%r14)
je 0x6858
movsd 0x20(%r15), %xmm0
addsd 0x20(%r14), %xmm0
movsd %xmm0, 0x20(%rbx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x18(%rbx)
movq %r15, %rdi
callq 0x5b2a
movl $0x38, %esi
movq %r15, %rdi
jmp 0x693d
movq (%rbx), %rdi
callq 0x66f6
movq 0x8(%rbx), %rdi
callq 0x66f6
movq (%rbx), %r14
movq 0x8(%rbx), %rax
cmpl $0x0, 0x1c(%r14)
movl 0x1c(%rax), %ecx
je 0x68f4
movsd 0x20(%r14), %xmm0
testl %ecx, %ecx
je 0x6903
mulsd 0x20(%rax), %xmm0
jmp 0x684e
movq (%rbx), %rdi
callq 0x66f6
movq 0x8(%rbx), %rdi
callq 0x66f6
movq (%rbx), %r14
cmpl $0x0, 0x1c(%r14)
je 0x6701
movq 0x8(%rbx), %rax
cmpl $0x0, 0x1c(%rax)
je 0x6909
movsd 0x20(%rax), %xmm0
cvttsd2si %xmm0, %eax
testl %eax, %eax
je 0x6701
movsd 0x20(%r14), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rbx)
jmp 0x691f
movq (%rbx), %rdi
callq 0x66f6
movq 0x8(%rbx), %rdi
callq 0x66f6
movq (%rbx), %r14
movq 0x8(%rbx), %rsi
cmpl $0x0, 0x1c(%r14)
je 0x68e2
cmpl $0x0, 0x1c(%rsi)
je 0x68e2
movsd 0x20(%r14), %xmm0
subsd 0x20(%rsi), %xmm0
movsd %xmm0, 0x20(%rbx)
jmp 0x691f
movq %r15, %rdi
movq %r14, %rsi
callq 0x696e
testb %al, %al
je 0x6701
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0x20(%rbx)
movq %rax, 0x20(%r14)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x18(%r14)
movq (%r14), %r14
testq %r14, %r14
je 0x689b
movq %r14, %rdi
callq 0x5b2a
movl $0x38, %esi
movq %r14, %rdi
callq 0x21f0
movq 0x8(%rbx), %rax
movq $0x0, (%rax)
movq 0x8(%rax), %r14
testq %r14, %r14
je 0x68c4
movq %r14, %rdi
callq 0x5b2a
movl $0x38, %esi
movq %r14, %rdi
callq 0x21f0
movq 0x8(%rbx), %rax
movq $0x0, 0x8(%rax)
jmp 0x6701
movq %r14, %rdi
callq 0x696e
testb %al, %al
je 0x6701
jmp 0x6917
testl %ecx, %ecx
je 0x6701
cvttsd2si 0x20(%rax), %eax
jmp 0x690f
cvttsd2si %xmm0, %eax
jmp 0x690f
cvttsd2si 0x20(%r14), %eax
testl %eax, %eax
jne 0x6701
movq $0x0, 0x20(%rbx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x18(%rbx)
movq %r14, %rdi
callq 0x5b2a
movl $0x38, %esi
movq %r14, %rdi
callq 0x21f0
movq 0x8(%rbx), %r14
testq %r14, %r14
je 0x6953
movq %r14, %rdi
callq 0x5b2a
movl $0x38, %esi
movq %r14, %rdi
callq 0x21f0
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
jmp 0x6701
nop