// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsi, %r14
movq %rdi, %r15
movl %edx, -0x2c(%rbp)
leaq 0x8(%rdi), %rbx
leaq 0xeccb(%rip), %rdi      # 0x1c368
movq %rbx, %rsi
callq 0x1229c
testq %rax, %rax
jne 0xd94c
movq 0x10(%r15), %r12
movq 0x18(%r15), %r13
cmpq %r13, %r12
je 0xd6da
movq (%r12), %rdi
movl -0x2c(%rbp), %edx
movq (%rdi), %rax
movq %r14, %rsi
callq *0x8(%rax)
movq (%r12), %rdi
callq 0xd9d8
addq $0x10, %r12
jmp 0xd6b6
movl -0x2c(%rbp), %edx
cmpb $0x0, 0xc(%r15)
je 0xd80a
cmpl 0xedd6(%rip), %edx      # 0x1c4c4
je 0xd99a
leaq 0xeca5(%rip), %rdi      # 0x1c3a0
leaq 0xedc2(%rip), %rsi      # 0x1c4c4
callq 0xbe56
movq %rax, %rdi
movq %rbx, %rsi
callq 0x12038
testq %rax, %rax
je 0xd756
movl 0xeda7(%rip), %eax      # 0x1c4c4
leaq -0x38(%rbp), %rsi
movl %eax, (%rsi)
movl 0x8(%r15), %eax
movl %eax, 0x4(%rsi)
leaq 0xed97(%rip), %rdi      # 0x1c4c8
callq 0x10bf4
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
movq 0x18(%r15), %rax
subq 0x10(%r15), %rax
sarq $0x4, %rax
cmpq %rax, %rcx
jne 0xd95c
leaq 0xec43(%rip), %rdi      # 0x1c3a0
leaq 0xed60(%rip), %rsi      # 0x1c4c4
callq 0xbe56
movq %rax, %rdi
movq %rbx, %rsi
callq 0x12038
testq %rax, %rax
jne 0xd93d
movq 0x18(%r15), %rax
cmpq 0x10(%r15), %rax
jne 0xd95c
leaq 0xec0e(%rip), %rdi      # 0x1c3a0
leaq 0xed2b(%rip), %r15      # 0x1c4c4
movq %r15, %rsi
callq 0xbe56
leaq -0x38(%rbp), %r14
movq %rax, (%r14)
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xc186
leaq 0xecc3(%rip), %r12      # 0x1c480
movq %r12, %rdi
movq %r15, %rsi
callq 0xb5dc
movl (%rax), %r13d
leal 0x1(%r13), %ecx
movl %ecx, (%rax)
movq %r12, %rdi
movq %r15, %rsi
callq 0xb5dc
leaq 0x8(%rax), %rdi
movq %r15, %rsi
callq 0x11870
movq %rax, %rdi
movq %rbx, %rsi
callq 0x12922
movl %r13d, (%rax)
movl 0xecc8(%rip), %eax      # 0x1c4c4
movl %eax, (%r14)
movl (%rbx), %eax
movl %eax, 0x4(%r14)
jmp 0xd912
movq %r15, %rdi
movq %r14, %rsi
callq 0xd3b6
movl %eax, %r12d
cmpl $0x7d0, %eax            # imm = 0x7D0
je 0xd859
leaq -0x38(%rbp), %rsi
movl %r12d, (%rsi)
movl 0x8(%r15), %eax
movl %eax, 0x4(%rsi)
leaq 0xec94(%rip), %rdi      # 0x1c4c8
callq 0x10bf4
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
movq 0x18(%r15), %rax
subq 0x10(%r15), %rax
sarq $0x4, %rax
cmpq %rax, %rcx
jne 0xd95c
cmpl $0x7d0, %r12d           # imm = 0x7D0
jne 0xd93d
movq 0x18(%r15), %rax
cmpq 0x10(%r15), %rax
jne 0xd95c
leaq -0x2c(%rbp), %r12
movl (%r12), %edi
movl $0x1, %esi
callq 0xc778
movl %eax, %r15d
leaq 0xebf0(%rip), %rdi      # 0x1c480
movq %r12, %rsi
callq 0xb5dc
cmpl $-0x1, %r15d
jne 0xd8b7
movl (%rax), %r15d
leal 0x1(%r15), %ecx
movl %ecx, (%rax)
leaq 0xebd2(%rip), %rdi      # 0x1c480
leaq -0x2c(%rbp), %rsi
callq 0xb5dc
addq $0x8, %rax
movq 0x8(%r14), %rsi
addq $-0x4, %rsi
movq %rax, %rdi
callq 0x11870
movq %rax, %rdi
movq %rbx, %rsi
callq 0x12922
movl %r15d, (%rax)
movq 0x8(%r14), %rsi
addq $-0x4, %rsi
leaq 0xeab8(%rip), %rdi      # 0x1c3a0
callq 0xbe56
leaq -0x38(%rbp), %r15
movq %rax, (%r15)
movq %rax, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0xc186
movq 0x8(%r14), %rax
movl -0x4(%rax), %eax
movl %eax, (%r15)
movl (%rbx), %eax
movl %eax, 0x4(%r15)
leaq 0xebaf(%rip), %rdi      # 0x1c4c8
leaq -0x38(%rbp), %rsi
callq 0x10bf4
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0xd93d
callq 0x41e0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xe69d(%rip), %rdi      # 0x1bff0
leaq 0x693c(%rip), %rsi      # 0x14296
jmp 0xd96a
movq 0xe68d(%rip), %rdi      # 0x1bff0
leaq 0x710c(%rip), %rsi      # 0x14a76
callq 0x4200
movslq (%rbx), %rsi
leaq 0xe9b7(%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
movq 0xe64f(%rip), %rdi      # 0x1bff0
leaq 0x7099(%rip), %rsi      # 0x14a41
callq 0x4200
movslq (%rbx), %rsi
leaq 0xe979(%rip), %rcx      # 0x1c330
shlq $0x5, %rsi
addq (%rcx), %rsi
movq %rax, %rdi
callq 0x41d0
leaq 0x6f01(%rip), %rsi      # 0x148ce
movq %rax, %rdi
callq 0x4200
jmp 0xd988
nop