// File: /workspace/github_cpp_makefile_star2_O3/CHEN-Zhihan[P]Compiler/Node.cpp
// Function: VarNode::assign(std::vector<int, std::allocator<int>>&, int) const
void VarNode::assign(vector<int> & sList, int functionID) const {
    if (functionTable.count(i) != 0) {
        cerr << "Redefinition of function: " << reverseLookup[i] << endl;
        exit(-1);
    }
    for (auto & i : subscriptions) {
        i->check(sList, functionID);
        i->evaluate();
    }
    if (global) {
        if (functionID == GLOBAL) {
            cerr << "Refer to global variable " << reverseLookup[i] << " in the global scope" << endl;
            exit(-1);
        }
        if (variableTable[GLOBAL].count(i) != 0 and sizeMap[{GLOBAL, i}].size() != subscriptions.size()) {
            cerr << "Invalid assignment to array " << reverseLookup[i] << endl;
            exit(-1);
        }
        if (variableTable[GLOBAL].count(i) == 0) {
            if (subscriptions.size() != 0) {
                cerr << "Invalid assignment to array " << reverseLookup[i] << endl;
                exit(-1);
            }
            variableTable[GLOBAL].insert(i);
            addressTable[GLOBAL].second[GLOBAL][i] = addressTable[GLOBAL].first++;
            sizeMap[{GLOBAL, i}] = vector<int>();
        }
    } else {
        int s = getDefinitionScope(sList, functionID);
        if (s != NOT_FOUND and sizeMap[{s, i}].size() != subscriptions.size()) {
            cerr << "Invalid assignment to array " << reverseLookup[i] << endl;
            exit(-1);
        }
        if (s == NOT_FOUND) {
            if (subscriptions.size() != 0) {
                cerr << "Invalid assignment to array " << reverseLookup[i] << endl;
                exit(-1);
            }
            auto address = findSpace(functionID, 1);
            if (address == -1) {
                addressTable[functionID].second[sList.back()][i] = addressTable[functionID].first++;
            } else {
                addressTable[functionID].second[sList.back()][i] = address;
            }
            variableTable[sList.back()].insert(i);
            #if DEBUG
                cerr << "add variable " << i << " to " << sList.back() << endl;
            #endif
            sizeMap[{sList.back(), i}] = vector<int>();
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %r14
movl %edx, -0x34(%rbp)
leaq 0x8(%rdi), %rsi
leaq 0xf248(%rip), %rdi      # 0x1c368
movq %rsi, -0x40(%rbp)
callq 0x11d24
testq %rax, %rax
jne 0xd3c1
movq 0x10(%r14), %r13
movq 0x18(%r14), %rbx
cmpq %rbx, %r13
je 0xd15e
movq (%r13), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl %r12d, %edx
callq *0x8(%rax)
movq (%r13), %rdi
callq 0xd472
addq $0x10, %r13
jmp 0xd13a
cmpb $0x0, 0xc(%r14)
je 0xd28b
cmpl %r12d, 0xf354(%rip)     # 0x1c4c4
movq -0x40(%rbp), %r13
je 0xd3dd
leaq 0xf21f(%rip), %rdi      # 0x1c3a0
leaq 0xf33c(%rip), %rsi      # 0x1c4c4
callq 0xb9ba
movq %rax, %rdi
movq %r13, %rsi
callq 0x11a64
testq %rax, %rax
je 0xd1dc
movl 0xf321(%rip), %eax      # 0x1c4c4
leaq -0x30(%rbp), %rsi
movl %eax, (%rsi)
movl 0x8(%r14), %eax
movl %eax, 0x4(%rsi)
leaq 0xf311(%rip), %rdi      # 0x1c4c8
callq 0x10704
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
movq 0x18(%r14), %rax
subq 0x10(%r14), %rax
sarq $0x4, %rax
cmpq %rax, %rcx
jne 0xd433
leaq 0xf1bd(%rip), %rdi      # 0x1c3a0
leaq 0xf2da(%rip), %rsi      # 0x1c4c4
callq 0xb9ba
movq %rax, %rdi
movq %r13, %rsi
callq 0x11a64
testq %rax, %rax
jne 0xd3b2
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rax
jne 0xd433
leaq 0xf188(%rip), %rdi      # 0x1c3a0
leaq 0xf2a5(%rip), %r15      # 0x1c4c4
movq %r15, %rsi
callq 0xb9ba
leaq -0x30(%rbp), %r14
movq %rax, (%r14)
movq %rax, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0xbcaa
leaq 0xf23d(%rip), %r12      # 0x1c480
movq %r12, %rdi
movq %r15, %rsi
callq 0xb1ce
movl (%rax), %ebx
leal 0x1(%rbx), %ecx
movl %ecx, (%rax)
movq %r12, %rdi
movq %r15, %rsi
callq 0xb1ce
leaq 0x8(%rax), %rdi
movq %r15, %rsi
callq 0x11302
movq %rax, %rdi
movq %r13, %rsi
callq 0x1237e
movl %ebx, (%rax)
movl 0xf245(%rip), %eax      # 0x1c4c4
movl %eax, (%r14)
movl (%r13), %eax
jmp 0xd34c
movq %r14, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0xce4e
cmpl $0x7d0, %eax            # imm = 0x7D0
movq -0x40(%rbp), %rbx
jne 0xd37d
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rax
jne 0xd41b
movl %r12d, %edi
movl $0x1, %esi
callq 0xc22c
movl %eax, %r14d
leaq 0xf1b3(%rip), %rdi      # 0x1c480
leaq -0x34(%rbp), %rsi
callq 0xb1ce
cmpl $-0x1, %r14d
jne 0xd2f5
movl (%rax), %r14d
leal 0x1(%r14), %ecx
movl %ecx, (%rax)
leaq 0xf194(%rip), %rdi      # 0x1c480
leaq -0x34(%rbp), %rsi
callq 0xb1ce
addq $0x8, %rax
movq 0x8(%r15), %rsi
addq $-0x4, %rsi
movq %rax, %rdi
callq 0x11302
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1237e
movl %r14d, (%rax)
movq 0x8(%r15), %rsi
addq $-0x4, %rsi
leaq 0xf07a(%rip), %rdi      # 0x1c3a0
callq 0xb9ba
leaq -0x30(%rbp), %r14
movq %rax, (%r14)
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xbcaa
movq 0x8(%r15), %rax
movl -0x4(%rax), %eax
movl %eax, (%r14)
movl (%rbx), %eax
movl %eax, 0x4(%r14)
leaq 0xf171(%rip), %rdi      # 0x1c4c8
leaq -0x30(%rbp), %rsi
callq 0x10704
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0xd3b2
callq 0x41e0
jmp 0xd3b2
leaq -0x30(%rbp), %rsi
movl %eax, (%rsi)
movl 0x8(%r14), %eax
movl %eax, 0x4(%rsi)
leaq 0xf137(%rip), %rdi      # 0x1c4c8
callq 0x10704
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
movq 0x18(%r14), %rax
subq 0x10(%r14), %rax
sarq $0x4, %rax
cmpq %rax, %rcx
jne 0xd41b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xec20(%rip), %rdi      # 0x1bfe8
leaq 0x6ec7(%rip), %rsi      # 0x14296
callq 0x4200
movq -0x40(%rbp), %rcx
movslq (%rcx), %rsi
jmp 0xd44a
movq 0xec04(%rip), %rdi      # 0x1bfe8
leaq 0x7656(%rip), %rsi      # 0x14a41
callq 0x4200
movslq (%r13), %rsi
leaq 0xef35(%rip), %rcx      # 0x1c330
shlq $0x5, %rsi
addq (%rcx), %rsi
movq %rax, %rdi
callq 0x41d0
leaq 0x74bd(%rip), %rsi      # 0x148ce
movq %rax, %rdi
callq 0x4200
jmp 0xd460
movq 0xebc6(%rip), %rdi      # 0x1bfe8
leaq 0x764d(%rip), %rsi      # 0x14a76
callq 0x4200
movslq (%rbx), %rsi
jmp 0xd44a
movq 0xebae(%rip), %rdi      # 0x1bfe8
leaq 0x7635(%rip), %rsi      # 0x14a76
callq 0x4200
movslq (%r13), %rsi
leaq 0xeedf(%rip), %rcx      # 0x1c330
shlq $0x5, %rsi
addq (%rcx), %rsi
movq %rax, %rdi
callq 0x41d0
movq %rax, %rdi
callq 0x4120
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42a0