// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movl %r8d, -0x34(%rbp)
movl %ecx, -0x30(%rbp)
movq %rsi, -0x88(%rbp)
movq %rdi, %rbx
cmpb $0x0, 0xc(%rdi)
movl %edx, -0x2c(%rbp)
movl %edx, %eax
je 0xdf56
movl 0xf556(%rip), %eax      # 0x1d4ac
leaq -0xa0(%rbp), %r14
movl %eax, (%r14)
movl 0x8(%rbx), %eax
movl %eax, 0x4(%r14)
leaq 0xf542(%rip), %rdi      # 0x1d4b0
movq %r14, %rsi
callq 0xeb8a
leaq -0xb8(%rbp), %r13
movq %r13, %rdi
movq %rax, %rsi
callq 0xebf4
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
leaq -0x38(%rbp), %r15
movq 0x8(%r13), %rax
subq (%r13), %rax
movl $0x1, (%r15)
sarq $0x2, %rax
decq %rax
movq %rax, %r12
subq $0x1, %r12
jb 0xdfd8
movq -0xb8(%rbp), %rcx
movl -0x38(%rbp), %edx
imull (%rcx,%rax,4), %edx
movl %edx, -0x38(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xee54
movq %r12, %rax
jmp 0xdfb1
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x110a9
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movb $0x1, %r14b
xorl %r12d, %r12d
leaq -0x60(%rbp), %r15
xorl %r13d, %r13d
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
cmpq %rcx, %r13
je 0xe05d
movq (%rax,%r12), %rax
cmpb $0x1, 0x14(%rax)
jne 0xe041
movl 0x10(%rax), %eax
movl %eax, -0x60(%rbp)
testl %eax, %eax
js 0xe222
leaq -0x80(%rbp), %rdi
movq %r15, %rsi
callq 0xee54
jmp 0xe054
orl $-0x1, -0x60(%rbp)
leaq -0x80(%rbp), %rdi
movq %r15, %rsi
callq 0x110cc
xorl %r14d, %r14d
incq %r13
addq $0x10, %r12
jmp 0xe007
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
andq $0x0, -0x50(%rbp)
testb $0x1, %r14b
je 0xe0bb
xorl %r15d, %r15d
leaq -0x60(%rbp), %rbx
leaq -0x3c(%rbp), %r14
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rsi
movq %rsi, %rcx
subq %rax, %rcx
sarq $0x2, %rcx
decq %rcx
cmpq %rcx, %r15
je 0xe173
movq -0xa0(%rbp), %rcx
movl (%rax,%r15,4), %eax
imull (%rcx,%r15,4), %eax
movl %eax, -0x3c(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x110cc
incq %r15
jmp 0xe07a
leaq 0x5540(%rip), %r14      # 0x13602
leaq 0x5a4b(%rip), %r15      # 0x13b14
xorl %r13d, %r13d
xorl %r12d, %r12d
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
decq %rcx
cmpq %rcx, %r12
je 0xe14b
movl (%rax,%r12,4), %esi
cmpl $-0x1, %esi
je 0xe107
movq -0xa0(%rbp), %rax
imull (%rax,%r12,4), %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x3040
jmp 0xe142
movq 0x10(%rbx), %rax
movq (%rax,%r13), %rdi
movq (%rdi), %rax
movq -0x88(%rbp), %rsi
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %ecx
movl -0x34(%rbp), %r8d
callq *(%rax)
movq -0xa0(%rbp), %rax
movl (%rax,%r12,4), %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x3040
movq %r15, %rdi
callq 0x3310
incq %r12
addq $0x10, %r13
jmp 0xe0cf
movq 0x18(%rbx), %rax
movq -0x10(%rax), %rdi
cmpb $0x0, 0x14(%rdi)
je 0xe1e1
movl 0x10(%rdi), %esi
leaq 0x549b(%rip), %rdi      # 0x13602
xorl %eax, %eax
callq 0x3040
jmp 0xe1f7
addq $-0x4, %rsi
leaq -0x60(%rbp), %rdi
callq 0xee54
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %rcx
xorl %esi, %esi
cmpq %rcx, %rax
je 0xe197
addl (%rax), %esi
addq $0x4, %rax
jmp 0xe18a
leaq 0x5464(%rip), %rdi      # 0x13602
xorl %eax, %eax
callq 0x3040
leaq -0x60(%rbp), %rdi
callq 0xa21e
leaq -0x80(%rbp), %rdi
callq 0xa21e
leaq -0xa0(%rbp), %rdi
callq 0xa21e
leaq -0xb8(%rbp), %rdi
callq 0xa21e
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rdi), %rax
movq -0x88(%rbp), %rsi
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %ecx
movl -0x34(%rbp), %r8d
callq *(%rax)
xorl %r15d, %r15d
leaq 0x5457(%rip), %r14      # 0x13658
movq 0x18(%rbx), %rax
subq 0x10(%rbx), %rax
sarq $0x4, %rax
decq %rax
cmpq %rax, %r15
je 0xe1a5
movq %r14, %rdi
callq 0x3310
incq %r15
jmp 0xe201
movq 0xedbf(%rip), %rdi      # 0x1cfe8
leaq 0x57c0(%rip), %rsi      # 0x139f0
callq 0x31e0
movl 0x8(%rbx), %esi
movq %rax, %rdi
callq 0x3370
movq %rax, %rdi
callq 0x3130
pushq $-0x1
popq %rdi
callq 0x3260
jmp 0xe258
jmp 0xe276
jmp 0xe258
jmp 0xe268
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0xa21e
jmp 0xe26b
jmp 0xe268
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0xa21e
jmp 0xe279
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0xa21e
leaq -0xb8(%rbp), %rdi
callq 0xa21e
movq %rbx, %rdi
callq 0x3390
nop