// File: /workspace/github_cpp_makefile_star2_O1/CHEN-Zhihan[P]Compiler/Node.cpp
// Function: VarNode::getOffSet(std::vector<int, std::allocator<int>>&, int, int, int) const
void VarNode::getOffSet(vector<int>& sList, int functionID, int blbl, int clbl) const {
    auto dimension = sizeMap[{global?GLOBAL:functionID, i}];
    auto size = vector<int>();
    int acc = 1;
    for (auto j = dimension.size() -1 ; j != 0; --j) {
        acc *= dimension[j];
        size.push_back(acc);
    }
    reverse(size.begin(), size.end());
    vector<int> values;
    bool known = true;
    for (int j = 0; j != subscriptions.size();++j) {
        if (subscriptions[j]->isKnown()) {
            auto value = subscriptions[j]->getValue();
            if (value < 0) {
                cerr << "invalid index of array " << i << endl;
                exit(-1);
            }
            values.push_back(value);
        } else {
            values.push_back(-1);
            known = false;
        }
    }
    vector<int> offsets;
    if (known) {
        for (int i = 0; i != values.size() - 1; ++i) {
            offsets.push_back(size[i] * values[i]);
        }
        offsets.push_back(values.back());
        int sum = accumulate(offsets.begin(), offsets.end(), 0);
        printf("\tpush\t%d\n", sum);
    } else {
        for (int i = 0; i != values.size() - 1; ++i) {
            if (values[i] != -1) {
                printf("\tpush\t%d\n", size[i] * values[i]);
            } else {
                subscriptions[i]->ex(sList, functionID, blbl, clbl);
                printf("\tpush\t%d\n", size[i]);
                printf("\tmul\n");
            }
        }
        if (not subscriptions.back()->isKnown()) {
            subscriptions.back()->ex(sList, functionID, blbl, clbl);
        } else {
            printf("\tpush\t%d\n", subscriptions.back()->getValue());
        }
        for (int i = 0; i != subscriptions.size() - 1; ++i) {
            printf("\tadd\n");
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r8d, -0x5c(%rbp)
movl %ecx, -0x58(%rbp)
movq %rsi, -0xb0(%rbp)
movq %rdi, %rbx
cmpb $0x0, 0xc(%rdi)
movl %edx, -0x54(%rbp)
movl %edx, %eax
je 0xfdaa
movl 0xc71a(%rip), %eax      # 0x1c4c4
leaq -0xa0(%rbp), %r14
movl %eax, (%r14)
movl 0x8(%rbx), %eax
movl %eax, 0x4(%r14)
leaq 0xc706(%rip), %rdi      # 0x1c4c8
movq %r14, %rsi
callq 0x10bf4
leaq -0xc8(%rbp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x10c84
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
movl $0x1, -0x2c(%rbp)
movq 0x8(%r15), %r12
subq (%r15), %r12
sarq $0x2, %r12
decq %r12
je 0xfe47
leaq -0x2c(%rbp), %r15
movq -0xc8(%rbp), %rcx
movl -0x2c(%rbp), %eax
imull (%rcx,%r12,4), %eax
movl %eax, -0x2c(%rbp)
movq -0x98(%rbp), %rsi
cmpq -0x90(%rbp), %rsi
je 0xfe37
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x98(%rbp)
jmp 0xfe42
movq %r14, %rdi
movq %r15, %rdx
callq 0x12182
decq %r12
jne 0xfe06
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rcx
cmpq %rcx, %rax
setne %dl
addq $-0x4, %rcx
cmpq %rax, %rcx
seta %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xfe8d
addq $0x4, %rax
movl -0x4(%rax), %edx
movl (%rcx), %esi
movl %esi, -0x4(%rax)
movl %edx, (%rcx)
addq $-0x4, %rcx
leaq 0x4(%rax), %rdx
cmpq %rcx, %rax
movq %rdx, %rax
jb 0xfe73
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq 0x10(%rbx), %rax
cmpq %rax, 0x18(%rbx)
je 0xff44
movb $0x1, %r14b
xorl %r13d, %r13d
leaq -0x80(%rbp), %r15
xorl %r12d, %r12d
movq (%rax,%r13), %rax
cmpb $0x1, 0x14(%rax)
jne 0xfee5
movl 0x10(%rax), %eax
movl %eax, -0x80(%rbp)
testl %eax, %eax
js 0x10184
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0xff17
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x48(%rbp)
jmp 0xff23
movl $0xffffffff, -0x80(%rbp) # imm = 0xFFFFFFFF
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0xff06
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, -0x48(%rbp)
jmp 0xff12
leaq -0x50(%rbp), %rdi
movq %r15, %rdx
callq 0x12adc
xorl %r14d, %r14d
jmp 0xff23
leaq -0x50(%rbp), %rdi
movq %r15, %rdx
callq 0x12182
incq %r12
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
addq $0x10, %r13
cmpq %rcx, %r12
jne 0xfeb7
jmp 0xff47
movb $0x1, %r14b
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
movq %rdx, %rcx
subq %rax, %rcx
testb $0x1, %r14b
je 0xfffb
cmpq $0x4, %rcx
je 0xffd8
movl $0x1, %r15d
leaq -0x80(%rbp), %rbx
leaq -0xa4(%rbp), %r14
movq -0xa0(%rbp), %rcx
movl -0x4(%rax,%r15,4), %eax
imull -0x4(%rcx,%r15,4), %eax
movl %eax, -0xa4(%rbp)
movq -0x78(%rbp), %rsi
cmpq -0x70(%rbp), %rsi
je 0xffb3
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x78(%rbp)
jmp 0xffbe
movq %rbx, %rdi
movq %r14, %rdx
callq 0x12adc
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
movq %rdx, %rcx
subq %rax, %rcx
sarq $0x2, %rcx
incq %r15
cmpq %rcx, %r15
jne 0xff85
addq $-0x4, %rdx
movq -0x78(%rbp), %rsi
cmpq -0x70(%rbp), %rsi
je 0x10106
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x78(%rbp)
jmp 0x1010f
cmpq $0x4, %rcx
je 0x10096
movl $0x1, %r12d
leaq 0x4610(%rip), %r14      # 0x14622
leaq 0x4b1b(%rip), %r15      # 0x14b34
xorl %r13d, %r13d
movl -0x4(%rax,%r12,4), %esi
cmpl $-0x1, %esi
je 0x1003f
movq -0xa0(%rbp), %rax
imull -0x4(%rax,%r12,4), %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x4050
jmp 0x1007b
movq 0x10(%rbx), %rax
movq (%rax,%r13), %rdi
movq (%rdi), %rax
movq -0xb0(%rbp), %rsi
movl -0x54(%rbp), %edx
movl -0x58(%rbp), %ecx
movl -0x5c(%rbp), %r8d
callq *(%rax)
movq -0xa0(%rbp), %rax
movl -0x4(%rax,%r12,4), %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x4050
movq %r15, %rdi
callq 0x4330
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
incq %r12
addq $0x10, %r13
cmpq %rcx, %r12
jne 0x1001c
movq 0x18(%rbx), %rax
movq -0x10(%rax), %rdi
cmpb $0x0, 0x14(%rdi)
je 0x100b7
movl 0x10(%rdi), %esi
leaq 0x4574(%rip), %rdi      # 0x14622
xorl %eax, %eax
callq 0x4050
jmp 0x100cd
movq (%rdi), %rax
movq -0xb0(%rbp), %rsi
movl -0x54(%rbp), %edx
movl -0x58(%rbp), %ecx
movl -0x5c(%rbp), %r8d
callq *(%rax)
movq 0x18(%rbx), %rax
subq 0x10(%rbx), %rax
cmpq $0x10, %rax
je 0x10134
movl $0x1, %r15d
leaq 0x4590(%rip), %r14      # 0x14678
movq %r14, %rdi
callq 0x4330
movq 0x18(%rbx), %rax
subq 0x10(%rbx), %rax
sarq $0x4, %rax
incq %r15
cmpq %rax, %r15
jne 0x100e8
jmp 0x10134
leaq -0x80(%rbp), %rdi
callq 0x12182
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rcx
xorl %esi, %esi
cmpq %rcx, %rax
je 0x10126
addl (%rax), %esi
addq $0x4, %rax
jmp 0x10119
leaq 0x44f5(%rip), %rdi      # 0x14622
xorl %eax, %eax
callq 0x4050
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x10142
callq 0x41e0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x10150
callq 0x41e0
movq -0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0x10161
callq 0x41e0
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0x10172
callq 0x41e0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xbe65(%rip), %rdi      # 0x1bff0
leaq 0x487e(%rip), %rsi      # 0x14a10
movl $0x17, %edx
callq 0x4260
movl 0x8(%rbx), %esi
movq 0xbe4a(%rip), %rdi      # 0x1bff0
callq 0x4390
movq %rax, %rdi
callq 0x4120
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42a0
jmp 0x101c1
jmp 0x101c1
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x101e0
callq 0x41e0
jmp 0x101e0
jmp 0x101dd
jmp 0x101dd
movq %rax, %rbx
jmp 0x101ee
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x101ee
callq 0x41e0
movq -0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0x101ff
callq 0x41e0
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0x10210
callq 0x41e0
movq %rbx, %rdi
callq 0x43b0