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

    bool found = false;
    for (auto& regs : _registers)
    {
        if ((regs.state == RegisterState::VARIABLE || regs.state == RegisterState::CONSTVARIABLE) && regs.variableName == name)
        {
            found = true;
            b.lines.push_back({"COPY", r.name, regs.name});
        }
    }

    if (!found)
    {
        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 $0x1e8, %rsp            # imm = 0x1E8
movq %rcx, 0x8(%rsp)
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, (%rsp)
movq (%rdi), %rbx
leaq 0x1d8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rdx), %rsi
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
leaq 0x1c8(%rsp), %r15
movq %r15, %rdi
callq 0xca12
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1a7e6
movq %rax, 0xe0(%rsp)
movq 0x1c8(%rsp), %rdi
cmpq %r12, %rdi
je 0xaac2
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x42a0
movq (%rsp), %rdx
movq 0x68(%rdx), %rbx
movq 0x70(%rdx), %r15
cmpq %r15, %rbx
je 0xac9f
movq %rbp, 0xd8(%rsp)
leaq 0x20(%rbp), %rax
movq %rax, 0xe8(%rsp)
xorl %r12d, %r12d
leaq 0x70(%rsp), %r14
movl (%rbx), %eax
cmpl $0x4, %eax
je 0xab03
cmpl $0x1, %eax
jne 0xac7c
movq 0x38(%rbx), %rdx
cmpq 0x8(%r13), %rdx
jne 0xac7c
testq %rdx, %rdx
je 0xab2b
movq (%r13), %rsi
movq 0x30(%rbx), %rdi
callq 0x42b0
testl %eax, %eax
jne 0xac7c
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x50(%rsp), %r12
movq %r12, %rdi
leaq 0x2d581(%rip), %rsi     # 0x380c5
leaq 0x2d57e(%rip), %rdx     # 0x380c9
callq 0x54fc
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
callq 0xca12
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
callq 0xca12
movq %r14, %rdi
movq %r12, %rsi
leaq 0x10(%rsp), %rdx
movq %rbp, %rcx
callq 0xbe58
movq 0xe8(%rsp), %rdi
movq %r14, %rsi
callq 0xcf0e
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0xabde
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0xac03
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0xac25
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xac41
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xac5d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xac79
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x42a0
movb $0x1, %r12b
addq $0x58, %rbx
cmpq %r15, %rbx
jne 0xaaf3
testb $0x1, %r12b
movq 0xd8(%rsp), %rbp
movq (%rsp), %rdx
jne 0xafc4
cmpl $0x0, 0x10(%rdx)
jne 0xae1c
leaq 0x1b8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2d3da(%rip), %rsi     # 0x38096
leaq 0x2d3d6(%rip), %rdx     # 0x38099
leaq 0x1a8(%rsp), %rdi
callq 0x54fc
leaq 0x198(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2d3b0(%rip), %rsi     # 0x38094
leaq 0x2d3aa(%rip), %rdx     # 0x38095
leaq 0x188(%rsp), %rdi
callq 0x54fc
leaq 0x178(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x2d389(%rip), %rsi     # 0x38094
leaq 0x2d383(%rip), %rdx     # 0x38095
leaq 0x168(%rsp), %rdi
callq 0x54fc
leaq 0x70(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
leaq 0x188(%rsp), %rdx
leaq 0x168(%rsp), %rcx
callq 0xbe58
leaq 0x20(%rbp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xcf0e
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xad70
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xad91
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xadb2
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x168(%rsp), %rdi
cmpq %r13, %rdi
je 0xadcf
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x188(%rsp), %rdi
cmpq %r12, %rdi
je 0xadec
movq 0x198(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x1a8(%rsp), %rdi
cmpq %r15, %rdi
je 0xae09
movq 0x1b8(%rsp), %rsi
incq %rsi
callq 0x42a0
movq (%rsp), %rdx
movl $0x2, 0x10(%rdx)
movq $0x0, 0x18(%rdx)
addq $0x18, %rdx
leaq 0xf0(%rsp), %rdi
movq 0xe0(%rsp), %rcx
callq 0x65be
leaq 0x158(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2d278(%rip), %rsi     # 0x380c0
leaq 0x2d275(%rip), %rdx     # 0x380c4
leaq 0x148(%rsp), %rdi
callq 0x54fc
leaq 0x138(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
addq %rsi, %rdx
leaq 0x128(%rsp), %rdi
callq 0xca12
leaq 0x118(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2d24a(%rip), %rdx     # 0x380e3
leaq 0x108(%rsp), %rdi
movq %rdx, %rsi
callq 0x54fc
leaq 0x70(%rsp), %rdi
leaq 0x148(%rsp), %rsi
leaq 0x128(%rsp), %rdx
leaq 0x108(%rsp), %rcx
callq 0xbe58
leaq 0xf0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xcf0e
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaefe
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaf1f
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaf40
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
je 0xaf5d
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x128(%rsp), %rdi
cmpq %r12, %rdi
je 0xaf7a
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x148(%rsp), %rdi
cmpq %r15, %rdi
je 0xaf97
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x28(%rbp), %rsi
addq $0x20, %rbp
movq 0xf0(%rsp), %rdx
movq 0xf8(%rsp), %rcx
movq %rbp, %rdi
callq 0xc3f4
leaq 0xf0(%rsp), %rdi
callq 0xbf5e
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0xbf10
jmp 0xafe8
movq %rax, %rbx
movq 0x168(%rsp), %rdi
cmpq %r13, %rdi
je 0xb00a
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xb00a
movq %rax, %rbx
movq 0x188(%rsp), %rdi
cmpq %r12, %rdi
je 0xb02c
movq 0x198(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xb02c
movq %rax, %rbx
movq 0x1a8(%rsp), %rdi
cmpq %r15, %rdi
je 0xb16a
movq 0x1b8(%rsp), %rsi
jmp 0xb15d
jmp 0xb167
jmp 0xb0c6
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0xbf10
jmp 0xb063
movq %rax, %rbx
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
je 0xb085
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xb085
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r12, %rdi
je 0xb0a7
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xb0a7
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r15, %rdi
je 0xb0c9
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xb0c9
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0xbf5e
jmp 0xb16a
movq %rax, %rbx
movq 0x1c8(%rsp), %rdi
cmpq %r12, %rdi
je 0xb16a
movq 0x1d8(%rsp), %rsi
jmp 0xb15d
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0xbf10
jmp 0xb107
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xb128
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xb128
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xb149
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xb149
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xb16a
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xb16a
movq %rax, %rbx
movq %rbx, %rdi
callq 0x44c0