// File: CHEN-Zhihan[P]Compiler/Node.cpp
// Function: FunctionNode::match(std::vector<std::shared_ptr<ExprNode>, std::allocator<std::shared_ptr<ExprNode>>> const&, std::vector<int, std::allocator<int>> const&, int) const
void FunctionNode::match(const vector<shared_ptr<ExprNode> >& arguments, const vector<int>& sList, int base) const {
    for (int i = 0; i != arguments.size(); ++i) {
        auto parameter = parameters[i];
        auto argument = arguments[i];
        if (parameter->getDimensions() != 0) {
            if (argument->oper != VAR) {
                cerr << "Invalid " << i << " th argument for function " << reverseLookup[this->i] << endl;
                exit(-1);
            }
            auto v = dynamic_pointer_cast<VarNode>(argument->op[0]);
            auto dimension = sizeMap[{v->getDefinitionScope(sList, base), v->getID()}];
            if (parameter->getDimensions() != dimension.size()) {
                #if DEBUG
                    cerr << "expect " << parameter->getDimensions() <<
                    " got " << dimension.size() << " for function " << reverseLookup[this->i] << endl;
                #endif
                cerr << "Invalid " << i << " th argument for function " << reverseLookup[this->i] << endl;
                exit(-1);
            }
            auto pDimension = parameter->getDimension();
            for (auto j = 1; j != pDimension.size(); ++j) {
                if (pDimension[j] != dimension[j]) {
                    cerr << "Invalid " << i << " th argument for function, dimension not match" << endl;
                    exit(-1);
                }
            }
            v->match();
            sizeMap[{this->i, parameter->getID()}] = dimension;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl $0x0, -0x20(%rbp)
movslq -0x20(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2a210
movq %rax, %rcx
movq -0xc0(%rbp), %rax
cmpq %rcx, %rax
je 0x26597
movq -0xb8(%rbp), %rdi
addq $0x10, %rdi
movslq -0x20(%rbp), %rsi
callq 0x2a230
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x2a250
movq -0x10(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x2a280
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x2a2a0
movq -0xd0(%rbp), %rdi
callq 0x292f0
movq %rax, %rdi
callq 0x230d0
movl %eax, -0xc4(%rbp)
jmp 0x260ef
movl -0xc4(%rbp), %eax
cmpl $0x0, %eax
je 0x26563
leaq -0x40(%rbp), %rdi
callq 0x299a0
cmpl $-0x5, 0x8(%rax)
je 0x261c0
movq 0x2aed8(%rip), %rdi     # 0x50ff0
leaq 0x107e4(%rip), %rsi     # 0x36903
callq 0x4210
movq %rax, -0xd8(%rbp)
jmp 0x2612d
movq -0xd8(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x43b0
movq %rax, -0xe0(%rbp)
jmp 0x26145
movq -0xe0(%rbp), %rdi
leaq 0x107b9(%rip), %rsi     # 0x3690c
callq 0x4210
movq %rax, -0xe8(%rbp)
jmp 0x26161
movq -0xb8(%rbp), %rax
movslq 0x8(%rax), %rsi
leaq 0x2b1d5(%rip), %rdi     # 0x51348
callq 0x29680
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
callq 0x41f0
movq %rax, -0xf0(%rbp)
jmp 0x26190
movq -0xf0(%rbp), %rdi
movq 0x2ae02(%rip), %rsi     # 0x50fa0
callq 0x4240
jmp 0x261a5
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x26583
leaq -0x40(%rbp), %rdi
callq 0x299a0
movq %rax, %rdi
addq $0x18, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x29460
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0xbb80
movq -0x100(%rbp), %rdi
callq 0x292f0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x230f0
movl %eax, -0xf4(%rbp)
jmp 0x2620f
movl -0xf4(%rbp), %eax
movl %eax, -0x84(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x292f0
movq %rax, %rdi
callq 0x231c0
movl %eax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x84(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x28ee0
jmp 0x2624b
leaq 0x2b28e(%rip), %rdi     # 0x514e0
leaq -0x80(%rbp), %rsi
callq 0x28f70
movq %rax, -0x108(%rbp)
jmp 0x26264
movq -0x108(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x29080
jmp 0x26276
leaq -0x30(%rbp), %rdi
callq 0x292f0
movq %rax, %rdi
callq 0x230d0
movl %eax, -0x10c(%rbp)
jmp 0x2628f
movl -0x10c(%rbp), %eax
cltq
movq %rax, -0x118(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x29660
movq %rax, %rcx
movq -0x118(%rbp), %rax
cmpq %rcx, %rax
je 0x2637a
movq 0x2ad2f(%rip), %rdi     # 0x50ff0
leaq 0x1063b(%rip), %rsi     # 0x36903
callq 0x4210
movq %rax, -0x120(%rbp)
jmp 0x262d6
movq -0x120(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x43b0
movq %rax, -0x128(%rbp)
jmp 0x262ee
movq -0x128(%rbp), %rdi
leaq 0x10610(%rip), %rsi     # 0x3690c
callq 0x4210
movq %rax, -0x130(%rbp)
jmp 0x2630a
movq -0xb8(%rbp), %rax
movslq 0x8(%rax), %rsi
leaq 0x2b02c(%rip), %rdi     # 0x51348
callq 0x29680
movq -0x130(%rbp), %rdi
movq %rax, %rsi
callq 0x41f0
movq %rax, -0x138(%rbp)
jmp 0x26339
movq -0x138(%rbp), %rdi
movq 0x2ac59(%rip), %rsi     # 0x50fa0
callq 0x4240
jmp 0x2634e
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x26558
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x2654f
leaq -0x30(%rbp), %rdi
callq 0x292f0
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x265b0
jmp 0x26394
movl $0x1, -0xa4(%rbp)
movslq -0xa4(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x29660
movq %rax, %rcx
movq -0x140(%rbp), %rax
cmpq %rcx, %rax
je 0x264a9
movslq -0xa4(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x29d00
movl (%rax), %eax
movl %eax, -0x144(%rbp)
movslq -0xa4(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x29d00
movq %rax, %rcx
movl -0x144(%rbp), %eax
cmpl (%rcx), %eax
je 0x26493
movq 0x2abe2(%rip), %rdi     # 0x50ff0
leaq 0x104ee(%rip), %rsi     # 0x36903
callq 0x4210
movq %rax, -0x150(%rbp)
jmp 0x26423
movq -0x150(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x43b0
movq %rax, -0x158(%rbp)
jmp 0x2643b
movq -0x158(%rbp), %rdi
leaq 0x104de(%rip), %rsi     # 0x36927
callq 0x4210
movq %rax, -0x160(%rbp)
jmp 0x26457
movq -0x160(%rbp), %rdi
movq 0x2ab3b(%rip), %rsi     # 0x50fa0
callq 0x4240
jmp 0x2646c
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x16fe0
jmp 0x2654f
jmp 0x26495
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x2639e
leaq -0x60(%rbp), %rdi
callq 0x292f0
movq %rax, %rdi
callq 0x26700
jmp 0x264bc
movq -0xb8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x168(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x292f0
movq %rax, %rdi
callq 0x231c0
movq -0x168(%rbp), %rsi
movl %eax, -0xb0(%rbp)
leaq -0xac(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x2a2d0
jmp 0x26501
leaq 0x2afd8(%rip), %rdi     # 0x514e0
leaq -0xac(%rbp), %rsi
callq 0x28f70
movq %rax, -0x170(%rbp)
jmp 0x2651d
movq -0x170(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2a300
jmp 0x2652f
leaq -0xa0(%rbp), %rdi
callq 0x16fe0
leaq -0x78(%rbp), %rdi
callq 0x16fe0
leaq -0x60(%rbp), %rdi
callq 0xbc50
jmp 0x26563
leaq -0x78(%rbp), %rdi
callq 0x16fe0
leaq -0x60(%rbp), %rdi
callq 0xbc50
jmp 0x26583
leaq -0x40(%rbp), %rdi
callq 0xbc30
leaq -0x30(%rbp), %rdi
callq 0xbc50
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2606c
leaq -0x40(%rbp), %rdi
callq 0xbc30
leaq -0x30(%rbp), %rdi
callq 0xbc50
jmp 0x265a0
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x43d0
nopl (%rax)