// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %r14
movl %edx, -0x34(%rbp)
leaq 0x8(%rdi), %rsi
leaq 0x1144e(%rip), %rdi     # 0x1d350
movq %rsi, -0x30(%rbp)
callq 0x1055c
testq %rax, %rax
jne 0xc1b9
movq 0x10(%r14), %r13
movq 0x18(%r14), %rbx
cmpq %rbx, %r13
je 0xbf40
movq (%r13), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl %r12d, %edx
callq *0x8(%rax)
movq (%r13), %rdi
callq 0xc294
addq $0x10, %r13
jmp 0xbf1c
cmpb $0x0, 0xc(%r14)
je 0xc081
cmpl %r12d, 0x1155a(%rip)    # 0x1d4ac
je 0xc1d8
leaq 0x11429(%rip), %rdi     # 0x1d388
leaq 0x11546(%rip), %rsi     # 0x1d4ac
callq 0xa758
movq %rax, %rdi
movq -0x30(%rbp), %r12
movq %r12, %rsi
callq 0x1021c
testq %rax, %rax
je 0xbfbe
movl 0x11527(%rip), %eax     # 0x1d4ac
leaq -0x50(%rbp), %rsi
movl %eax, (%rsi)
movl 0x8(%r14), %eax
movl %eax, 0x4(%rsi)
leaq 0x11517(%rip), %rdi     # 0x1d4b0
callq 0xeb8a
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 0xc219
leaq 0x113c3(%rip), %rdi     # 0x1d388
leaq 0x114e0(%rip), %rsi     # 0x1d4ac
callq 0xa758
movq %rax, %rdi
movq %r12, %rsi
callq 0x1021c
testq %rax, %rax
jne 0xc1aa
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rax
jne 0xc219
leaq 0x1138e(%rip), %rdi     # 0x1d388
leaq 0x114ab(%rip), %r14     # 0x1d4ac
movq %r14, %rsi
callq 0xa758
movq %rax, %rdi
movq %r12, %rsi
callq 0xab0e
leaq 0x1144d(%rip), %r15     # 0x1d468
movq %r15, %rdi
movq %r14, %rsi
callq 0x9d9e
movl (%rax), %ebx
leal 0x1(%rbx), %ecx
movl %ecx, (%rax)
movq %r15, %rdi
movq %r14, %rsi
callq 0x9d9e
leaq 0x8(%rax), %rdi
movq %r14, %rsi
callq 0xf958
movq %rax, %rdi
movq %r12, %rsi
callq 0x10ea2
movl %ebx, (%rax)
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
movl 0x11449(%rip), %eax     # 0x1d4ac
leaq -0x58(%rbp), %rsi
movl %eax, (%rsi)
movl (%r12), %eax
movl %eax, 0x4(%rsi)
leaq 0x11439(%rip), %rdi     # 0x1d4b0
callq 0xeb8a
jmp 0xc154
movq %r14, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0xbcac
cmpl $0x7d0, %eax            # imm = 0x7D0
jne 0xc16d
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rax
jne 0xc232
pushq $0x1
popq %rsi
movl %r12d, %edi
callq 0xb384
movl %eax, %r14d
leaq 0x113ab(%rip), %rdi     # 0x1d468
leaq -0x34(%rbp), %rsi
callq 0x9d9e
cmpl $-0x1, %r14d
jne 0xc0e5
movl (%rax), %r14d
leal 0x1(%r14), %ecx
movl %ecx, (%rax)
leaq 0x1138c(%rip), %rdi     # 0x1d468
leaq -0x34(%rbp), %rsi
callq 0x9d9e
movq -0x30(%rbp), %rbx
addq $0x8, %rax
movq 0x8(%r15), %rsi
addq $-0x4, %rsi
movq %rax, %rdi
callq 0xf958
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10ea2
movl %r14d, (%rax)
movq 0x8(%r15), %rsi
addq $-0x4, %rsi
leaq 0x1126e(%rip), %rdi     # 0x1d388
callq 0xa758
movq %rax, %rdi
movq %rbx, %rsi
callq 0xab0e
andq $0x0, -0x40(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq 0x8(%r15), %rax
movl -0x4(%rax), %eax
leaq -0x58(%rbp), %rsi
movl %eax, (%rsi)
movl (%rbx), %eax
movl %eax, 0x4(%rsi)
leaq 0x11361(%rip), %rdi     # 0x1d4b0
callq 0xeb8a
leaq -0x50(%rbp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0xb316
movq %rbx, %rdi
callq 0xa21e
jmp 0xc1aa
leaq -0x50(%rbp), %rsi
movl %eax, (%rsi)
movl 0x8(%r14), %eax
movl %eax, 0x4(%rsi)
leaq 0x1132f(%rip), %rdi     # 0x1d4b0
callq 0xeb8a
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
movq 0x18(%r14), %rax
subq 0x10(%r14), %rax
sarq $0x4, %rax
cmpq %rax, %rcx
movq -0x30(%rbp), %rbx
jne 0xc242
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10e28(%rip), %rdi     # 0x1cfe8
leaq 0x70af(%rip), %rsi      # 0x13276
callq 0x31e0
movq -0x30(%rbp), %rcx
movslq (%rcx), %rsi
jmp 0xc258
movq 0x10e09(%rip), %rdi     # 0x1cfe8
leaq 0x783b(%rip), %rsi      # 0x13a21
callq 0x31e0
movq -0x30(%rbp), %rcx
movslq (%rcx), %rsi
leaq 0x1111f(%rip), %rcx     # 0x1d318
shlq $0x5, %rsi
addq (%rcx), %rsi
movq %rax, %rdi
callq 0x31c0
leaq 0x769f(%rip), %rsi      # 0x138ae
movq %rax, %rdi
callq 0x31e0
jmp 0xc26e
movq 0x10dc8(%rip), %rdi     # 0x1cfe8
leaq 0x782f(%rip), %rsi      # 0x13a56
callq 0x31e0
movslq (%r12), %rsi
jmp 0xc258
movq 0x10daf(%rip), %rdi     # 0x1cfe8
leaq 0x7816(%rip), %rsi      # 0x13a56
jmp 0xc1c7
movq 0x10d9f(%rip), %rdi     # 0x1cfe8
leaq 0x7806(%rip), %rsi      # 0x13a56
callq 0x31e0
movslq (%rbx), %rsi
leaq 0x110b9(%rip), %rcx     # 0x1d318
shlq $0x5, %rsi
addq (%rcx), %rsi
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x3130
pushq $-0x1
popq %rdi
callq 0x3260
jmp 0xc280
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0xa21e
movq %rbx, %rdi
callq 0x3390