// File: /workspace/github_cpp_makefile_star2_O3/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 0xc4a0(%rip), %rdi      # 0x1c368
movq %rbx, %rsi
callq 0x11d24
testq %rax, %rax
jne 0x1017e
leaq -0x50(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0xedc8
movq (%r14), %rax
movq 0x8(%r14), %rcx
movl $0x1, %r14d
cmpq %rcx, %rax
je 0xff10
imull (%rax), %r14d
addq $0x4, %rax
cmpq %rcx, %rax
jne 0xfefa
testl %r14d, %r14d
jle 0x101bc
cmpb $0x1, 0xc(%r13)
jne 0xff9f
cmpl %r12d, 0xc5a2(%rip)     # 0x1c4c4
je 0x10204
leaq 0xc471(%rip), %rdi      # 0x1c3a0
leaq 0xc58e(%rip), %rsi      # 0x1c4c4
callq 0xb9ba
movq %rax, %rdi
movq %rbx, %rsi
callq 0x11a64
testq %rax, %rax
jne 0x102b1
movl %r12d, %edi
movl %r14d, %esi
callq 0xc22c
movl %eax, %r15d
cmpl $-0x1, %eax
je 0x1002c
leaq 0xc513(%rip), %rdi      # 0x1c480
leaq 0xc550(%rip), %rsi      # 0x1c4c4
callq 0xb1ce
addq $0x8, %rax
leaq 0xc540(%rip), %rsi      # 0x1c4c4
movq %rax, %rdi
callq 0x11302
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1237e
movl %r15d, (%rax)
jmp 0x1008c
movq %r13, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0xce4e
cmpl $0x7d0, %eax            # imm = 0x7D0
jne 0x10266
movq 0x8(%r15), %rsi
addq $-0x4, %rsi
leaq 0xc3d9(%rip), %rdi      # 0x1c3a0
callq 0xb9ba
leaq -0x38(%rbp), %rdx
movq %rax, (%rdx)
movq %rax, %rdi
movq %rbx, %rsi
callq 0xbcaa
movl %r12d, %edi
movl %r14d, %esi
callq 0xc22c
movl %eax, %r12d
cmpl $-0x1, %eax
je 0x100df
leaq 0xc484(%rip), %rdi      # 0x1c480
leaq -0x2c(%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 %r12d, (%rax)
jmp 0x10137
leaq 0xc44d(%rip), %rdi      # 0x1c480
leaq 0xc48a(%rip), %rsi      # 0x1c4c4
callq 0xb1ce
movl (%rax), %r15d
leaq 0xc437(%rip), %rdi      # 0x1c480
leaq 0xc474(%rip), %rsi      # 0x1c4c4
callq 0xb1ce
addq $0x8, %rax
leaq 0xc464(%rip), %rsi      # 0x1c4c4
movq %rax, %rdi
callq 0x11302
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1237e
movl %r15d, (%rax)
leaq 0xc403(%rip), %rdi      # 0x1c480
leaq 0xc440(%rip), %rsi      # 0x1c4c4
callq 0xb1ce
addl %r14d, (%rax)
leaq 0xc30d(%rip), %rdi      # 0x1c3a0
leaq 0xc42a(%rip), %rsi      # 0x1c4c4
callq 0xb9ba
leaq -0x38(%rbp), %rdx
movq %rax, (%rdx)
movq %rax, %rdi
movq %rbx, %rsi
callq 0xbcaa
movl 0xc40d(%rip), %eax      # 0x1c4c4
leaq -0x38(%rbp), %rsi
movl %eax, (%rsi)
movl (%rbx), %eax
movl %eax, 0x4(%rsi)
leaq 0xc3ff(%rip), %rdi      # 0x1c4c8
callq 0x10704
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0x109f6
jmp 0x10161
leaq 0xc39a(%rip), %rdi      # 0x1c480
leaq -0x2c(%rbp), %rsi
callq 0xb1ce
movl (%rax), %r12d
leaq 0xc387(%rip), %rdi      # 0x1c480
leaq -0x2c(%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 %r12d, (%rax)
leaq 0xc355(%rip), %rdi      # 0x1c480
leaq -0x2c(%rbp), %rsi
callq 0xb1ce
addl %r14d, (%rax)
movq 0x8(%r15), %rax
movl -0x4(%rax), %eax
leaq -0x38(%rbp), %rsi
movl %eax, (%rsi)
movl (%rbx), %eax
movl %eax, 0x4(%rsi)
leaq 0xc378(%rip), %rdi      # 0x1c4c8
callq 0x10704
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0x109f6
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x1016f
callq 0x41e0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xbe63(%rip), %rdi      # 0x1bfe8
leaq 0x410a(%rip), %rsi      # 0x14296
callq 0x4200
movslq (%rbx), %rsi
leaq 0xc195(%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 0xbe25(%rip), %rdi      # 0x1bfe8
leaq 0x485e(%rip), %rsi      # 0x14a28
movl $0x18, %edx
callq 0x4260
movslq (%rbx), %rax
leaq 0xc152(%rip), %rcx      # 0x1c330
movq (%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq 0xbdf3(%rip), %rdi      # 0x1bfe8
callq 0x4260
movq %rax, %rdi
callq 0x4120
jmp 0x101b2
movq 0xbddd(%rip), %rdi      # 0x1bfe8
leaq 0x482f(%rip), %rsi      # 0x14a41
movl $0x19, %edx
callq 0x4260
movslq (%rbx), %rax
leaq 0xc10a(%rip), %rcx      # 0x1c330
movq (%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq 0xbdab(%rip), %rdi      # 0x1bfe8
callq 0x4260
movq %rax, %rbx
leaq 0x4682(%rip), %rsi      # 0x148ce
movl $0x14, %edx
movq %rax, %rdi
callq 0x4260
movq %rbx, %rdi
callq 0x4120
jmp 0x101b2
movq 0xbd7b(%rip), %rdi      # 0x1bfe8
leaq 0x47e7(%rip), %rsi      # 0x14a5b
movl $0x1a, %edx
callq 0x4260
movslq (%rbx), %rax
leaq 0xc0a8(%rip), %rcx      # 0x1c330
movq (%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq 0xbd49(%rip), %rdi      # 0x1bfe8
callq 0x4260
movq %rax, %rdi
callq 0x4120
jmp 0x101b2
movq 0xbd30(%rip), %rdi      # 0x1bfe8
leaq 0x479c(%rip), %rsi      # 0x14a5b
movl $0x1a, %edx
callq 0x4260
movslq (%rbx), %rax
leaq 0xc05d(%rip), %rcx      # 0x1c330
movq (%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq 0xbcfe(%rip), %rdi      # 0x1bfe8
callq 0x4260
movq %rax, %rdi
callq 0x4120
jmp 0x101b2
jmp 0x10306
jmp 0x10306
jmp 0x10306
jmp 0x10306
jmp 0x10306
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x10317
callq 0x41e0
movq %rbx, %rdi
callq 0x43b0
nop