// File: 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:
subq $0x2c8, %rsp            # imm = 0x2C8
movq %rdx, 0x60(%rsp)
movq %rdi, %rax
movq 0x60(%rsp), %rdi
movq %rdi, 0x70(%rsp)
movq %r9, 0x68(%rsp)
movq %rax, 0x2c0(%rsp)
movq %rsi, 0x2b8(%rsp)
movq %rdi, 0x2b0(%rsp)
movq %rcx, 0x2a8(%rsp)
movq %r8, 0x2a0(%rsp)
movq %r9, 0x298(%rsp)
movq 0x2c0(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x471aa(%rip), %rsi     # 0x526cf
xorl %eax, %eax
movl %eax, %edx
movq %rdx, 0x78(%rsp)
callq 0x46b0
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq %rax, %rcx
leaq 0x278(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x4350
movq 0x80(%rsp), %rdi
callq 0xdde0
movq 0x88(%rsp), %rsi
movq %rax, 0x90(%rsp)
leaq 0x250(%rsp), %rdi
callq 0x4180
jmp 0xb581
movq 0x90(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0x20200
movq %rax, 0x58(%rsp)
jmp 0xb59d
leaq 0x250(%rsp), %rdi
callq 0x46e8
movq 0x58(%rsp), %rax
movq 0x80(%rsp), %rdi
movq %rax, 0x270(%rsp)
callq 0xdde0
movq %rax, 0x50(%rsp)
leaq 0x218(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x4180
jmp 0xb5e0
movq 0x50(%rsp), %rdi
leaq 0x218(%rsp), %rsi
callq 0x21630
movq %rax, 0x48(%rsp)
jmp 0xb5f9
leaq 0x218(%rsp), %rdi
callq 0x46e8
movq 0x48(%rsp), %rax
movq %rax, 0x238(%rsp)
leaq 0x1ef(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x4600
movq 0x40(%rsp), %rdx
leaq 0x45aea(%rip), %rsi     # 0x5111b
leaq 0x1f0(%rsp), %rdi
callq 0x4f10
jmp 0xb640
movq 0x2b8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x2a8(%rsp), %rsi
leaq 0x1b0(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xddf0
leaq 0x1b8(%rsp), %rdi
movq 0x2a0(%rsp), %rsi
callq 0xddf0
movq 0x30(%rsp), %rax
movq %rax, 0x1c0(%rsp)
movq $0x2, 0x1c8(%rsp)
leaq 0x1af(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0xde20
movq 0x38(%rsp), %rcx
movq 0x1c0(%rsp), %rsi
movq 0x1c8(%rsp), %rdx
leaq 0x1d0(%rsp), %rdi
callq 0xde30
jmp 0xb6cb
movq 0x28(%rsp), %rdx
movq 0x80(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
leaq 0x1d0(%rsp), %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x7ac0
movq %rax, 0x20(%rsp)
jmp 0xb6fd
leaq 0x1d0(%rsp), %rdi
callq 0xd9c0
leaq 0x1af(%rsp), %rdi
callq 0xdec0
leaq 0x1f0(%rsp), %rdi
callq 0x46e8
leaq 0x1ef(%rsp), %rdi
callq 0x43b0
movq 0x20(%rsp), %rax
movq 0x68(%rsp), %rsi
movq %rax, 0x210(%rsp)
movq 0x2b8(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x4180
jmp 0xb75f
movq 0x18(%rsp), %rsi
movq 0x80(%rsp), %rdi
movq 0x2a0(%rsp), %rcx
movq 0x2a8(%rsp), %r8
leaq 0x188(%rsp), %rdx
callq 0xa6e0
jmp 0xb78b
leaq 0x188(%rsp), %rdi
callq 0x46e8
movq 0x80(%rsp), %rsi
movq 0x270(%rsp), %rcx
movq 0x210(%rsp), %r8
leaq 0x170(%rsp), %rdi
leaq 0x238(%rsp), %rdx
callq 0x8830
jmp 0xb7c7
movq 0x210(%rsp), %rdi
addq $0x30, %rdi
leaq 0x45941(%rip), %rsi     # 0x5111b
callq 0x44a0
jmp 0xb7e1
movq 0x80(%rsp), %rax
movq 0x210(%rsp), %rcx
movl $0x0, (%rcx)
movl $0x0, 0x10(%rax)
movq 0x2b8(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0xd4d0
jmp 0xb815
movq 0x2b8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x8(%rsp)
leaq 0xe7(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x4600
movq 0x10(%rsp), %rdx
leaq 0x458b4(%rip), %rsi     # 0x510f8
leaq 0xe8(%rsp), %rdi
callq 0x4f10
jmp 0xb853
movq 0x2a8(%rsp), %rsi
addq $0x10, %rsi
leaq 0xc0(%rsp), %rdi
callq 0x4180
jmp 0xb86e
leaq 0x9f(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x4600
movq (%rsp), %rdx
leaq 0x45891(%rip), %rsi     # 0x5111b
leaq 0xa0(%rsp), %rdi
callq 0x4f10
jmp 0xb899
leaq 0x108(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
leaq 0xa0(%rsp), %rcx
callq 0xd3b0
jmp 0xb8c0
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0xd380
jmp 0xb8d4
leaq 0x108(%rsp), %rdi
callq 0xd490
leaq 0xa0(%rsp), %rdi
callq 0x46e8
leaq 0x9f(%rsp), %rdi
callq 0x43b0
leaq 0xc0(%rsp), %rdi
callq 0x46e8
leaq 0xe8(%rsp), %rdi
callq 0x46e8
leaq 0xe7(%rsp), %rdi
callq 0x43b0
leaq 0x170(%rsp), %rdi
callq 0xd550
leaq 0x278(%rsp), %rdi
callq 0x46e8
addq $0x2c8, %rsp            # imm = 0x2C8
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0xbb2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x250(%rsp), %rdi
callq 0x46e8
jmp 0xbb2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x46e8
jmp 0xbb2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0xba10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0xb9f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0xd9c0
leaq 0x1af(%rsp), %rdi
callq 0xdec0
leaq 0x1f0(%rsp), %rdi
callq 0x46e8
leaq 0x1ef(%rsp), %rdi
callq 0x43b0
jmp 0xbb2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x46e8
jmp 0xbb2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0xbb1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0xbb11
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0xbb04
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0xbaea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0xbadd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x108(%rsp), %rdi
callq 0xd490
leaq 0xa0(%rsp), %rdi
callq 0x46e8
leaq 0x9f(%rsp), %rdi
callq 0x43b0
leaq 0xc0(%rsp), %rdi
callq 0x46e8
leaq 0xe8(%rsp), %rdi
callq 0x46e8
leaq 0xe7(%rsp), %rdi
callq 0x43b0
leaq 0x170(%rsp), %rdi
callq 0xd550
leaq 0x278(%rsp), %rdi
callq 0x46e8
movq 0x248(%rsp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)