// File: CHEN-Zhihan[P]Compiler/Node.cpp
// Function: CallNode::check(std::vector<int, std::allocator<int>>&, int)
void CallNode::check(vector<int> & sList, int functionID) {
    if (i < 9) {
        if (arguments.size() != 1 and i >= 3) {
            cerr << reverseLookup[i] << " expects 1 argument, got " << arguments.size() << endl;
            exit(-1); 
        }
        if (arguments.size() != 0 and i < 3) {
            cerr << reverseLookup[i] << " expects 0 argument, got " << arguments.size() << endl;
            exit(-1); 
        }
        if (i >= 3) {
            auto first = arguments.front();
            first->check(sList, functionID);
        }
    } else {
        if (functionTable.count(i) == 0) {
            cerr << "Call to undefined function: " << reverseLookup[i] << endl;
            exit(-1);
        }
        auto f = functionTable[i];
        if (f->getNumParameters() != arguments.size()) {
            cerr << reverseLookup[i] << " expects " << f->getNumParameters()
                 << " argument(s), got " << arguments.size() << endl;
            exit(-1);
        }
        f->match(arguments, sList, functionID);
        for (const auto & i: arguments) {
            i->check(sList, functionID);
        }
        if (functionLabel.count(i) == 0) {
            functionLabel[i] = lbl++;
            sList.push_back(i);
            f->checkStmt(sList, i);
            sList.pop_back();
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpl $0x9, 0x8(%rax)
jge 0x26ae1
movq -0x68(%rbp), %rdi
addq $0x10, %rdi
callq 0x2a210
cmpq $0x1, %rax
je 0x269ed
movq -0x68(%rbp), %rax
cmpl $0x3, 0x8(%rax)
jl 0x269ed
movq -0x68(%rbp), %rax
movslq 0x8(%rax), %rsi
leaq 0x2a9b4(%rip), %rdi     # 0x51348
callq 0x29680
movq %rax, %rsi
movq 0x2a64d(%rip), %rdi     # 0x50ff0
callq 0x41f0
movq %rax, %rdi
leaq 0xffb5(%rip), %rsi      # 0x36967
callq 0x4210
movq -0x68(%rbp), %rdi
movq %rax, -0x70(%rbp)
addq $0x10, %rdi
callq 0x2a210
movq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x4090
movq %rax, %rdi
movq 0x2a5c2(%rip), %rsi     # 0x50fa0
callq 0x4240
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42c0
movq -0x68(%rbp), %rdi
addq $0x10, %rdi
callq 0x2a210
cmpq $0x0, %rax
je 0x26a72
movq -0x68(%rbp), %rax
cmpl $0x3, 0x8(%rax)
jge 0x26a72
movq -0x68(%rbp), %rax
movslq 0x8(%rax), %rsi
leaq 0x2a92f(%rip), %rdi     # 0x51348
callq 0x29680
movq %rax, %rsi
movq 0x2a5c8(%rip), %rdi     # 0x50ff0
callq 0x41f0
movq %rax, %rdi
leaq 0xff4a(%rip), %rsi      # 0x36981
callq 0x4210
movq -0x68(%rbp), %rdi
movq %rax, -0x78(%rbp)
addq $0x10, %rdi
callq 0x2a210
movq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x4090
movq %rax, %rdi
movq 0x2a53d(%rip), %rsi     # 0x50fa0
callq 0x4240
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42c0
movq -0x68(%rbp), %rax
cmpl $0x3, 0x8(%rax)
jl 0x26adc
movq -0x68(%rbp), %rdi
addq $0x10, %rdi
callq 0x2a790
movq %rax, %rsi
leaq -0x28(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x2a2a0
movq -0x80(%rbp), %rdi
callq 0x299a0
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0x26ab7
leaq -0x28(%rbp), %rdi
callq 0xbc30
jmp 0x26adc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xbc30
jmp 0x26d41
jmp 0x26d38
movq -0x68(%rbp), %rsi
addq $0x8, %rsi
leaq 0x2a890(%rip), %rdi     # 0x51380
callq 0x29f80
cmpq $0x0, %rax
jne 0x26b54
movq 0x2a4ee(%rip), %rdi     # 0x50ff0
leaq 0xfe92(%rip), %rsi      # 0x3699b
callq 0x4210
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, -0x88(%rbp)
movslq 0x8(%rax), %rsi
leaq 0x2a821(%rip), %rdi     # 0x51348
callq 0x29680
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x41f0
movq %rax, %rdi
movq 0x2a45b(%rip), %rsi     # 0x50fa0
callq 0x4240
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42c0
movq -0x68(%rbp), %rsi
addq $0x8, %rsi
leaq 0x2a81d(%rip), %rdi     # 0x51380
callq 0x29ff0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x256a0
movq -0x68(%rbp), %rdi
movq %rax, -0x90(%rbp)
addq $0x10, %rdi
callq 0x2a210
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
je 0x26c3b
movq -0x68(%rbp), %rax
movslq 0x8(%rax), %rsi
leaq 0x2a79a(%rip), %rdi     # 0x51348
callq 0x29680
movq %rax, %rsi
movq 0x2a433(%rip), %rdi     # 0x50ff0
callq 0x41f0
movq %rax, %rdi
leaq 0xfdec(%rip), %rsi      # 0x369b8
callq 0x4210
movq %rax, -0xa0(%rbp)
movq -0x40(%rbp), %rdi
callq 0x256a0
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x4090
movq %rax, %rdi
leaq 0xfdc8(%rip), %rsi      # 0x369c2
callq 0x4210
movq -0x68(%rbp), %rdi
movq %rax, -0x98(%rbp)
addq $0x10, %rdi
callq 0x2a210
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x4090
movq %rax, %rdi
movq 0x2a374(%rip), %rsi     # 0x50fa0
callq 0x4240
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42c0
movq -0x68(%rbp), %rsi
movq -0x40(%rbp), %rdi
addq $0x10, %rsi
movq -0x10(%rbp), %rdx
movl -0x14(%rbp), %ecx
callq 0x26040
movq -0x68(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2a7c0
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2a7f0
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2a820
testb $0x1, %al
jne 0x26c8c
jmp 0x26cbd
leaq -0x50(%rbp), %rdi
callq 0x2a860
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x299a0
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movq (%rdi), %rax
callq *0x8(%rax)
leaq -0x50(%rbp), %rdi
callq 0x2a880
jmp 0x26c79
movq -0x68(%rbp), %rsi
addq $0x8, %rsi
leaq 0x2a75c(%rip), %rdi     # 0x51428
callq 0x2a8a0
cmpq $0x0, %rax
jne 0x26d36
movq -0x68(%rbp), %rsi
movl 0x2a82f(%rip), %eax     # 0x51510
movl %eax, -0xa4(%rbp)
addl $0x1, %eax
movl %eax, 0x2a820(%rip)     # 0x51510
addq $0x8, %rsi
leaq 0x2a72d(%rip), %rdi     # 0x51428
callq 0x2a760
movl -0xa4(%rbp), %ecx
movq -0x68(%rbp), %rsi
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
addq $0x8, %rsi
callq 0x29b00
movq -0x68(%rbp), %rax
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl 0x8(%rax), %edx
callq 0x25770
movq -0x10(%rbp), %rdi
callq 0x29bb0
jmp 0x26d38
addq $0xb0, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x43d0
nopw (%rax,%rax)