// File: /workspace/github_cpp_makefile_star2_O2/Merulo[P]CompilerJFTT/src/Register/RegisterBlock.cpp
// Function: RegisterBlock::loadConstTableFromMemory(Block&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Register&, Register&, unsigned long long)
void RegisterBlock::loadConstTableFromMemory(Block& b, std::string name, Register& r, Register& freeRegister, unsigned long long diff)
{
    std::string array = name.substr(0, name.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({"LOAD", r.name});
    b.insert(lines);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %r9, %r12
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x1cc90(%rip), %rsi     # 0x245bd
movq %rdx, %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 0x7a87
leaq 0x1b6ca(%rip), %rsi     # 0x23096
leaq 0xc0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x4a54
leaq 0x1b6af(%rip), %rsi     # 0x23094
leaq 0xa0(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x4a54
leaq 0x1b696(%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 0x1b618(%rip), %rsi     # 0x230c0
leaq 0x60(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x4a54
addq $0x10, %r14
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x4390
leaq 0x1b614(%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 0x7b82
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x4548
jmp 0x7b94
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x4548
jmp 0x7ba6
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
jmp 0x7c1e
jmp 0x7c25
jmp 0x7bf3
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x81fe
jmp 0x7bc9
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x4548
jmp 0x7bd8
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x4548
jmp 0x7be7
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x4548
jmp 0x7bf6
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8236
jmp 0x7c28
jmp 0x7c25
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
jmp 0x7c1e
jmp 0x7c25
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x4548
jmp 0x7c28
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x4548
movq %rbx, %rdi
callq 0x4490
nop