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

    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:
subq $0x2f8, %rsp            # imm = 0x2F8
movq %rdx, 0x48(%rsp)
movq %rdi, %rax
movq 0x48(%rsp), %rdi
movq %rdi, 0x50(%rsp)
movq %rax, 0x2f0(%rsp)
movq %rsi, 0x2e8(%rsp)
movq %rdi, 0x2e0(%rsp)
movq %rcx, 0x2d8(%rsp)
movq %r8, 0x2d0(%rsp)
movq %r9, 0x2c8(%rsp)
movq 0x2f0(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x477f2(%rip), %rsi     # 0x526cf
xorl %eax, %eax
movl %eax, %edx
movq %rdx, 0x58(%rsp)
callq 0x46b0
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq %rax, %rcx
leaq 0x2a8(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x4350
movq 0x60(%rsp), %rdi
callq 0xdde0
movq 0x68(%rsp), %rsi
movq %rax, 0x70(%rsp)
leaq 0x280(%rsp), %rdi
callq 0x4180
jmp 0xaf2d
movq 0x70(%rsp), %rdi
leaq 0x280(%rsp), %rsi
callq 0x20200
movq %rax, 0x40(%rsp)
jmp 0xaf46
leaq 0x280(%rsp), %rdi
callq 0x46e8
movq 0x40(%rsp), %rax
movq 0x60(%rsp), %rdi
movq %rax, 0x2a0(%rsp)
callq 0xdde0
movq %rax, 0x38(%rsp)
leaq 0x248(%rsp), %rdi
leaq 0x2a8(%rsp), %rsi
callq 0x4180
jmp 0xaf86
movq 0x38(%rsp), %rdi
leaq 0x248(%rsp), %rsi
callq 0x21630
movq %rax, 0x30(%rsp)
jmp 0xaf9f
leaq 0x248(%rsp), %rdi
callq 0x46e8
movq 0x30(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x268(%rsp)
movq 0x2a0(%rsp), %rcx
addq 0x2c8(%rsp), %rcx
subq 0x268(%rsp), %rcx
movq %rcx, 0x2a0(%rsp)
cmpl $0x0, 0x10(%rax)
jne 0xb263
movq 0x2e8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x20(%rsp)
leaq 0x1bf(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x4600
movq 0x28(%rsp), %rdx
leaq 0x460b7(%rip), %rsi     # 0x510ce
leaq 0x1c0(%rsp), %rdi
callq 0x4f10
jmp 0xb026
leaq 0x197(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x4600
movq 0x18(%rsp), %rdx
leaq 0x46088(%rip), %rsi     # 0x510cc
leaq 0x198(%rsp), %rdi
callq 0x4f10
jmp 0xb053
leaq 0x16f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x4600
movq 0x10(%rsp), %rdx
leaq 0x4605b(%rip), %rsi     # 0x510cc
leaq 0x170(%rsp), %rdi
callq 0x4f10
jmp 0xb080
leaq 0x1e0(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
leaq 0x198(%rsp), %rdx
leaq 0x170(%rsp), %rcx
callq 0xd3b0
jmp 0xb0a7
movq 0x20(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
callq 0xd380
jmp 0xb0bb
leaq 0x1e0(%rsp), %rdi
callq 0xd490
leaq 0x170(%rsp), %rdi
callq 0x46e8
leaq 0x16f(%rsp), %rdi
callq 0x43b0
leaq 0x198(%rsp), %rdi
callq 0x46e8
leaq 0x197(%rsp), %rdi
callq 0x43b0
leaq 0x1c0(%rsp), %rdi
callq 0x46e8
leaq 0x1bf(%rsp), %rdi
callq 0x43b0
movq 0x60(%rsp), %rax
movl $0x2, 0x10(%rax)
movq $0x0, 0x18(%rax)
jmp 0xb263
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
jmp 0xb49d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
leaq 0x280(%rsp), %rdi
callq 0x46e8
jmp 0xb49d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
leaq 0x248(%rsp), %rdi
callq 0x46e8
jmp 0xb49d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
jmp 0xb251
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
jmp 0xb237
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
jmp 0xb21d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
jmp 0xb210
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0xd490
leaq 0x170(%rsp), %rdi
callq 0x46e8
leaq 0x16f(%rsp), %rdi
callq 0x43b0
leaq 0x198(%rsp), %rdi
callq 0x46e8
leaq 0x197(%rsp), %rdi
callq 0x43b0
leaq 0x1c0(%rsp), %rdi
callq 0x46e8
leaq 0x1bf(%rsp), %rdi
callq 0x43b0
jmp 0xb49d
movq 0x60(%rsp), %rsi
movq %rsi, %rdx
addq $0x18, %rdx
movq 0x2a0(%rsp), %rcx
movq 0x2d0(%rsp), %r8
leaq 0x150(%rsp), %rdi
callq 0x6770
jmp 0xb28e
leaq 0xc7(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x4600
movq 0x8(%rsp), %rdx
leaq 0x45e4c(%rip), %rsi     # 0x510f8
leaq 0xc8(%rsp), %rdi
callq 0x4f10
jmp 0xb2bb
movq 0x2d8(%rsp), %rsi
addq $0x10, %rsi
leaq 0xa0(%rsp), %rdi
callq 0x4180
jmp 0xb2d6
leaq 0x7f(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x4600
movq (%rsp), %rdx
leaq 0x45e2c(%rip), %rsi     # 0x5111b
leaq 0x80(%rsp), %rdi
callq 0x4f10
jmp 0xb2fe
leaq 0xe8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
leaq 0x80(%rsp), %rcx
callq 0xd3b0
jmp 0xb325
leaq 0x150(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0xd380
jmp 0xb33c
leaq 0xe8(%rsp), %rdi
callq 0xd490
leaq 0x80(%rsp), %rdi
callq 0x46e8
leaq 0x7f(%rsp), %rdi
callq 0x43b0
leaq 0xa0(%rsp), %rdi
callq 0x46e8
leaq 0xc8(%rsp), %rdi
callq 0x46e8
leaq 0xc7(%rsp), %rdi
callq 0x43b0
movq 0x2e8(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0xd4d0
jmp 0xb39e
leaq 0x150(%rsp), %rdi
callq 0xd550
leaq 0x2a8(%rsp), %rdi
callq 0x46e8
addq $0x2f8, %rsp            # imm = 0x2F8
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
jmp 0xb46d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
jmp 0xb460
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
jmp 0xb449
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
jmp 0xb43c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xd490
leaq 0x80(%rsp), %rdi
callq 0x46e8
leaq 0x7f(%rsp), %rdi
callq 0x43b0
leaq 0xa0(%rsp), %rdi
callq 0x46e8
leaq 0xc8(%rsp), %rdi
callq 0x46e8
leaq 0xc7(%rsp), %rdi
callq 0x43b0
jmp 0xb490
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x278(%rsp)
movl %eax, 0x274(%rsp)
leaq 0x150(%rsp), %rdi
callq 0xd550
leaq 0x2a8(%rsp), %rdi
callq 0x46e8
movq 0x278(%rsp), %rdi
callq 0x45f0
nopw (%rax,%rax)