// File: /workspace/github_cpp_makefile_star2_O3/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, 0x10(%rsp)
movq %rdx, %r13
movq %rsi, 0x8(%rsp)
movq %rdi, %r15
movq (%rdi), %r12
leaq 0x1d8(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rdx), %rsi
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
leaq 0x1c8(%rsp), %rbp
movq %rbp, %rdi
callq 0xc7aa
movq %r12, %rdi
movq %rbp, %rsi
callq 0x1a522
movq %rax, 0xe8(%rsp)
movq 0x1c8(%rsp), %rdi
cmpq %r14, %rdi
je 0xa848
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x68(%r15), %r12
movq 0x70(%r15), %rbp
cmpq %rbp, %r12
je 0xaa24
movq 0x8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0xe0(%rsp)
xorl %r14d, %r14d
leaq 0x78(%rsp), %rbx
movl (%r12), %eax
cmpl $0x4, %eax
je 0xa880
cmpl $0x1, %eax
jne 0xa8a2
movq 0x38(%r12), %rdx
cmpq 0x8(%r13), %rdx
jne 0xa8a2
testq %rdx, %rdx
je 0xa8b0
movq (%r13), %rsi
movq 0x30(%r12), %rdi
callq 0x42b0
testl %eax, %eax
je 0xa8b0
addq $0x58, %r12
cmpq %rbp, %r12
jne 0xa872
jmp 0xaa1a
leaq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x2c7ff(%rip), %rsi     # 0x370c5
leaq 0x2c7fc(%rip), %rdx     # 0x370c9
callq 0x53cc
movq %rbx, %r14
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rdi
callq 0xc7aa
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0xc7aa
movq %r14, %rdi
leaq 0x38(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %rbx, %rcx
callq 0xbbea
movq 0xe0(%rsp), %rdi
movq %r14, %rsi
callq 0xccac
movq %r14, %rbx
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0xa96a
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xa98f
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xa9b1
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xa9cd
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xa9e9
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xaa05
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x42a0
addq $0x58, %r12
movb $0x1, %r14b
cmpq %rbp, %r12
jne 0xa872
jmp 0xad51
testb $0x1, %r14b
jne 0xad51
cmpl $0x0, 0x10(%r15)
jne 0xaba4
leaq 0x1b8(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2c653(%rip), %rsi     # 0x37096
leaq 0x2c64f(%rip), %rdx     # 0x37099
leaq 0x1a8(%rsp), %rdi
callq 0x53cc
leaq 0x198(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x2c62a(%rip), %rsi     # 0x37094
leaq 0x2c624(%rip), %rdx     # 0x37095
leaq 0x188(%rsp), %rdi
callq 0x53cc
leaq 0x178(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x2c603(%rip), %rsi     # 0x37094
leaq 0x2c5fd(%rip), %rdx     # 0x37095
leaq 0x168(%rsp), %rdi
callq 0x53cc
leaq 0x78(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
leaq 0x188(%rsp), %rdx
leaq 0x168(%rsp), %rcx
callq 0xbbea
movq 0x8(%rsp), %rax
leaq 0x20(%rax), %rdi
leaq 0x78(%rsp), %rsi
callq 0xccac
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaafb
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xab1c
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xab3d
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x168(%rsp), %rdi
cmpq %rbp, %rdi
je 0xab5a
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x188(%rsp), %rdi
cmpq %r13, %rdi
je 0xab77
movq 0x198(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x1a8(%rsp), %rdi
cmpq %r12, %rdi
je 0xab94
movq 0x1b8(%rsp), %rsi
incq %rsi
callq 0x42a0
movl $0x2, 0x10(%r15)
movq $0x0, 0x18(%r15)
addq $0x18, %r15
leaq 0xf0(%rsp), %rdi
movq %r15, %rdx
movq 0xe8(%rsp), %rcx
callq 0x64be
leaq 0x158(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2c4ed(%rip), %rsi     # 0x370c0
leaq 0x2c4ea(%rip), %rdx     # 0x370c4
leaq 0x148(%rsp), %rdi
callq 0x53cc
leaq 0x138(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
addq %rsi, %rdx
leaq 0x128(%rsp), %rdi
callq 0xc7aa
leaq 0x118(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2c4bf(%rip), %rdx     # 0x370e3
leaq 0x108(%rsp), %rdi
movq %rdx, %rsi
callq 0x53cc
leaq 0x78(%rsp), %rdi
leaq 0x148(%rsp), %rsi
leaq 0x128(%rsp), %rdx
leaq 0x108(%rsp), %rcx
callq 0xbbea
leaq 0xf0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0xccac
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xac89
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xacaa
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaccb
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
je 0xace8
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x128(%rsp), %rdi
cmpq %r12, %rdi
je 0xad05
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x148(%rsp), %rdi
cmpq %r15, %rdi
je 0xad22
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x8(%rsp), %rdi
movq 0x28(%rdi), %rsi
addq $0x20, %rdi
movq 0xf0(%rsp), %rdx
movq 0xf8(%rsp), %rcx
callq 0xc18c
leaq 0xf0(%rsp), %rdi
callq 0xbcf0
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0xbca2
jmp 0xad75
movq %rax, %rbx
movq 0x168(%rsp), %rdi
cmpq %rbp, %rdi
je 0xad97
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xad97
movq %rax, %rbx
movq 0x188(%rsp), %rdi
cmpq %r13, %rdi
je 0xadb9
movq 0x198(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xadb9
movq %rax, %rbx
movq 0x1a8(%rsp), %rdi
cmpq %r12, %rdi
je 0xaefb
movq 0x1b8(%rsp), %rsi
jmp 0xaef3
jmp 0xadd9
movq %rax, %rbx
jmp 0xaefb
movq %rax, %rbx
jmp 0xae35
movq %rax, %rbx
jmp 0xae19
movq %rax, %rbx
jmp 0xadfd
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0xbca2
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xae19
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xae35
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xaefb
movq 0x48(%rsp), %rsi
jmp 0xaef3
jmp 0xaec9
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0xbca2
jmp 0xae66
movq %rax, %rbx
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
je 0xae88
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xae88
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r12, %rdi
je 0xaeaa
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xaeaa
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r15, %rdi
je 0xaecc
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0xaecc
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0xbcf0
jmp 0xaefb
movq %rax, %rbx
movq 0x1c8(%rsp), %rdi
cmpq %r14, %rdi
je 0xaefb
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %rbx, %rdi
callq 0x44c0
nop