// File: /workspace/github_cpp_makefile_star2_O2/Merulo[P]CompilerJFTT/src/Register/RegisterBlock.cpp
// Function: RegisterBlock::loadVarTableFromMemory(Block&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Register&, Register&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void RegisterBlock::loadVarTableFromMemory(Block& b, std::string name, Register& r, Register& freeRegister, std::string addresVariableName)
{
    std::string array = name.substr(0, name.find("("));
    unsigned long memoryCell = _symbolTable->getMemoryCell(array);
    unsigned long long shift = _symbolTable->getTableShift(array);

    Register& regToSub = getRegister("", b, {r, freeRegister}, false, true);
    loadVariableFromMemory(b, addresVariableName, freeRegister, r);

    auto linesToAdd = generateNumber(shift, memoryCell, regToSub);
    regToSub.variableName = "";
    regToSub.state = RegisterState::UNKNOWN;

    _addressRegister.state = RegisterState::UNKNOWN;    
    b.insert(linesToAdd);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %r9, 0x10(%rsp)
movq %r8, %r12
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x1c953(%rip), %rsi     # 0x245bd
movq %rdx, %rdi
xorl %edx, %edx
callq 0x4520
leaq 0x130(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x42a0
movq (%r15), %r13
leaq 0x110(%rsp), %rdi
movq %rbp, %rsi
callq 0x4390
leaq 0x110(%rsp), %rsi
movq %r13, %rdi
callq 0x100f2
movq %rax, %rbp
leaq 0x110(%rsp), %rdi
callq 0x4548
movq (%r15), %r13
leaq 0xf0(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x4390
leaq 0xf0(%rsp), %rsi
movq %r13, %rdi
callq 0x109a6
movq %rax, %r13
leaq 0xf0(%rsp), %rdi
callq 0x4548
movq %r13, 0x18(%rsp)
leaq 0x1b3e0(%rip), %rsi     # 0x230e3
leaq 0xd0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x4a54
leaq 0x150(%rsp), %rsi
movq %r14, (%rsi)
movq %r12, 0x8(%rsi)
leaq 0x38(%rsp), %rdi
pushq $0x2
popq %rdx
leaq 0xe(%rsp), %rcx
callq 0x8492
leaq 0xd0(%rsp), %rsi
leaq 0x38(%rsp), %rcx
pushq $0x1
popq %r9
movq %r15, %rdi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x5ec6
movq %rax, %r13
leaq 0x38(%rsp), %rdi
callq 0x9106
leaq 0xd0(%rsp), %rdi
callq 0x4548
leaq 0xb0(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x4390
leaq 0xb0(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rcx
callq 0x7502
leaq 0xb0(%rsp), %rdi
callq 0x4548
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %r15, %rsi
movq %rbp, %rcx
movq %r13, %r8
callq 0x6704
movq %r13, %rdi
addq $0x30, %rdi
leaq 0x1b319(%rip), %rsi     # 0x230e3
callq 0x44e0
andl $0x0, (%r13)
andl $0x0, 0x10(%r15)
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x821e
leaq 0x1b2d3(%rip), %rsi     # 0x230c0
leaq 0x90(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x4a54
addq $0x10, %r14
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x4390
leaq 0x1b2cc(%rip), %rsi     # 0x230e3
leaq 0x50(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x4a54
leaq 0x150(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
callq 0x816a
addq $0x20, %rbx
leaq 0x150(%rsp), %rsi
movq %rbx, %rdi
callq 0x8f90
leaq 0x150(%rsp), %rdi
callq 0x81fe
leaq 0x50(%rsp), %rdi
callq 0x4548
leaq 0x70(%rsp), %rdi
callq 0x4548
leaq 0x90(%rsp), %rdi
callq 0x4548
leaq 0x20(%rsp), %rdi
callq 0x8236
leaq 0x130(%rsp), %rdi
callq 0x4548
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x81fe
jmp 0x7ec5
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x4548
jmp 0x7ed4
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x4548
jmp 0x7ee3
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x4548
jmp 0x7f4c
jmp 0x7f49
jmp 0x7f44
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
jmp 0x7f3d
jmp 0x7f44
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x9106
jmp 0x7f17
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
jmp 0x7f3d
jmp 0x7f44
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
jmp 0x7f3d
jmp 0x7f44
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x4548
jmp 0x7f56
movq %rax, %rbx
jmp 0x7f56
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x8236
leaq 0x130(%rsp), %rdi
callq 0x4548
movq %rbx, %rdi
callq 0x4490
nop