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

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

    loadVariableFromMemory(b, name, freeRegister, r);
    regToSub.variableName = "";
    regToSub.state = RegisterState::UNKNOWN;

    auto linesToAdd = generateNumber(shift, memoryCell, regToSub);
    _addressRegister.state = RegisterState::UNKNOWN;    
    b.insert(linesToAdd);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %r8, 0x8(%rsp)
movq %rcx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movq %rdx, 0x10(%rsp)
leaq 0x30(%rdx), %r13
leaq 0x2f08a(%rip), %rsi     # 0x395bd
movl $0x1, %ecx
movq %r13, %rdi
xorl %edx, %edx
callq 0x44a0
leaq 0x130(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x42c0
movq (%r15), %r13
leaq 0x120(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq 0x110(%rsp), %rdi
callq 0xca12
leaq 0x110(%rsp), %rsi
movq %r13, %rdi
callq 0x1a7e6
movq %rax, (%rsp)
movq 0x110(%rsp), %rdi
cmpq %rbp, %rdi
je 0xa5b3
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x42a0
movq (%r15), %r13
leaq 0x100(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x130(%rsp), %rsi
movq 0x138(%rsp), %rdx
addq %rsi, %rdx
leaq 0xf0(%rsp), %rdi
callq 0xca12
movq %r14, %rbp
leaq 0xf0(%rsp), %rsi
movq %r13, %rdi
callq 0x1b4b8
movq 0x10(%rsp), %r14
movq %rax, %r13
movq 0xf0(%rsp), %rdi
cmpq %r12, %rdi
je 0xa61b
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %r13, 0x48(%rsp)
leaq 0xe0(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2daaf(%rip), %rdx     # 0x380e3
leaq 0xd0(%rsp), %rdi
movq %rdx, %rsi
callq 0x54fc
leaq 0x150(%rsp), %rsi
movq %r14, (%rsi)
movq %rbp, 0x8(%rsi)
leaq 0x30(%rsp), %rdi
leaq 0x18(%rsp), %rcx
movl $0x2, %edx
callq 0xc2ee
leaq 0xd0(%rsp), %rsi
leaq 0x30(%rsp), %rcx
movq %r15, %rdi
movq %rbx, %rdx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x7d06
movq %rax, %r13
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xa6a2
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x42a0
movq 0xd0(%rsp), %rdi
cmpq %r12, %rdi
je 0xa6bf
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xc0(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xb0(%rsp), %rdi
callq 0xca12
leaq 0xb0(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rcx
callq 0xaa48
movq 0xb0(%rsp), %rdi
cmpq %r12, %rdi
je 0xa71b
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %r13, %rdi
addq $0x30, %rdi
movq 0x38(%r13), %rdx
leaq 0x2d9b6(%rip), %rcx     # 0x380e3
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x4440
movl $0x0, (%r13)
leaq 0x18(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movq %r15, %rsi
movq (%rsp), %rcx
movq %r13, %r8
callq 0x91bc
movl $0x0, 0x10(%r15)
movq 0x28(%rbx), %rsi
addq $0x20, %rbx
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %rbx, %rdi
callq 0xc3f4
leaq 0xa0(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2d92d(%rip), %rsi     # 0x380ba
leaq 0x2d92b(%rip), %rdx     # 0x380bf
leaq 0x90(%rsp), %rdi
callq 0x54fc
leaq 0x80(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0xca12
leaq 0x60(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2d910(%rip), %rdx     # 0x380e3
leaq 0x50(%rsp), %rdi
movq %rdx, %rsi
callq 0x54fc
leaq 0x150(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
callq 0xbe58
leaq 0x150(%rsp), %rsi
movq %rbx, %rdi
callq 0xcf0e
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa830
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x180(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa851
movq 0x180(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x160(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa872
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x50(%rsp), %rdi
cmpq %r14, %rdi
je 0xa889
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0xa8a3
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0xa8c0
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x18(%rsp), %rdi
callq 0xbf5e
leaq 0x140(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa8eb
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x42a0
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 0xbf10
jmp 0xa912
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r14, %rdi
je 0xa92e
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xa92e
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0xa94d
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xa94d
movq %rax, %rbx
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0xa971
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xa971
jmp 0xa96e
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xbf5e
jmp 0xaa1e
jmp 0xaa1b
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %r12, %rdi
je 0xaa1e
movq 0xc0(%rsp), %rsi
jmp 0xaa0f
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xa9c2
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x42a0
jmp 0xa9c2
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
cmpq %r12, %rdi
je 0xaa1e
movq 0xe0(%rsp), %rsi
jmp 0xaa0f
jmp 0xaa1b
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
cmpq %r12, %rdi
je 0xaa1e
movq 0x100(%rsp), %rsi
jmp 0xaa0f
jmp 0xaa1b
movq %rax, %rbx
movq 0x110(%rsp), %rdi
cmpq %rbp, %rdi
je 0xaa1e
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xaa1e
jmp 0xaa1b
movq %rax, %rbx
leaq 0x140(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaa3f
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %rbx, %rdi
callq 0x44c0
nop