// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x30, %rsp
movq %rsi, %r15
movq %rdi, %r12
movl %edx, -0x24(%rbp)
leaq 0x8(%rdi), %rbx
leaq 0xbfab(%rip), %rdi      # 0x1c368
movq %rbx, %rsi
callq 0x1229c
testq %rax, %rax
jne 0x1066e
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0xf2ec
movq (%r14), %rax
movq 0x8(%r14), %rcx
movl $0x1, %r14d
cmpq %rcx, %rax
je 0x103f9
imull (%rax), %r14d
addq $0x4, %rax
jmp 0x103ea
testl %r14d, %r14d
jle 0x106ac
movl -0x24(%rbp), %edx
cmpb $0x1, 0xc(%r12)
jne 0x10494
cmpl 0xc0ad(%rip), %edx      # 0x1c4c4
je 0x106f4
leaq 0xbf7c(%rip), %rdi      # 0x1c3a0
leaq 0xc099(%rip), %rsi      # 0x1c4c4
callq 0xbe56
movq %rax, %rdi
movq %rbx, %rsi
callq 0x12038
testq %rax, %rax
jne 0x107a1
movl -0x24(%rbp), %edi
movl %r14d, %esi
callq 0xc778
movl %eax, %r15d
cmpl $-0x1, %eax
je 0x1051e
leaq 0xc01e(%rip), %rdi      # 0x1c480
leaq 0xc05b(%rip), %rsi      # 0x1c4c4
callq 0xb5dc
addq $0x8, %rax
leaq 0xc04b(%rip), %rsi      # 0x1c4c4
movq %rax, %rdi
callq 0x11870
movq %rax, %rdi
movq %rbx, %rsi
callq 0x12922
movl %r15d, (%rax)
jmp 0x1057e
movq %r12, %rdi
movq %r15, %rsi
callq 0xd3b6
cmpl $0x7d0, %eax            # imm = 0x7D0
jne 0x10756
movq 0x8(%r15), %rsi
addq $-0x4, %rsi
leaq 0xbee7(%rip), %rdi      # 0x1c3a0
callq 0xbe56
leaq -0x30(%rbp), %rdx
movq %rax, (%rdx)
movq %rax, %rdi
movq %rbx, %rsi
callq 0xc186
movl -0x24(%rbp), %edi
movl %r14d, %esi
callq 0xc778
movl %eax, %r12d
cmpl $-0x1, %eax
je 0x105d1
leaq 0xbf92(%rip), %rdi      # 0x1c480
leaq -0x24(%rbp), %rsi
callq 0xb5dc
addq $0x8, %rax
movq 0x8(%r15), %rsi
addq $-0x4, %rsi
movq %rax, %rdi
callq 0x11870
movq %rax, %rdi
movq %rbx, %rsi
callq 0x12922
movl %r12d, (%rax)
jmp 0x10629
leaq 0xbf5b(%rip), %rdi      # 0x1c480
leaq 0xbf98(%rip), %rsi      # 0x1c4c4
callq 0xb5dc
movl (%rax), %r15d
leaq 0xbf45(%rip), %rdi      # 0x1c480
leaq 0xbf82(%rip), %rsi      # 0x1c4c4
callq 0xb5dc
addq $0x8, %rax
leaq 0xbf72(%rip), %rsi      # 0x1c4c4
movq %rax, %rdi
callq 0x11870
movq %rax, %rdi
movq %rbx, %rsi
callq 0x12922
movl %r15d, (%rax)
leaq 0xbf11(%rip), %rdi      # 0x1c480
leaq 0xbf4e(%rip), %rsi      # 0x1c4c4
callq 0xb5dc
addl %r14d, (%rax)
leaq 0xbe1b(%rip), %rdi      # 0x1c3a0
leaq 0xbf38(%rip), %rsi      # 0x1c4c4
callq 0xbe56
leaq -0x30(%rbp), %rdx
movq %rax, (%rdx)
movq %rax, %rdi
movq %rbx, %rsi
callq 0xc186
movl 0xbf1b(%rip), %eax      # 0x1c4c4
leaq -0x30(%rbp), %rsi
movl %eax, (%rsi)
movl (%rbx), %eax
movl %eax, 0x4(%rsi)
leaq 0xbf0d(%rip), %rdi      # 0x1c4c8
callq 0x10bf4
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x10ee8
jmp 0x10653
leaq 0xbea8(%rip), %rdi      # 0x1c480
leaq -0x24(%rbp), %rsi
callq 0xb5dc
movl (%rax), %r12d
leaq 0xbe95(%rip), %rdi      # 0x1c480
leaq -0x24(%rbp), %rsi
callq 0xb5dc
addq $0x8, %rax
movq 0x8(%r15), %rsi
addq $-0x4, %rsi
movq %rax, %rdi
callq 0x11870
movq %rax, %rdi
movq %rbx, %rsi
callq 0x12922
movl %r12d, (%rax)
leaq 0xbe63(%rip), %rdi      # 0x1c480
leaq -0x24(%rbp), %rsi
callq 0xb5dc
addl %r14d, (%rax)
movq 0x8(%r15), %rax
movl -0x4(%rax), %eax
leaq -0x30(%rbp), %rsi
movl %eax, (%rsi)
movl (%rbx), %eax
movl %eax, 0x4(%rsi)
leaq 0xbe86(%rip), %rdi      # 0x1c4c8
callq 0x10bf4
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x10ee8
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x10661
callq 0x41e0
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0xb97b(%rip), %rdi      # 0x1bff0
leaq 0x3c1a(%rip), %rsi      # 0x14296
callq 0x4200
movslq (%rbx), %rsi
leaq 0xbca5(%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 0xb93d(%rip), %rdi      # 0x1bff0
leaq 0x436e(%rip), %rsi      # 0x14a28
movl $0x18, %edx
callq 0x4260
movslq (%rbx), %rax
leaq 0xbc62(%rip), %rcx      # 0x1c330
movq (%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq 0xb90b(%rip), %rdi      # 0x1bff0
callq 0x4260
movq %rax, %rdi
callq 0x4120
jmp 0x106a2
movq 0xb8f5(%rip), %rdi      # 0x1bff0
leaq 0x433f(%rip), %rsi      # 0x14a41
movl $0x19, %edx
callq 0x4260
movslq (%rbx), %rax
leaq 0xbc1a(%rip), %rcx      # 0x1c330
movq (%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq 0xb8c3(%rip), %rdi      # 0x1bff0
callq 0x4260
movq %rax, %rbx
leaq 0x4192(%rip), %rsi      # 0x148ce
movl $0x14, %edx
movq %rax, %rdi
callq 0x4260
movq %rbx, %rdi
callq 0x4120
jmp 0x106a2
movq 0xb893(%rip), %rdi      # 0x1bff0
leaq 0x42f7(%rip), %rsi      # 0x14a5b
movl $0x1a, %edx
callq 0x4260
movslq (%rbx), %rax
leaq 0xbbb8(%rip), %rcx      # 0x1c330
movq (%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq 0xb861(%rip), %rdi      # 0x1bff0
callq 0x4260
movq %rax, %rdi
callq 0x4120
jmp 0x106a2
movq 0xb848(%rip), %rdi      # 0x1bff0
leaq 0x42ac(%rip), %rsi      # 0x14a5b
movl $0x1a, %edx
callq 0x4260
movslq (%rbx), %rax
leaq 0xbb6d(%rip), %rcx      # 0x1c330
movq (%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq 0xb816(%rip), %rdi      # 0x1bff0
callq 0x4260
movq %rax, %rdi
callq 0x4120
jmp 0x106a2
jmp 0x107f6
jmp 0x107f6
jmp 0x107f6
jmp 0x107f6
jmp 0x107f6
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x10807
callq 0x41e0
movq %rbx, %rdi
callq 0x43b0
nop