// File: /workspace/github_cpp_makefile_star2_O3/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, -0x7c(%rbp)
movl %ecx, -0x78(%rbp)
movq %rsi, -0xb0(%rbp)
movq %rdi, %rbx
cmpb $0x0, 0xc(%rdi)
movl %edx, -0x74(%rbp)
movl %edx, %eax
je 0xf884
movl 0xcc40(%rip), %eax      # 0x1c4c4
leaq -0xa0(%rbp), %r14
movl %eax, (%r14)
movl 0x8(%rbx), %eax
movl %eax, 0x4(%r14)
leaq 0xcc2c(%rip), %rdi      # 0x1c4c8
movq %r14, %rsi
callq 0x10704
leaq -0xc8(%rbp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x10790
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 0xf96b
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 0xf915
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x98(%rbp)
jmp 0xf920
movq %r14, %rdi
movq %r15, %rdx
callq 0x11c0a
decq %r12
jne 0xf8e4
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 0xf96b
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 0xf951
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq 0x10(%rbx), %rax
cmpq %rax, 0x18(%rbx)
je 0xfb0a
movb $0x1, %r14b
xorl %r13d, %r13d
leaq -0x70(%rbp), %r15
xorl %r12d, %r12d
movq (%rax,%r13), %rax
cmpb $0x1, 0x14(%rax)
jne 0xf9c3
movl 0x10(%rax), %eax
movl %eax, -0x70(%rbp)
testl %eax, %eax
js 0xfc87
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0xf9f5
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x48(%rbp)
jmp 0xfa01
movl $0xffffffff, -0x70(%rbp) # imm = 0xFFFFFFFF
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0xf9e4
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, -0x48(%rbp)
jmp 0xf9f0
leaq -0x50(%rbp), %rdi
movq %r15, %rdx
callq 0x12580
xorl %r14d, %r14d
jmp 0xfa01
leaq -0x50(%rbp), %rdi
movq %r15, %rdx
callq 0x11c0a
incq %r12
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x4, %rdx
addq $0x10, %r13
cmpq %rdx, %r12
jne 0xf995
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
testb $0x1, %r14b
jne 0xfb16
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
subq %rax, %rdx
cmpq $0x4, %rdx
je 0xfae6
movl $0x1, %r12d
leaq 0x4bc4(%rip), %r14      # 0x14622
leaq 0x50cf(%rip), %r15      # 0x14b34
xorl %r13d, %r13d
movl -0x4(%rax,%r12,4), %esi
cmpl $-0x1, %esi
je 0xfa8b
movq -0xa0(%rbp), %rax
imull -0x4(%rax,%r12,4), %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x4050
jmp 0xfac7
movq 0x10(%rbx), %rax
movq (%rax,%r13), %rdi
movq (%rdi), %rax
movq -0xb0(%rbp), %rsi
movl -0x74(%rbp), %edx
movl -0x78(%rbp), %ecx
movl -0x7c(%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 0xfa68
movq 0x18(%rbx), %rcx
movq -0x10(%rcx), %rdi
cmpb $0x0, 0x14(%rdi)
je 0xfc35
movl 0x10(%rdi), %esi
leaq 0x4b24(%rip), %rdi      # 0x14622
xorl %eax, %eax
callq 0x4050
jmp 0xfc4b
movaps %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
movq %rdx, %rcx
subq %rax, %rcx
cmpq $0x4, %rcx
jne 0xfb35
addq $-0x4, %rdx
xorl %esi, %esi
jmp 0xfbb5
movl $0x1, %r15d
leaq -0x70(%rbp), %rbx
leaq -0xa4(%rbp), %r14
movq -0xa0(%rbp), %rsi
movl -0x4(%rax,%r15,4), %ecx
imull -0x4(%rsi,%r15,4), %ecx
movl %ecx, -0xa4(%rbp)
movq -0x68(%rbp), %rsi
cmpq -0x60(%rbp), %rsi
je 0xfb74
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x68(%rbp)
jmp 0xfb87
movq %rbx, %rdi
movq %r14, %rdx
callq 0x12580
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
movq %rdx, %rcx
subq %rax, %rcx
sarq $0x2, %rcx
incq %r15
cmpq %rcx, %r15
jne 0xfb46
movq -0x68(%rbp), %rsi
addq $-0x4, %rdx
cmpq -0x60(%rbp), %rsi
je 0xfbb5
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x68(%rbp)
jmp 0xfbc2
leaq -0x70(%rbp), %rdi
callq 0x11c0a
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rcx
xorl %eax, %eax
cmpq %rsi, %rcx
je 0xfbd5
addl (%rcx), %eax
addq $0x4, %rcx
jmp 0xfbc8
leaq 0x4a46(%rip), %rdi      # 0x14622
movl %eax, %esi
xorl %eax, %eax
callq 0x4050
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0xfbf3
callq 0x41e0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0xfc01
callq 0x41e0
movq -0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0xfc12
callq 0x41e0
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0xfc23
callq 0x41e0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rdi), %rax
movq -0xb0(%rbp), %rsi
movl -0x74(%rbp), %edx
movl -0x78(%rbp), %ecx
movl -0x7c(%rbp), %r8d
callq *(%rax)
movq 0x18(%rbx), %rax
subq 0x10(%rbx), %rax
cmpq $0x10, %rax
je 0xfbe5
movl $0x1, %r15d
leaq 0x4a12(%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 0xfc66
jmp 0xfbe5
movq 0xc35a(%rip), %rdi      # 0x1bfe8
leaq 0x4d7b(%rip), %rsi      # 0x14a10
movl $0x17, %edx
callq 0x4260
movl 0x8(%rbx), %esi
movq 0xc33f(%rip), %rdi      # 0x1bfe8
callq 0x4390
movq %rax, %rdi
callq 0x4120
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42a0
jmp 0xfcc8
jmp 0xfcc8
jmp 0xfce0
jmp 0xfce0
movq %rax, %rbx
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0xfce3
callq 0x41e0
jmp 0xfce3
movq %rax, %rbx
jmp 0xfcf1
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0xfcf1
callq 0x41e0
movq -0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0xfd02
callq 0x41e0
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0xfd13
callq 0x41e0
movq %rbx, %rdi
callq 0x43b0
nop