// File: CHEN-Zhihan[P]Compiler/Node.cpp
// Function: VarNode::pushPop(std::vector<int, std::allocator<int>>&, int, bool) const
void VarNode::pushPop(vector<int>&sList, int functionID, bool push) const {
    string instruction = push ? "push" : "pop";
    if (subscriptions.size() == 0) {
        if (global) {
            cout << "\t" << instruction << "\tsb[" <<  addressTable[GLOBAL].second[GLOBAL][i] << "]\n";
        } else if (functionID == GLOBAL) {
            cout << "\t" << instruction << "\tsb[" << addressTable[GLOBAL].second[getDefinitionScope(sList, GLOBAL)][i] << "]\n";
        } else {
            auto address = addressTable[functionID].second[getDefinitionScope(sList, functionID)][i];
            cout << "\t" << instruction << "\tfp[" << address << "]" << endl;
        }
        return;
    }
    getOffSet(sList, functionID, -1, -1);
    if (global) {
        printf("\tpush\t%d\n", addressTable[GLOBAL].second[GLOBAL][i]);
    } else if (functionID == GLOBAL) {
        auto address = addressTable[GLOBAL].second[getDefinitionScope(sList, functionID)][i];
        printf("\tpush\t%d\n", address);
    } else {
        auto address = addressTable[functionID].second[getDefinitionScope(sList, functionID)][i];        
        printf("\tpush\tfp[%d]\n", address);
        if (address >= 0) {
            printf("\tpush\tfp\n");
            printf("\tadd\n");
        }
    }
    printf("\tadd\n");
    printf("\tpop\tac\n");
    cout << "\t" << instruction << "\tsb[ac]\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
andb $0x1, %al
movb %al, -0x15(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movb -0x15(%rbp), %dl
leaq 0xfbd3(%rip), %rcx      # 0x369d5
leaq 0xfbd1(%rip), %rax      # 0x369da
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, -0x80(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x78(%rbp)
callq 0x43e0
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x4300
jmp 0x26e34
leaq -0x39(%rbp), %rdi
callq 0x4260
movq -0x88(%rbp), %rdi
addq $0x10, %rdi
callq 0x2a210
cmpq $0x0, %rax
jne 0x271e5
movq -0x88(%rbp), %rax
testb $0x1, 0xc(%rax)
je 0x26f81
movq 0x2a151(%rip), %rdi     # 0x50fc0
leaq 0xf96f(%rip), %rsi      # 0x367e5
callq 0x4210
movq %rax, -0x90(%rbp)
jmp 0x26e84
movq -0x90(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x41f0
movq %rax, -0x98(%rbp)
jmp 0x26e9d
movq -0x98(%rbp), %rdi
leaq 0xfb33(%rip), %rsi      # 0x369de
callq 0x4210
movq %rax, -0xa0(%rbp)
jmp 0x26eb9
leaq 0x2a5d8(%rip), %rdi     # 0x51498
leaq 0x2a615(%rip), %rsi     # 0x514dc
callq 0x16ef0
movq %rax, -0xa8(%rbp)
jmp 0x26ed5
movq -0xa8(%rbp), %rdi
addq $0x8, %rdi
leaq 0x2a5f5(%rip), %rsi     # 0x514dc
callq 0x28f40
movq %rax, -0xb0(%rbp)
jmp 0x26ef5
movq -0xb0(%rbp), %rdi
movq -0x88(%rbp), %rsi
addq $0x8, %rsi
callq 0x2a760
movq %rax, -0xb8(%rbp)
jmp 0x26f15
movq -0xa0(%rbp), %rdi
movq -0xb8(%rbp), %rax
movl (%rax), %esi
callq 0x43b0
movq %rax, -0xc0(%rbp)
jmp 0x26f33
movq -0xc0(%rbp), %rdi
leaq 0xfad0(%rip), %rsi      # 0x36a11
callq 0x4210
jmp 0x26f48
jmp 0x271d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x4260
jmp 0x2749e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x4170
jmp 0x2749e
movl -0x14(%rbp), %eax
cmpl 0x2a552(%rip), %eax     # 0x514dc
jne 0x270a7
movq 0x2a029(%rip), %rdi     # 0x50fc0
leaq 0xf847(%rip), %rsi      # 0x367e5
callq 0x4210
movq %rax, -0xc8(%rbp)
jmp 0x26fac
movq -0xc8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x41f0
movq %rax, -0xd0(%rbp)
jmp 0x26fc5
movq -0xd0(%rbp), %rdi
leaq 0xfa0b(%rip), %rsi      # 0x369de
callq 0x4210
movq %rax, -0xd8(%rbp)
jmp 0x26fe1
leaq 0x2a4b0(%rip), %rdi     # 0x51498
leaq 0x2a4ed(%rip), %rsi     # 0x514dc
callq 0x16ef0
movq %rax, -0xe0(%rbp)
jmp 0x26ffd
movq -0x88(%rbp), %rdi
movq -0xe0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rsi
movl 0x2a4bc(%rip), %edx     # 0x514dc
callq 0x230f0
movl %eax, -0xe4(%rbp)
jmp 0x2702d
movq -0xf0(%rbp), %rdi
movl -0xe4(%rbp), %eax
movl %eax, -0x50(%rbp)
leaq -0x50(%rbp), %rsi
callq 0x2a8d0
movq %rax, -0xf8(%rbp)
jmp 0x2704f
movq -0xf8(%rbp), %rdi
movq -0x88(%rbp), %rsi
addq $0x8, %rsi
callq 0x2a760
movq %rax, -0x100(%rbp)
jmp 0x2706f
movq -0xd8(%rbp), %rdi
movq -0x100(%rbp), %rax
movl (%rax), %esi
callq 0x43b0
movq %rax, -0x108(%rbp)
jmp 0x2708d
movq -0x108(%rbp), %rdi
leaq 0xf976(%rip), %rsi      # 0x36a11
callq 0x4210
jmp 0x270a2
jmp 0x271d7
leaq 0x2a3ea(%rip), %rdi     # 0x51498
leaq -0x14(%rbp), %rsi
callq 0x16ef0
movq %rax, -0x110(%rbp)
jmp 0x270c0
movq -0x88(%rbp), %rdi
movq -0x110(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x120(%rbp)
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x230f0
movl %eax, -0x114(%rbp)
jmp 0x270ed
movq -0x120(%rbp), %rdi
movl -0x114(%rbp), %eax
movl %eax, -0x58(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x2a8d0
movq %rax, -0x128(%rbp)
jmp 0x2710f
movq -0x128(%rbp), %rdi
movq -0x88(%rbp), %rsi
addq $0x8, %rsi
callq 0x2a760
movq %rax, -0x130(%rbp)
jmp 0x2712f
movq -0x130(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movq 0x29e7e(%rip), %rdi     # 0x50fc0
leaq 0xf69c(%rip), %rsi      # 0x367e5
callq 0x4210
movq %rax, -0x138(%rbp)
jmp 0x27157
movq -0x138(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x41f0
movq %rax, -0x140(%rbp)
jmp 0x27170
movq -0x140(%rbp), %rdi
leaq 0xf865(%rip), %rsi      # 0x369e3
callq 0x4210
movq %rax, -0x148(%rbp)
jmp 0x2718c
movq -0x148(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x43b0
movq %rax, -0x150(%rbp)
jmp 0x271a4
movq -0x150(%rbp), %rdi
leaq 0xf836(%rip), %rsi      # 0x369e8
callq 0x4210
movq %rax, -0x158(%rbp)
jmp 0x271c0
movq -0x158(%rbp), %rdi
movq 0x29dd2(%rip), %rsi     # 0x50fa0
callq 0x4240
jmp 0x271d5
jmp 0x271d7
jmp 0x271d9
movl $0x1, -0x5c(%rbp)
jmp 0x2748c
movq -0x88(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl %r8d, %ecx
callq 0x274b0
jmp 0x27203
movq -0x88(%rbp), %rax
testb $0x1, 0xc(%rax)
je 0x2728a
leaq 0x2a281(%rip), %rdi     # 0x51498
leaq 0x2a2be(%rip), %rsi     # 0x514dc
callq 0x16ef0
movq %rax, -0x160(%rbp)
jmp 0x2722c
movq -0x160(%rbp), %rdi
addq $0x8, %rdi
leaq 0x2a29e(%rip), %rsi     # 0x514dc
callq 0x28f40
movq %rax, -0x168(%rbp)
jmp 0x2724c
movq -0x168(%rbp), %rdi
movq -0x88(%rbp), %rsi
addq $0x8, %rsi
callq 0x2a760
movq %rax, -0x170(%rbp)
jmp 0x2726c
movq -0x170(%rbp), %rax
movl (%rax), %esi
leaq 0xf3e0(%rip), %rdi      # 0x3665c
xorl %eax, %eax
callq 0x4040
jmp 0x27285
jmp 0x2741b
movl -0x14(%rbp), %eax
cmpl 0x2a249(%rip), %eax     # 0x514dc
jne 0x27348
leaq 0x2a1f8(%rip), %rdi     # 0x51498
leaq 0x2a235(%rip), %rsi     # 0x514dc
callq 0x16ef0
movq %rax, -0x178(%rbp)
jmp 0x272b5
movq -0x88(%rbp), %rdi
movq -0x178(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x188(%rbp)
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x230f0
movl %eax, -0x17c(%rbp)
jmp 0x272e2
movq -0x188(%rbp), %rdi
movl -0x17c(%rbp), %eax
movl %eax, -0x64(%rbp)
leaq -0x64(%rbp), %rsi
callq 0x2a8d0
movq %rax, -0x190(%rbp)
jmp 0x27304
movq -0x190(%rbp), %rdi
movq -0x88(%rbp), %rsi
addq $0x8, %rsi
callq 0x2a760
movq %rax, -0x198(%rbp)
jmp 0x27324
movq -0x198(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %esi
leaq 0xf322(%rip), %rdi      # 0x3665c
xorl %eax, %eax
callq 0x4040
jmp 0x27343
jmp 0x27419
leaq 0x2a149(%rip), %rdi     # 0x51498
leaq -0x14(%rbp), %rsi
callq 0x16ef0
movq %rax, -0x1a0(%rbp)
jmp 0x27361
movq -0x88(%rbp), %rdi
movq -0x1a0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x1b0(%rbp)
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x230f0
movl %eax, -0x1a4(%rbp)
jmp 0x2738e
movq -0x1b0(%rbp), %rdi
movl -0x1a4(%rbp), %eax
movl %eax, -0x6c(%rbp)
leaq -0x6c(%rbp), %rsi
callq 0x2a8d0
movq %rax, -0x1b8(%rbp)
jmp 0x273b0
movq -0x1b8(%rbp), %rdi
movq -0x88(%rbp), %rsi
addq $0x8, %rsi
callq 0x2a760
movq %rax, -0x1c0(%rbp)
jmp 0x273d0
movq -0x1c0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %esi
leaq 0xf604(%rip), %rdi      # 0x369ea
xorl %eax, %eax
callq 0x4040
jmp 0x273ef
cmpl $0x0, -0x68(%rbp)
jl 0x27417
leaq 0xf5fc(%rip), %rdi      # 0x369f8
xorl %eax, %eax
callq 0x4040
jmp 0x27405
leaq 0xf264(%rip), %rdi      # 0x36670
xorl %eax, %eax
callq 0x4040
jmp 0x27415
jmp 0x27417
jmp 0x27419
jmp 0x2741b
leaq 0xf24e(%rip), %rdi      # 0x36670
xorl %eax, %eax
callq 0x4040
jmp 0x2742b
leaq 0xf5d0(%rip), %rdi      # 0x36a02
xorl %eax, %eax
callq 0x4040
jmp 0x2743b
movq 0x29b7e(%rip), %rdi     # 0x50fc0
leaq 0xf39c(%rip), %rsi      # 0x367e5
callq 0x4210
movq %rax, -0x1c8(%rbp)
jmp 0x27457
movq -0x1c8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x41f0
movq %rax, -0x1d0(%rbp)
jmp 0x27470
movq -0x1d0(%rbp), %rdi
leaq 0xf58d(%rip), %rsi      # 0x36a0b
callq 0x4210
jmp 0x27485
movl $0x0, -0x5c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x4170
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x43d0
nopw (%rax,%rax)