// File: CHEN-Zhihan[P]Compiler/compiler.cpp
// Function: run(std::shared_ptr<Node>)
void run(shared_ptr<Node> p) {
    operatorInstruction = unordered_map<int, string> {{'+', "add"}, {'-', "sub"}, {'*', "mul"}, 
                                            {'/', "div"}, {'%', "mod"}, {'<', "compLT"},
                                            {'>', "compGT"}, {GE, "compGE"}, {LE, "compLE"},
                                            {NE, "compNE"}, {EQ, "compEQ"}, {AND, "and"},
                                            {OR, "or"}};
    variableTable[GLOBAL] = unordered_set<int>{};
    functionTable = unordered_map<int, const FunctionNode* >();
    for (auto i = 0; i != 9; ++i) {
        variableTable[GLOBAL].insert(i);
        functionTable[i] = nullptr;
    }
    vector<scope> sList{GLOBAL};
    #if DEBUG
        for (auto i = 0; i != reverseLookup.size(); ++i) {
            cerr << i << reverseLookup[i] << endl;
        }
    #endif
    addressTable[GLOBAL] = pair<int, unordered_map<scope, unordered_map<ID, address> > >();
    reusableAddress[GLOBAL] = set<pair<int, int> >();
    p->check(sList, GLOBAL);
    if (addressTable[GLOBAL].first != 0) {
        printf("\tpush\tsp\n");
        printf("\tpush\t%d\n", addressTable[GLOBAL].first);
        printf("\tadd\n");
        printf("\tpop\tsp\n");
    }
    scopeCounter = 0;
    sList = vector<scope>{GLOBAL};
    p->ex(sList, GLOBAL, 998, 998);
    printf("\tend\n");
    defineFunctions();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4a0, %rsp            # imm = 0x4A0
movq %rdi, -0x3f8(%rbp)
movq %rdi, -0x8(%rbp)
leaq -0x258(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movb $0x2b, -0x261(%rbp)
leaq 0x2029c(%rip), %rdx     # 0x3668e
leaq -0x261(%rbp), %rsi
callq 0x17070
jmp 0x16400
leaq -0x230(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movb $0x2d, -0x275(%rbp)
leaq 0x20276(%rip), %rdx     # 0x36692
leaq -0x275(%rbp), %rsi
callq 0x17070
jmp 0x1642a
leaq -0x208(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movb $0x2a, -0x276(%rbp)
leaq 0x20250(%rip), %rdx     # 0x36696
leaq -0x276(%rbp), %rsi
callq 0x17070
jmp 0x16454
leaq -0x1e0(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movb $0x2f, -0x277(%rbp)
leaq 0x2022a(%rip), %rdx     # 0x3669a
leaq -0x277(%rbp), %rsi
callq 0x17070
jmp 0x1647e
leaq -0x1b8(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movb $0x25, -0x278(%rbp)
leaq 0x20204(%rip), %rdx     # 0x3669e
leaq -0x278(%rbp), %rsi
callq 0x17070
jmp 0x164a8
leaq -0x190(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movb $0x3c, -0x279(%rbp)
leaq 0x201de(%rip), %rdx     # 0x366a2
leaq -0x279(%rbp), %rsi
callq 0x170f0
jmp 0x164d2
leaq -0x168(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movb $0x3e, -0x27a(%rbp)
leaq 0x201bb(%rip), %rdx     # 0x366a9
leaq -0x27a(%rbp), %rsi
callq 0x170f0
jmp 0x164fc
leaq -0x140(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movl $0x11a, -0x280(%rbp)    # imm = 0x11A
leaq 0x20195(%rip), %rdx     # 0x366b0
leaq -0x280(%rbp), %rsi
callq 0x17170
jmp 0x16529
leaq -0x118(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movl $0x11b, -0x284(%rbp)    # imm = 0x11B
leaq 0x2016f(%rip), %rdx     # 0x366b7
leaq -0x284(%rbp), %rsi
callq 0x17170
jmp 0x16556
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movl $0x11d, -0x288(%rbp)    # imm = 0x11D
leaq 0x20149(%rip), %rdx     # 0x366be
leaq -0x288(%rbp), %rsi
callq 0x17170
jmp 0x16583
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movl $0x11c, -0x28c(%rbp)    # imm = 0x11C
leaq 0x20123(%rip), %rdx     # 0x366c5
leaq -0x28c(%rbp), %rsi
callq 0x17170
jmp 0x165b0
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movl $0x118, -0x290(%rbp)    # imm = 0x118
leaq 0x200fd(%rip), %rdx     # 0x366cc
leaq -0x290(%rbp), %rsi
callq 0x171f0
jmp 0x165dd
leaq -0x78(%rbp), %rdi
movq %rdi, -0x260(%rbp)
movl $0x119, -0x294(%rbp)    # imm = 0x119
leaq 0x1ef67(%rip), %rdx     # 0x35560
leaq -0x294(%rbp), %rsi
callq 0x17270
jmp 0x16607
leaq -0x258(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $0xd, -0x48(%rbp)
leaq -0x297(%rbp), %rdi
movq %rdi, -0x400(%rbp)
callq 0x17310
movq -0x400(%rbp), %rcx
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rsp, %rax
movq %rcx, (%rax)
xorl %eax, %eax
movl %eax, %ecx
leaq -0x40(%rbp), %rdi
leaq -0x295(%rbp), %r8
leaq -0x296(%rbp), %r9
callq 0x17330
jmp 0x1665f
leaq 0x3ad8a(%rip), %rdi     # 0x513f0
leaq -0x40(%rbp), %rsi
callq 0x17390
leaq -0x40(%rbp), %rdi
callq 0x16d20
leaq -0x297(%rbp), %rdi
callq 0x173c0
leaq -0x258(%rbp), %rax
movq %rax, -0x410(%rbp)
addq $0x208, %rax            # imm = 0x208
movq %rax, -0x408(%rbp)
movq -0x408(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x418(%rbp)
callq 0x172f0
movq -0x410(%rbp), %rcx
movq -0x418(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x408(%rbp)
jne 0x1669f
xorps %xmm0, %xmm0
movaps %xmm0, -0x2b0(%rbp)
movaps %xmm0, -0x2c0(%rbp)
movaps %xmm0, -0x2d0(%rbp)
movq $0x0, -0x2a0(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0x173e0
leaq 0x3acb2(%rip), %rdi     # 0x513b8
leaq 0x3adcf(%rip), %rsi     # 0x514dc
callq 0x17400
movq %rax, -0x420(%rbp)
jmp 0x1671b
movq -0x420(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x17430
leaq -0x2d0(%rbp), %rdi
callq 0x17460
leaq -0x308(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x4130
leaq -0x308(%rbp), %rdi
callq 0x16c80
leaq 0x3ac20(%rip), %rdi     # 0x51380
leaq -0x308(%rbp), %rsi
callq 0x17480
leaq -0x308(%rbp), %rdi
callq 0x16ca0
movl $0x0, -0x30c(%rbp)
cmpl $0x9, -0x30c(%rbp)
je 0x168dd
leaq 0x3ac22(%rip), %rdi     # 0x513b8
leaq 0x3ad3f(%rip), %rsi     # 0x514dc
callq 0x17400
movq %rax, %rdi
leaq -0x30c(%rbp), %rsi
callq 0x174b0
movq %rax, -0x320(%rbp)
movb %dl, -0x318(%rbp)
leaq 0x3abbb(%rip), %rdi     # 0x51380
leaq -0x30c(%rbp), %rsi
callq 0x16ec0
movq $0x0, (%rax)
movl -0x30c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30c(%rbp)
jmp 0x16782
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
movq -0x260(%rbp), %rax
leaq -0x258(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x428(%rbp)
je 0x16846
movq -0x428(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x430(%rbp)
callq 0x172f0
movq -0x430(%rbp), %rax
leaq -0x258(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x428(%rbp)
jne 0x16815
jmp 0x16c66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
leaq -0x297(%rbp), %rdi
callq 0x173c0
leaq -0x258(%rbp), %rax
movq %rax, -0x440(%rbp)
addq $0x208, %rax            # imm = 0x208
movq %rax, -0x438(%rbp)
movq -0x438(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x448(%rbp)
callq 0x172f0
movq -0x440(%rbp), %rcx
movq -0x448(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x438(%rbp)
jne 0x16884
jmp 0x16c66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0x17460
jmp 0x16c66
leaq 0x3abf8(%rip), %rax     # 0x514dc
movl (%rax), %eax
movl %eax, -0x34c(%rbp)
leaq -0x34c(%rbp), %rax
movq %rax, -0x348(%rbp)
movq $0x1, -0x340(%rbp)
leaq -0x34d(%rbp), %rdi
movq %rdi, -0x450(%rbp)
callq 0x16f20
movq -0x450(%rbp), %rcx
movq -0x348(%rbp), %rsi
movq -0x340(%rbp), %rdx
leaq -0x338(%rbp), %rdi
callq 0x16f40
jmp 0x1693b
leaq -0x34d(%rbp), %rdi
callq 0x16fc0
leaq -0x390(%rbp), %rdi
callq 0x174f0
jmp 0x16955
leaq 0x3ab3c(%rip), %rdi     # 0x51498
leaq 0x3ab79(%rip), %rsi     # 0x514dc
callq 0x16ef0
movq %rax, -0x458(%rbp)
jmp 0x16971
movq -0x458(%rbp), %rdi
leaq -0x390(%rbp), %rsi
movq %rsi, -0x468(%rbp)
callq 0x17530
movq -0x468(%rbp), %rdi
callq 0x17570
xorps %xmm0, %xmm0
movaps %xmm0, -0x3a0(%rbp)
movaps %xmm0, -0x3b0(%rbp)
movaps %xmm0, -0x3c0(%rbp)
leaq -0x3c0(%rbp), %rdi
callq 0x17590
leaq 0x3aa9e(%rip), %rdi     # 0x51460
leaq 0x3ab13(%rip), %rsi     # 0x514dc
callq 0x175b0
movq %rax, -0x460(%rbp)
jmp 0x169d7
movq -0x460(%rbp), %rdi
leaq -0x3c0(%rbp), %rsi
movq %rsi, -0x470(%rbp)
callq 0x175e0
movq -0x470(%rbp), %rdi
callq 0x17610
movq -0x3f8(%rbp), %rdi
callq 0x17630
movq %rax, %rdi
leaq 0x3aac9(%rip), %rax     # 0x514dc
movl (%rax), %edx
movq (%rdi), %rax
movq 0x8(%rax), %rax
leaq -0x338(%rbp), %rsi
callq *%rax
jmp 0x16a27
leaq 0x3aa6a(%rip), %rdi     # 0x51498
leaq 0x3aaa7(%rip), %rsi     # 0x514dc
callq 0x16ef0
movq %rax, -0x478(%rbp)
jmp 0x16a43
movq -0x478(%rbp), %rax
cmpl $0x0, (%rax)
je 0x16b3d
leaq 0x1fc0c(%rip), %rdi     # 0x36666
xorl %eax, %eax
callq 0x4040
jmp 0x16a63
leaq 0x3aa2e(%rip), %rdi     # 0x51498
leaq 0x3aa6b(%rip), %rsi     # 0x514dc
callq 0x16ef0
movq %rax, -0x480(%rbp)
jmp 0x16a7f
movq -0x480(%rbp), %rax
movl (%rax), %esi
leaq 0x1fbcd(%rip), %rdi     # 0x3665c
xorl %eax, %eax
callq 0x4040
jmp 0x16a98
leaq 0x1fbd1(%rip), %rdi     # 0x36670
xorl %eax, %eax
callq 0x4040
jmp 0x16aa8
leaq 0x1fbc7(%rip), %rdi     # 0x36676
xorl %eax, %eax
callq 0x4040
jmp 0x16ab8
jmp 0x16b3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
leaq -0x34d(%rbp), %rdi
callq 0x16fc0
jmp 0x16c66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
jmp 0x16c5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
leaq -0x390(%rbp), %rdi
callq 0x17570
jmp 0x16c5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
leaq -0x3c0(%rbp), %rdi
callq 0x17610
jmp 0x16c5a
movl $0x0, 0x3a989(%rip)     # 0x514d0
leaq 0x3a98e(%rip), %rax     # 0x514dc
movl (%rax), %eax
movl %eax, -0x3ec(%rbp)
leaq -0x3ec(%rbp), %rax
movq %rax, -0x3e8(%rbp)
movq $0x1, -0x3e0(%rbp)
leaq -0x3ed(%rbp), %rdi
movq %rdi, -0x488(%rbp)
callq 0x16f20
movq -0x488(%rbp), %rcx
movq -0x3e8(%rbp), %rsi
movq -0x3e0(%rbp), %rdx
leaq -0x3d8(%rbp), %rdi
callq 0x16f40
jmp 0x16ba5
leaq -0x338(%rbp), %rdi
movq %rdi, -0x490(%rbp)
leaq -0x3d8(%rbp), %rsi
movq %rsi, -0x498(%rbp)
callq 0x17650
movq -0x498(%rbp), %rdi
callq 0x16fe0
leaq -0x3ed(%rbp), %rdi
callq 0x16fc0
movq -0x3f8(%rbp), %rdi
callq 0x17630
movq -0x490(%rbp), %rsi
movq %rax, %rdi
leaq 0x3a8e1(%rip), %rax     # 0x514dc
movl (%rax), %edx
movq (%rdi), %rax
movq (%rax), %rax
movl $0x3e6, %r8d            # imm = 0x3E6
movl %r8d, %ecx
callq *%rax
jmp 0x16c10
leaq 0x1fab9(%rip), %rdi     # 0x366d0
xorl %eax, %eax
callq 0x4040
jmp 0x16c20
callq 0x16200
jmp 0x16c27
leaq -0x338(%rbp), %rdi
callq 0x16fe0
addq $0x4a0, %rsp            # imm = 0x4A0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
leaq -0x3ed(%rbp), %rdi
callq 0x16fc0
leaq -0x338(%rbp), %rdi
callq 0x16fe0
movq -0x270(%rbp), %rdi
callq 0x43d0
nopw %cs:(%rax,%rax)
nopl (%rax)