// File: /workspace/github_cpp_makefile_star2_O2/CHEN-Zhihan[P]Compiler/Node.cpp
// Function: VarNode::declare(std::vector<int, std::allocator<int>>&, int) const
void VarNode::declare(vector<int> &sList, int functionID) const {
    if (functionTable.count(i) != 0) {
        cerr << "Redefinition of function: " << reverseLookup[i] << endl;
        exit(-1);
    }
    auto dimension = getDimension();
    int size = accumulate(dimension.begin(), dimension.end(), 1, multiplies<int>());
    if (size <= 0) {
        cerr << "Invalid length of array " << reverseLookup[i] << endl;
        exit(-1);
    }
    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) {
            cerr << "Redeclaration of variable " << reverseLookup[i] << endl;
            exit(-1);
        }
        auto address = findSpace(functionID, size);
        if (address == -1) {
            addressTable[GLOBAL].second[GLOBAL][i] = addressTable[GLOBAL].first;
            addressTable[GLOBAL].first += size;
        } else {
            addressTable[GLOBAL].second[GLOBAL][i] = address;
        }
        variableTable[GLOBAL].insert(i);
        sizeMap[{GLOBAL, i}] = dimension;
    } else {
        int s = getDefinitionScope(sList, functionID);
        if (s != NOT_FOUND) {
            cerr << "Redeclaration of variable " << reverseLookup[i] << endl;
            exit(-1);
        }
        variableTable[sList.back()].insert(i);
        #if DEBUG
            cerr << "add variable " << i << " to " << sList.back() << endl;
        #endif
        auto address = findSpace(functionID, size);
        if (address == -1) {
            addressTable[functionID].second[sList.back()][i] = addressTable[functionID].first;
            addressTable[functionID].first += size;
        } else {
            addressTable[functionID].second[sList.back()][i] = address;
        }
        sizeMap[{sList.back(), i}] = dimension;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %r13
movl %edx, -0x2c(%rbp)
leaq 0x8(%rdi), %rbx
leaq 0xef10(%rip), %rdi      # 0x1d350
movq %rbx, %rsi
callq 0x1055c
testq %rax, %rax
jne 0xe6de
leaq -0x50(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0xd64c
movq (%r14), %rax
movq 0x8(%r14), %rcx
pushq $0x1
popq %r14
cmpq %rcx, %rax
je 0xe47a
imull (%rax), %r14d
addq $0x4, %rax
jmp 0xe46b
testl %r14d, %r14d
jle 0xe71a
cmpb $0x1, 0xc(%r13)
jne 0xe512
cmpl %r12d, 0xf017(%rip)     # 0x1d4ac
je 0xe750
leaq 0xeee6(%rip), %rdi      # 0x1d388
leaq 0xf003(%rip), %rsi      # 0x1d4ac
callq 0xa758
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1021c
testq %rax, %rax
jne 0xe7d1
movl %r12d, %edi
movl %r14d, %esi
callq 0xb384
movl %eax, %r15d
cmpl $-0x1, %eax
je 0xe598
leaq 0xef88(%rip), %rdi      # 0x1d468
leaq 0xefc5(%rip), %rsi      # 0x1d4ac
callq 0x9d9e
addq $0x8, %rax
leaq 0xefb5(%rip), %rsi      # 0x1d4ac
movq %rax, %rdi
callq 0xf958
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10ea2
movl %r15d, (%rax)
jmp 0xe5f8
movq %r13, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0xbcac
cmpl $0x7d0, %eax            # imm = 0x7D0
jne 0xe798
movq 0x8(%r15), %rsi
addq $-0x4, %rsi
leaq 0xee4e(%rip), %rdi      # 0x1d388
callq 0xa758
movq %rax, %rdi
movq %rbx, %rsi
callq 0xab0e
movl %r12d, %edi
movl %r14d, %esi
callq 0xb384
movl %eax, %r12d
cmpl $-0x1, %eax
je 0xe644
leaq 0xef00(%rip), %rdi      # 0x1d468
leaq -0x2c(%rbp), %rsi
callq 0x9d9e
addq $0x8, %rax
movq 0x8(%r15), %rsi
addq $-0x4, %rsi
movq %rax, %rdi
callq 0xf958
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10ea2
movl %r12d, (%rax)
jmp 0xe69c
leaq 0xeec9(%rip), %rdi      # 0x1d468
leaq 0xef06(%rip), %rsi      # 0x1d4ac
callq 0x9d9e
movl (%rax), %r15d
leaq 0xeeb3(%rip), %rdi      # 0x1d468
leaq 0xeef0(%rip), %rsi      # 0x1d4ac
callq 0x9d9e
addq $0x8, %rax
leaq 0xeee0(%rip), %rsi      # 0x1d4ac
movq %rax, %rdi
callq 0xf958
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10ea2
movl %r15d, (%rax)
leaq 0xee7f(%rip), %rdi      # 0x1d468
leaq 0xeebc(%rip), %rsi      # 0x1d4ac
callq 0x9d9e
addl %r14d, (%rax)
leaq 0xed89(%rip), %rdi      # 0x1d388
leaq 0xeea6(%rip), %rsi      # 0x1d4ac
callq 0xa758
movq %rax, %rdi
movq %rbx, %rsi
callq 0xab0e
movl 0xee90(%rip), %eax      # 0x1d4ac
leaq -0x34(%rbp), %rsi
movl %eax, (%rsi)
movl (%rbx), %eax
movl %eax, 0x4(%rsi)
leaq 0xee82(%rip), %rdi      # 0x1d4b0
callq 0xeb8a
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0xef20
jmp 0xe6c6
leaq 0xee1d(%rip), %rdi      # 0x1d468
leaq -0x2c(%rbp), %rsi
callq 0x9d9e
movl (%rax), %r12d
leaq 0xee0a(%rip), %rdi      # 0x1d468
leaq -0x2c(%rbp), %rsi
callq 0x9d9e
addq $0x8, %rax
movq 0x8(%r15), %rsi
addq $-0x4, %rsi
movq %rax, %rdi
callq 0xf958
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10ea2
movl %r12d, (%rax)
leaq 0xedd8(%rip), %rdi      # 0x1d468
leaq -0x2c(%rbp), %rsi
callq 0x9d9e
addl %r14d, (%rax)
movq 0x8(%r15), %rax
movl -0x4(%rax), %eax
leaq -0x34(%rbp), %rsi
movl %eax, (%rsi)
movl (%rbx), %eax
movl %eax, 0x4(%rsi)
leaq 0xedfb(%rip), %rdi      # 0x1d4b0
callq 0xeb8a
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0xef20
leaq -0x50(%rbp), %rdi
callq 0xa21e
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xe903(%rip), %rdi      # 0x1cfe8
leaq 0x4b8a(%rip), %rsi      # 0x13276
callq 0x31e0
movslq (%rbx), %rsi
leaq 0xec1d(%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
movq 0xe8c7(%rip), %rdi      # 0x1cfe8
leaq 0x52e0(%rip), %rsi      # 0x13a08
callq 0x31e0
movslq (%rbx), %rsi
leaq 0xebe1(%rip), %rcx      # 0x1d318
shlq $0x5, %rsi
addq (%rcx), %rsi
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x3130
jmp 0xe712
movq 0xe891(%rip), %rdi      # 0x1cfe8
leaq 0x52c3(%rip), %rsi      # 0x13a21
callq 0x31e0
movslq (%rbx), %rsi
leaq 0xebab(%rip), %rcx      # 0x1d318
shlq $0x5, %rsi
addq (%rcx), %rsi
movq %rax, %rdi
callq 0x31c0
leaq 0x512b(%rip), %rsi      # 0x138ae
movq %rax, %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3130
jmp 0xe712
movq 0xe849(%rip), %rdi      # 0x1cfe8
leaq 0x5295(%rip), %rsi      # 0x13a3b
callq 0x31e0
movslq (%rbx), %rsi
leaq 0xeb63(%rip), %rcx      # 0x1d318
shlq $0x5, %rsi
addq (%rcx), %rsi
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x3130
jmp 0xe712
movq 0xe810(%rip), %rdi      # 0x1cfe8
leaq 0x525c(%rip), %rsi      # 0x13a3b
callq 0x31e0
movslq (%rbx), %rsi
leaq 0xeb2a(%rip), %rcx      # 0x1d318
shlq $0x5, %rsi
addq (%rcx), %rsi
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x3130
jmp 0xe712
jmp 0xe814
jmp 0xe814
jmp 0xe814
jmp 0xe814
jmp 0xe814
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0xa21e
movq %rbx, %rdi
callq 0x3390