// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movl %edx, -0x24(%rbp)
leaq 0x5e3e(%rip), %rax      # 0x139c4
leaq 0x5e3c(%rip), %rsi      # 0x139c9
testl %ecx, %ecx
cmovneq %rax, %rsi
leaq -0x48(%rbp), %rdi
leaq -0x28(%rbp), %rdx
callq 0x30e0
movq 0x18(%rbx), %rax
cmpq 0x10(%rbx), %rax
je 0xdc02
pushq $-0x1
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
movl %ecx, %r8d
callq 0xdf20
cmpb $0x1, 0xc(%rbx)
jne 0xdc88
leaq 0xf899(%rip), %rdi      # 0x1d468
leaq 0xf8d6(%rip), %rsi      # 0x1d4ac
callq 0x9d9e
addq $0x8, %rax
leaq 0xf8c6(%rip), %rsi      # 0x1d4ac
movq %rax, %rdi
callq 0xf958
addq $0x8, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10ea2
jmp 0xdcdc
cmpb $0x1, 0xc(%rbx)
jne 0xdd48
movq 0xf3ad(%rip), %rdi      # 0x1cfc0
leaq 0x5bcf(%rip), %rsi      # 0x137e9
callq 0x31e0
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x31c0
leaq 0x5d9b(%rip), %rsi      # 0x139cd
movq %rax, %rdi
callq 0x31e0
movq %rax, %r14
leaq 0xf824(%rip), %rdi      # 0x1d468
leaq 0xf861(%rip), %rsi      # 0x1d4ac
callq 0x9d9e
addq $0x8, %rax
leaq 0xf851(%rip), %rsi      # 0x1d4ac
movq %rax, %rdi
callq 0xf958
addq $0x8, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10ea2
movl (%rax), %esi
movq %r14, %rdi
callq 0x3370
leaq 0x5d6a(%rip), %rsi      # 0x139ed
jmp 0xdd2a
movl -0x24(%rbp), %eax
cmpl 0xf81b(%rip), %eax      # 0x1d4ac
jne 0xddec
leaq 0xf7ca(%rip), %rdi      # 0x1d468
leaq 0xf807(%rip), %rsi      # 0x1d4ac
callq 0x9d9e
movq %rax, %r15
movl -0x24(%rbp), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xbcac
addq $0x8, %r15
leaq -0x28(%rbp), %rsi
movl %eax, (%rsi)
movq %r15, %rdi
callq 0x10fb0
addq $0x8, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10ea2
movl (%rax), %esi
leaq 0x591d(%rip), %rdi      # 0x13602
xorl %eax, %eax
callq 0x3040
leaq 0x5965(%rip), %rdi      # 0x13658
callq 0x3310
leaq 0x5e0d(%rip), %rdi      # 0x13b0c
callq 0x3310
movq 0xf2b5(%rip), %rdi      # 0x1cfc0
leaq 0x5ad7(%rip), %rsi      # 0x137e9
callq 0x31e0
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x31c0
leaq 0x5cbd(%rip), %rsi      # 0x139e7
movq %rax, %rdi
callq 0x31e0
leaq -0x48(%rbp), %rdi
callq 0x3120
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl %r15d, 0xf75d(%rip)     # 0x1d4ac
jne 0xde65
movq 0xf264(%rip), %rdi      # 0x1cfc0
leaq 0x5a86(%rip), %rsi      # 0x137e9
callq 0x31e0
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x31c0
leaq 0x5c52(%rip), %rsi      # 0x139cd
movq %rax, %rdi
callq 0x31e0
movq %rax, %r15
leaq 0xf6db(%rip), %rdi      # 0x1d468
leaq 0xf718(%rip), %rsi      # 0x1d4ac
callq 0x9d9e
movq %rax, %r12
movl 0xf70a(%rip), %edx      # 0x1d4ac
movq %rbx, %rdi
movq %r14, %rsi
callq 0xbcac
addq $0x8, %r12
leaq -0x28(%rbp), %rsi
movl %eax, (%rsi)
movq %r12, %rdi
callq 0x10fb0
addq $0x8, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10ea2
movl (%rax), %esi
movq %r15, %rdi
callq 0x3370
leaq 0x5c0e(%rip), %rsi      # 0x139ed
movq %rax, %rdi
callq 0x31e0
jmp 0xdd32
leaq 0xf675(%rip), %rdi      # 0x1d468
leaq -0x24(%rbp), %rsi
callq 0x9d9e
movq %rax, %r15
movl -0x24(%rbp), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xbcac
addq $0x8, %r15
leaq -0x28(%rbp), %rsi
movl %eax, (%rsi)
movq %r15, %rdi
callq 0x10fb0
addq $0x8, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10ea2
movl (%rax), %ebx
leaq 0x5ba2(%rip), %rdi      # 0x139d9
movl %ebx, %esi
xorl %eax, %eax
callq 0x3040
testl %ebx, %ebx
js 0xdcec
leaq 0x5cca(%rip), %rdi      # 0x13b19
callq 0x3310
leaq 0x57fd(%rip), %rdi      # 0x13658
callq 0x3310
jmp 0xdcec
leaq 0xf5fc(%rip), %rdi      # 0x1d468
leaq -0x24(%rbp), %rsi
callq 0x9d9e
movq %rax, %r15
movl -0x24(%rbp), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xbcac
addq $0x8, %r15
leaq -0x28(%rbp), %rsi
movl %eax, (%rsi)
movq %r15, %rdi
callq 0x10fb0
addq $0x8, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10ea2
movl (%rax), %ebx
movq 0xf110(%rip), %rdi      # 0x1cfc0
leaq 0x5932(%rip), %rsi      # 0x137e9
callq 0x31e0
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x31c0
leaq 0x5b03(%rip), %rsi      # 0x139d2
movq %rax, %rdi
callq 0x31e0
movq %rax, %rdi
movl %ebx, %esi
callq 0x3370
leaq 0x5aef(%rip), %rsi      # 0x139d7
movq %rax, %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3130
jmp 0xdd32
jmp 0xdf0b
jmp 0xdf0b
jmp 0xdf0b
jmp 0xdf0b
jmp 0xdf0b
jmp 0xdf0b
jmp 0xdf0b
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x3390
nop