// File: /workspace/github_cpp_makefile_star2_O1/CHEN-Zhihan[P]Compiler/Node.cpp
// Function: ExprNode::evaluate()
void ExprNode::evaluate() {
    array<int, 2> stack;
    if (oper == STRING) {
        cerr << "Invalid operation on string" << endl;
        exit(-1);
    }
    switch (oper) {
        case INTEGER: {
            value = dynamic_pointer_cast<IntNode>(op[0])->getValue();
            known = true;
            break;
        }
        case CHARACTER: {
            value = dynamic_pointer_cast<CharNode>(op[0])->getValue();
            known = true;            
            break;
        }
        case BOOL: {
            value = dynamic_pointer_cast<BoolNode>(op[0])->getValue();
            known = true;
            break;
        }
        case VAR: {
            known = false;
            return;
        }
        default: {
            auto left = dynamic_pointer_cast<ExprNode>(op[0]);
            auto right = dynamic_pointer_cast<ExprNode>(op[1]);
            left->evaluate();
            right->evaluate();
            if (not left->known or not right->known) {
                known = false;
                return;
            }
            known = true;
            stack[0] = left->value;
            stack[1] = right->value;
            switch (oper) {
                case '+': {
                    EVAL(+);
                }
                case '-': {
                    EVAL(-);
                }
                case '*': {
                    EVAL(*);
                }
                case '/': {
                    if (stack[1] == 0) {
                        cerr << "Division by 0" << endl;
                        exit(-1);
                    }
                    EVAL(/);
                }
                case '%': {
                    if (stack[1] == 0) {
                        cerr << "Division by 0" << endl;
                        exit(-1);
                    }
                    EVAL(%);
                } case UMINUS: {
                    value = -stack[0];
                    break;
                } case '>': {
                    EVAL(>);
                } case '<': {
                    EVAL(<);
                } case GE: {
                    EVAL(>=);
                } case LE: {
                    EVAL(<=);
                } case EQ: {
                    EVAL(==);
                } case NE: {
                    EVAL(!=);
                } case AND: {
                    EVAL(&&);
                } case OR: {
                    EVAL(||);
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x8(%rdi), %ecx
leal -0x102(%rcx), %eax
cmpl $0x3, %eax
ja 0xda2b
leaq 0x6c9e(%rip), %rcx      # 0x1469c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0xda9c
leaq 0xdf35(%rip), %rsi      # 0x1b950
leaq 0xe24e(%rip), %rdx      # 0x1bc70
xorl %ecx, %ecx
callq 0x4250
jmp 0xda9e
cmpl $-0x5, %ecx
jne 0xda79
movb $0x0, 0x14(%rbx)
jmp 0xdb4b
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0xdab8
leaq 0xdf07(%rip), %rsi      # 0x1b950
leaq 0xe208(%rip), %rdx      # 0x1bc58
xorl %ecx, %ecx
callq 0x4250
jmp 0xdaba
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0xdad4
leaq 0xdee7(%rip), %rsi      # 0x1b950
leaq 0xe1d0(%rip), %rdx      # 0x1bc40
xorl %ecx, %ecx
callq 0x4250
jmp 0xdad6
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0xdaf0
leaq 0xdec7(%rip), %rsi      # 0x1b950
leaq 0xe1f8(%rip), %rdx      # 0x1bc88
xorl %ecx, %ecx
callq 0x4250
movq %rax, %r12
jmp 0xdaf3
xorl %eax, %eax
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0xdb1f
movq 0xe512(%rip), %rcx      # 0x1bfc0
cmpb $0x0, (%rcx)
je 0xdb1b
incl 0x8(%rdi)
jmp 0xdb1f
xorl %eax, %eax
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0xdb28
movq 0xe4f6(%rip), %rcx      # 0x1bfc0
cmpb $0x0, (%rcx)
je 0xdb24
incl 0x8(%rdi)
jmp 0xdb28
xorl %eax, %eax
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0xdb36
movq 0xe4da(%rip), %rcx      # 0x1bfc0
cmpb $0x0, (%rcx)
je 0xdb32
incl 0x8(%rdi)
jmp 0xdb36
xorl %r12d, %r12d
testq %r12, %r12
je 0xdb13
movq 0x20(%rbx), %r14
testq %r14, %r14
je 0xdb5f
movq 0xe4b8(%rip), %rax      # 0x1bfc0
cmpb $0x0, (%rax)
je 0xdb5a
incl 0x8(%r14)
jmp 0xdb5f
xorl %r12d, %r12d
xorl %r14d, %r14d
jmp 0xdb5f
lock
incl 0x8(%rdi)
movl 0x8(%rax), %eax
jmp 0xdb3a
lock
incl 0x8(%rdi)
movq 0x8(%rax), %rax
movsbl 0x1(%rax), %eax
jmp 0xdb3a
lock
incl 0x8(%rdi)
movzbl 0x8(%rax), %eax
movl %eax, 0x10(%rbx)
testq %rdi, %rdi
je 0xdb47
callq 0x896e
movb $0x1, 0x14(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
lock
incl 0x8(%r14)
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0xdb82
leaq 0xdde1(%rip), %rsi      # 0x1b950
leaq 0xe112(%rip), %rdx      # 0x1bc88
xorl %ecx, %ecx
callq 0x4250
movq %rax, %r13
jmp 0xdb85
xorl %r13d, %r13d
testq %r13, %r13
je 0xdba5
movq 0x30(%rbx), %r15
testq %r15, %r15
je 0xdbb2
movq 0xe426(%rip), %rax      # 0x1bfc0
cmpb $0x0, (%rax)
je 0xdbad
incl 0x8(%r15)
jmp 0xdbb2
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0xdbb2
lock
incl 0x8(%r15)
movq %r12, %rdi
callq 0xd9d8
movq %r13, %rdi
callq 0xd9d8
cmpb $0x1, 0x14(%r12)
jne 0xdc11
cmpb $0x0, 0x14(%r13)
je 0xdc11
movb $0x1, 0x14(%rbx)
movl 0x10(%r12), %eax
movl 0x10(%r13), %ecx
movl 0x8(%rbx), %edx
cmpl $0x117, %edx            # imm = 0x117
jg 0xdc1a
leal -0x25(%rdx), %esi
cmpl $0xa, %esi
ja 0xdc4a
leaq 0x6ab4(%rip), %rdx      # 0x146ac
movslq (%rdx,%rsi,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
testl %ecx, %ecx
je 0xdd04
cltd
idivl %ecx
jmp 0xdcae
movb $0x0, 0x14(%rbx)
jmp 0xdcb3
addl $0xfffffee8, %edx       # imm = 0xFFFFFEE8
cmpl $0x8, %edx
ja 0xdcb3
leaq 0x6aa8(%rip), %rsi      # 0x146d8
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
testl %eax, %eax
setne %al
testl %ecx, %ecx
setne %cl
andb %al, %cl
movzbl %cl, %ecx
jmp 0xdcb0
cmpl $0x3c, %edx
je 0xdca7
cmpl $0x3e, %edx
jne 0xdcb3
xorl %edx, %edx
cmpl %ecx, %eax
setg %dl
jmp 0xdcae
subl %ecx, %eax
jmp 0xdc79
imull %eax, %ecx
jmp 0xdcb0
addl %eax, %ecx
jmp 0xdcb0
testl %ecx, %ecx
je 0xdd2a
cltd
idivl %ecx
jmp 0xdc79
negl %eax
movl %eax, %ecx
jmp 0xdcb0
xorl %edx, %edx
cmpl %ecx, %eax
jmp 0xdc90
xorl %edx, %edx
cmpl %ecx, %eax
setle %dl
jmp 0xdcae
xorl %edx, %edx
orl %ecx, %eax
setne %dl
jmp 0xdcae
xorl %edx, %edx
cmpl %ecx, %eax
setge %dl
jmp 0xdcae
xorl %edx, %edx
cmpl %ecx, %eax
sete %dl
jmp 0xdcae
xorl %edx, %edx
cmpl %ecx, %eax
setl %dl
movl %edx, %ecx
movl %ecx, 0x10(%rbx)
testq %r15, %r15
je 0xdcc0
movq %r15, %rdi
callq 0x896e
testq %r14, %r14
je 0xdb4b
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x896e
movq 0xe30a(%rip), %rdi      # 0x1bff0
leaq 0x6b60(%rip), %rsi      # 0x1484d
callq 0x4200
movq %rax, %rdi
callq 0x4120
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42a0
movq 0xe2e5(%rip), %rdi      # 0x1bff0
leaq 0x6b57(%rip), %rsi      # 0x14869
movl $0xd, %edx
callq 0x4260
movq 0xe2cd(%rip), %rdi      # 0x1bff0
callq 0x4120
jmp 0xdcfa
movq 0xe2bf(%rip), %rdi      # 0x1bff0
leaq 0x6b31(%rip), %rsi      # 0x14869
movl $0xd, %edx
callq 0x4260
movq 0xe2a7(%rip), %rdi      # 0x1bff0
callq 0x4120
jmp 0xdcfa
movq %rax, %rbx
testq %r15, %r15
je 0xdd60
movq %r15, %rdi
callq 0x896e
testq %r14, %r14
je 0xdd6d
movq %r14, %rdi
callq 0x896e
movq %rbx, %rdi
callq 0x43b0
nop