// File: /workspace/github_cpp_makefile_star2_O3/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 0xd4df
leaq 0x7204(%rip), %rcx      # 0x1469c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x18(%rbx), %rdi
leaq 0xe49c(%rip), %rsi      # 0x1b948
leaq 0xe7b5(%rip), %rdx      # 0x1bc68
xorl %ecx, %ecx
callq 0x4250
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0xd5b4
movq 0xeaea(%rip), %rcx      # 0x1bfb8
cmpb $0x0, (%rcx)
je 0xd5d4
incl 0x8(%rdi)
jmp 0xd5d8
cmpl $-0x5, %ecx
jne 0xd569
movb $0x0, 0x14(%rbx)
jmp 0xd5ff
movq 0x18(%rbx), %rdi
leaq 0xe44c(%rip), %rsi      # 0x1b948
leaq 0xe74d(%rip), %rdx      # 0x1bc50
xorl %ecx, %ecx
callq 0x4250
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0xd5b9
movq 0xea9a(%rip), %rcx      # 0x1bfb8
cmpb $0x0, (%rcx)
je 0xd5dd
incl 0x8(%rdi)
jmp 0xd5e1
movq 0x18(%rbx), %rdi
leaq 0xe40e(%rip), %rsi      # 0x1b948
leaq 0xe6f7(%rip), %rdx      # 0x1bc38
xorl %ecx, %ecx
callq 0x4250
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0xd5c3
movq 0xea60(%rip), %rcx      # 0x1bfb8
cmpb $0x0, (%rcx)
je 0xd5eb
incl 0x8(%rdi)
jmp 0xd5ef
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0xd5cc
leaq 0xe3cf(%rip), %rsi      # 0x1b948
leaq 0xe700(%rip), %rdx      # 0x1bc80
xorl %r12d, %r12d
xorl %ecx, %ecx
callq 0x4250
movl $0x0, %r14d
testq %rax, %rax
je 0xd61b
movq 0x20(%rbx), %r14
testq %r14, %r14
je 0xd60e
movq 0xea0f(%rip), %rcx      # 0x1bfb8
cmpb $0x0, (%rcx)
je 0xd613
incl 0x8(%r14)
jmp 0xd618
movl 0x8(%rax), %eax
jmp 0xd5c7
movq 0x8(%rax), %rax
movsbl 0x1(%rax), %eax
jmp 0xd5c7
movzbl 0x8(%rax), %eax
movl %eax, 0x10(%rbx)
jmp 0xd5fb
xorl %r12d, %r12d
xorl %r14d, %r14d
jmp 0xd61b
lock
incl 0x8(%rdi)
movl 0x8(%rax), %eax
jmp 0xd5f3
lock
incl 0x8(%rdi)
movq 0x8(%rax), %rax
movsbl 0x1(%rax), %eax
jmp 0xd5f3
lock
incl 0x8(%rdi)
movzbl 0x8(%rax), %eax
movl %eax, 0x10(%rbx)
callq 0x864c
movb $0x1, 0x14(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
jmp 0xd618
lock
incl 0x8(%r14)
movq %rax, %r12
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0xd662
leaq 0xe31d(%rip), %rsi      # 0x1b948
leaq 0xe64e(%rip), %rdx      # 0x1bc80
xorl %r13d, %r13d
xorl %ecx, %ecx
callq 0x4250
movl $0x0, %r15d
testq %rax, %rax
je 0xd677
movq 0x30(%rbx), %r15
testq %r15, %r15
je 0xd66a
movq 0xe961(%rip), %rcx      # 0x1bfb8
cmpb $0x0, (%rcx)
je 0xd66f
incl 0x8(%r15)
jmp 0xd674
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0xd677
xorl %r15d, %r15d
jmp 0xd674
lock
incl 0x8(%r15)
movq %rax, %r13
movq %r12, %rdi
callq 0xd472
movq %r13, %rdi
callq 0xd472
cmpb $0x1, 0x14(%r12)
jne 0xd6d6
cmpb $0x0, 0x14(%r13)
je 0xd6d6
movb $0x1, 0x14(%rbx)
movl 0x10(%r12), %eax
movl 0x10(%r13), %ecx
movl 0x8(%rbx), %edx
cmpl $0x117, %edx            # imm = 0x117
jg 0xd6df
leal -0x25(%rdx), %esi
cmpl $0xa, %esi
ja 0xd70f
leaq 0x6fef(%rip), %rdx      # 0x146ac
movslq (%rdx,%rsi,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
testl %ecx, %ecx
je 0xd7c9
cltd
idivl %ecx
jmp 0xd773
movb $0x0, 0x14(%rbx)
jmp 0xd778
addl $0xfffffee8, %edx       # imm = 0xFFFFFEE8
cmpl $0x8, %edx
ja 0xd778
leaq 0x6fe3(%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 0xd775
cmpl $0x3c, %edx
je 0xd76c
cmpl $0x3e, %edx
jne 0xd778
xorl %edx, %edx
cmpl %ecx, %eax
setg %dl
jmp 0xd773
subl %ecx, %eax
jmp 0xd73e
imull %eax, %ecx
jmp 0xd775
addl %eax, %ecx
jmp 0xd775
testl %ecx, %ecx
je 0xd7ef
cltd
idivl %ecx
jmp 0xd73e
negl %eax
movl %eax, %ecx
jmp 0xd775
xorl %edx, %edx
cmpl %ecx, %eax
jmp 0xd755
xorl %edx, %edx
cmpl %ecx, %eax
setle %dl
jmp 0xd773
xorl %edx, %edx
orl %ecx, %eax
setne %dl
jmp 0xd773
xorl %edx, %edx
cmpl %ecx, %eax
setge %dl
jmp 0xd773
xorl %edx, %edx
cmpl %ecx, %eax
sete %dl
jmp 0xd773
xorl %edx, %edx
cmpl %ecx, %eax
setl %dl
movl %edx, %ecx
movl %ecx, 0x10(%rbx)
testq %r15, %r15
je 0xd785
movq %r15, %rdi
callq 0x864c
testq %r14, %r14
je 0xd5ff
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x864c
movq 0xe83d(%rip), %rdi      # 0x1bfe8
leaq 0x709b(%rip), %rsi      # 0x1484d
callq 0x4200
movq %rax, %rdi
callq 0x4120
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42a0
movq 0xe818(%rip), %rdi      # 0x1bfe8
leaq 0x7092(%rip), %rsi      # 0x14869
movl $0xd, %edx
callq 0x4260
movq 0xe800(%rip), %rdi      # 0x1bfe8
callq 0x4120
jmp 0xd7bf
movq 0xe7f2(%rip), %rdi      # 0x1bfe8
leaq 0x706c(%rip), %rsi      # 0x14869
movl $0xd, %edx
callq 0x4260
movq 0xe7da(%rip), %rdi      # 0x1bfe8
callq 0x4120
jmp 0xd7bf
movq %rax, %rbx
testq %r15, %r15
je 0xd825
movq %r15, %rdi
callq 0x864c
testq %r14, %r14
je 0xd832
movq %r14, %rdi
callq 0x864c
movq %rbx, %rdi
callq 0x43b0