// File: /workspace/github_cpp_makefile_star2_O2/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 0x561d
popq %rbx
popq %r14
popq %r15
retq
movq %rdi, %rbx
cvttsd2si 0x20(%rdi), %eax
cmpl $0x3, %eax
ja 0x5617
leaq 0x4c93(%rip), %rcx      # 0xa2c4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rbx), %rdi
callq 0x560c
movq 0x8(%rbx), %rdi
callq 0x560c
movq (%rbx), %r15
movq 0x8(%rbx), %r14
cmpl $0x0, 0x1c(%r15)
je 0x576c
cmpl $0x0, 0x1c(%r14)
je 0x576c
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 0x4a1a
pushq $0x38
popq %rsi
movq %r15, %rdi
jmp 0x5842
movq (%rbx), %rdi
callq 0x560c
movq 0x8(%rbx), %rdi
callq 0x560c
movq (%rbx), %r14
movq 0x8(%rbx), %rax
cmpl $0x0, 0x1c(%r14)
movl 0x1c(%rax), %ecx
je 0x57fe
movsd 0x20(%r14), %xmm0
testl %ecx, %ecx
je 0x580d
mulsd 0x20(%rax), %xmm0
jmp 0x5762
movq (%rbx), %rdi
callq 0x560c
movq 0x8(%rbx), %rdi
callq 0x560c
movq (%rbx), %r14
cmpl $0x0, 0x1c(%r14)
je 0x5617
movq 0x8(%rbx), %rax
cmpl $0x0, 0x1c(%rax)
je 0x5813
movsd 0x20(%rax), %xmm0
cvttsd2si %xmm0, %eax
testl %eax, %eax
je 0x5617
movsd 0x20(%r14), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rbx)
jmp 0x5826
movq (%rbx), %rdi
callq 0x560c
movq 0x8(%rbx), %rdi
callq 0x560c
movq (%rbx), %r14
movq 0x8(%rbx), %rsi
cmpl $0x0, 0x1c(%r14)
je 0x57ec
cmpl $0x0, 0x1c(%rsi)
je 0x57ec
movsd 0x20(%r14), %xmm0
subsd 0x20(%rsi), %xmm0
movsd %xmm0, 0x20(%rbx)
jmp 0x5826
movq %r15, %rdi
movq %r14, %rsi
callq 0x5870
testb %al, %al
je 0x5617
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 0x57af
movq %r14, %rdi
callq 0x4a1a
pushq $0x38
popq %rsi
movq %r14, %rdi
callq 0x2200
movq 0x8(%rbx), %rax
andq $0x0, (%rax)
movq 0x8(%rax), %r14
testq %r14, %r14
je 0x57d3
movq %r14, %rdi
callq 0x4a1a
pushq $0x38
popq %rsi
movq %r14, %rdi
callq 0x2200
movq 0x8(%rbx), %rax
andq $0x0, 0x8(%rax)
jmp 0x5617
movq %r14, %rdi
callq 0x5870
testb %al, %al
je 0x5617
jmp 0x5821
testl %ecx, %ecx
je 0x5617
cvttsd2si 0x20(%rax), %eax
jmp 0x5819
cvttsd2si %xmm0, %eax
jmp 0x5819
cvttsd2si 0x20(%r14), %eax
testl %eax, %eax
jne 0x5617
andq $0x0, 0x20(%rbx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x18(%rbx)
movq %r14, %rdi
callq 0x4a1a
pushq $0x38
popq %rsi
movq %r14, %rdi
callq 0x2200
movq 0x8(%rbx), %r14
testq %r14, %r14
je 0x5858
movq %r14, %rdi
callq 0x4a1a
pushq $0x38
popq %rsi
movq %r14, %rdi
callq 0x2200
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
jmp 0x5617