// File: CHEN-Zhihan[P]Compiler/Node.cpp
// Function: VarNode::check(std::vector<int, std::allocator<int>>&, int)
void VarNode::check(vector<int>& sList, int functionID) {
    if (global) {
        if (variableTable[GLOBAL].count(i) == 0) {
            cerr << "Undefined reference to global variable: " << reverseLookup[i] << endl;
            exit(-1);
        }
        if (functionID == GLOBAL) {
            cerr << "Refer to a global variable: " << reverseLookup[i] << " in the global scope" << endl;
            exit(-1);
        }
    } else {
        auto s = getDefinitionScope(sList, functionID);
        if (s == NOT_FOUND) {
            cerr << "Undefined reference to variable " << reverseLookup[i] << endl;
            exit(-1);
        }
    }
    for (auto & i : subscriptions) {
        i->check(sList, functionID);
        i->evaluate();
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
testb $0x1, 0xc(%rax)
je 0x28720
leaq 0x28d7c(%rip), %rdi     # 0x513b8
leaq 0x28e99(%rip), %rsi     # 0x514dc
callq 0x17400
movq -0x40(%rbp), %rsi
movq %rax, %rdi
addq $0x8, %rsi
callq 0x29540
cmpq $0x0, %rax
jne 0x286b1
movq 0x2898b(%rip), %rdi     # 0x50ff0
leaq 0xe431(%rip), %rsi      # 0x36a9d
callq 0x4210
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, -0x48(%rbp)
movslq 0x8(%rax), %rsi
leaq 0x28cc1(%rip), %rdi     # 0x51348
callq 0x29680
movq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x41f0
movq %rax, %rdi
movq 0x288fe(%rip), %rsi     # 0x50fa0
callq 0x4240
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42c0
movl -0x14(%rbp), %eax
cmpl 0x28e22(%rip), %eax     # 0x514dc
jne 0x2871e
movq 0x2892d(%rip), %rdi     # 0x50ff0
leaq 0xe3fc(%rip), %rsi      # 0x36ac6
callq 0x4210
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, -0x50(%rbp)
movslq 0x8(%rax), %rsi
leaq 0x28c63(%rip), %rdi     # 0x51348
callq 0x29680
movq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x41f0
movq %rax, %rdi
leaq 0xe1bf(%rip), %rsi      # 0x368bf
callq 0x4210
movq %rax, %rdi
movq 0x28891(%rip), %rsi     # 0x50fa0
callq 0x4240
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42c0
jmp 0x28791
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x230f0
movl %eax, -0x18(%rbp)
cmpl $0x7d0, -0x18(%rbp)     # imm = 0x7D0
jne 0x2878f
movq 0x288ad(%rip), %rdi     # 0x50ff0
leaq 0xe399(%rip), %rsi      # 0x36ae3
callq 0x4210
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, -0x58(%rbp)
movslq 0x8(%rax), %rsi
leaq 0x28be3(%rip), %rdi     # 0x51348
callq 0x29680
movq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0x41f0
movq %rax, %rdi
movq 0x28820(%rip), %rsi     # 0x50fa0
callq 0x4240
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42c0
jmp 0x28791
movq -0x40(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2a7c0
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2a7f0
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2a820
testb $0x1, %al
jne 0x287ca
jmp 0x2880c
leaq -0x28(%rbp), %rdi
callq 0x2a860
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x299a0
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movq (%rdi), %rax
callq *0x8(%rax)
movq -0x38(%rbp), %rdi
callq 0x299a0
movq %rax, %rdi
callq 0x23d40
leaq -0x28(%rbp), %rdi
callq 0x2a880
jmp 0x287b7
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)