// File: /workspace/github_cpp_makefile_star2_O2/Merulo[P]CompilerJFTT/src/Register/RegisterBlock.cpp
// Function: RegisterBlock::saveConstTableToMemory(Block&, Register&, Register&, unsigned long long)
void RegisterBlock::saveConstTableToMemory(Block& b, Register& r, Register& freeRegister, unsigned long long diff)
{
    std::string array = r.variableName.substr(0, r.variableName.find("("));
    unsigned long memoryCell = _symbolTable->getMemoryCell(array);
    unsigned long long shift = _symbolTable->getTableShift(array);
    memoryCell = memoryCell + diff - shift;

    if (_addressRegister.state == RegisterState::UNKNOWN)
    {
        b.lines.push_back({"SUB", "A", "A"});
        _addressRegister.state = RegisterState::CONST;
        _addressRegister.constValue = 0;
    }
    auto lines = generateNumberFrom(_addressRegister.constValue, memoryCell, freeRegister);

    lines.push_back({"STORE", r.name});
    b.insert(lines);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %r8, %r12
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x30(%rdx), %r13
leaq 0x1d6f7(%rip), %rsi     # 0x245bd
movq %r13, %rdi
xorl %edx, %edx
callq 0x4520
leaq 0x120(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x42a0
movq (%r15), %r13
leaq 0x100(%rsp), %rdi
movq %rbp, %rsi
callq 0x4390
leaq 0x100(%rsp), %rsi
movq %r13, %rdi
callq 0x100f2
movq %rax, %r13
leaq 0x100(%rsp), %rdi
callq 0x4548
movq (%r15), %rbp
leaq 0xe0(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x4390
leaq 0xe0(%rsp), %rsi
movq %rbp, %rdi
callq 0x109a6
movq %rax, %rbp
leaq 0xe0(%rsp), %rdi
callq 0x4548
cmpl $0x0, 0x10(%r15)
jne 0x7020
leaq 0x1c131(%rip), %rsi     # 0x23096
leaq 0xc0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x4a54
leaq 0x1c116(%rip), %rsi     # 0x23094
leaq 0xa0(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x4a54
leaq 0x1c0fd(%rip), %rsi     # 0x23094
leaq 0x80(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x4a54
leaq 0x140(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
leaq 0x80(%rsp), %rcx
callq 0x816a
leaq 0x20(%rbx), %rdi
leaq 0x140(%rsp), %rsi
callq 0x8f90
leaq 0x140(%rsp), %rdi
callq 0x81fe
leaq 0x80(%rsp), %rdi
callq 0x4548
leaq 0xa0(%rsp), %rdi
callq 0x4548
leaq 0xc0(%rsp), %rdi
callq 0x4548
movl $0x2, 0x10(%r15)
andq $0x0, 0x18(%r15)
addq %r12, %r13
subq %rbp, %r13
addq $0x18, %r15
leaq 0x8(%rsp), %rdi
movq %r15, %rdx
movq %r13, %rcx
callq 0x5530
leaq 0x1c079(%rip), %rsi     # 0x230ba
leaq 0x60(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x4a54
addq $0x10, %r14
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x4390
leaq 0x1c07b(%rip), %rsi     # 0x230e3
leaq 0x20(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x4a54
leaq 0x140(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x40(%rsp), %rdx
leaq 0x20(%rsp), %rcx
callq 0x816a
leaq 0x8(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x8f90
leaq 0x140(%rsp), %rdi
callq 0x81fe
leaq 0x20(%rsp), %rdi
callq 0x4548
leaq 0x40(%rsp), %rdi
callq 0x4548
leaq 0x60(%rsp), %rdi
callq 0x4548
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x821e
leaq 0x8(%rsp), %rdi
callq 0x8236
leaq 0x120(%rsp), %rdi
callq 0x4548
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x81fe
jmp 0x711b
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x4548
jmp 0x712d
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x4548
jmp 0x713f
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
jmp 0x71b7
jmp 0x71be
jmp 0x718c
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x81fe
jmp 0x7162
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x4548
jmp 0x7171
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x4548
jmp 0x7180
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x4548
jmp 0x718f
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8236
jmp 0x71c1
jmp 0x71be
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
jmp 0x71b7
jmp 0x71be
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x4548
jmp 0x71c1
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x4548
movq %rbx, %rdi
callq 0x4490