// File: Merulo[P]CompilerJFTT/src/Register/RegisterBlock.cpp
// Function: RegisterBlock::saveConstTableToMemory(Block&, Register&, Register&, unsigned long long)
void RegisterBlock::saveConstTableToMemory(Block& b, Register& r, Register& freeRegister, unsigned long long diff)
{
    std::string array = r.variableName.substr(0, r.variableName.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({"STORE", r.name});
    b.insert(lines);
}

// Assembly:
subq $0x2e8, %rsp            # imm = 0x2E8
movq %rdi, 0x2e0(%rsp)
movq %rsi, 0x2d8(%rsp)
movq %rdx, 0x2d0(%rsp)
movq %rcx, 0x2c8(%rsp)
movq %r8, 0x2c0(%rsp)
movq 0x2e0(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x2d0(%rsp), %rdi
addq $0x30, %rdi
movq %rdi, 0x48(%rsp)
leaq 0x48c3b(%rip), %rsi     # 0x526cf
xorl %eax, %eax
movl %eax, %edx
movq %rdx, 0x50(%rsp)
callq 0x46b0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %rax, %rcx
leaq 0x2a0(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x4350
movq 0x58(%rsp), %rdi
callq 0xdde0
movq 0x60(%rsp), %rsi
movq %rax, 0x68(%rsp)
leaq 0x278(%rsp), %rdi
callq 0x4180
jmp 0x9ae4
movq 0x68(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x20200
movq %rax, 0x40(%rsp)
jmp 0x9afd
leaq 0x278(%rsp), %rdi
callq 0x46e8
movq 0x40(%rsp), %rax
movq 0x58(%rsp), %rdi
movq %rax, 0x298(%rsp)
callq 0xdde0
movq %rax, 0x38(%rsp)
leaq 0x240(%rsp), %rdi
leaq 0x2a0(%rsp), %rsi
callq 0x4180
jmp 0x9b3d
movq 0x38(%rsp), %rdi
leaq 0x240(%rsp), %rsi
callq 0x21630
movq %rax, 0x30(%rsp)
jmp 0x9b56
leaq 0x240(%rsp), %rdi
callq 0x46e8
movq 0x30(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x260(%rsp)
movq 0x298(%rsp), %rcx
addq 0x2c0(%rsp), %rcx
subq 0x260(%rsp), %rcx
movq %rcx, 0x298(%rsp)
cmpl $0x0, 0x10(%rax)
jne 0x9e1a
movq 0x2d8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x20(%rsp)
leaq 0x1b7(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x4600
movq 0x28(%rsp), %rdx
leaq 0x47500(%rip), %rsi     # 0x510ce
leaq 0x1b8(%rsp), %rdi
callq 0x4f10
jmp 0x9bdd
leaq 0x18f(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x4600
movq 0x18(%rsp), %rdx
leaq 0x474d1(%rip), %rsi     # 0x510cc
leaq 0x190(%rsp), %rdi
callq 0x4f10
jmp 0x9c0a
leaq 0x167(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x4600
movq 0x10(%rsp), %rdx
leaq 0x474a4(%rip), %rsi     # 0x510cc
leaq 0x168(%rsp), %rdi
callq 0x4f10
jmp 0x9c37
leaq 0x1d8(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
leaq 0x190(%rsp), %rdx
leaq 0x168(%rsp), %rcx
callq 0xd3b0
jmp 0x9c5e
movq 0x20(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
callq 0xd380
jmp 0x9c72
leaq 0x1d8(%rsp), %rdi
callq 0xd490
leaq 0x168(%rsp), %rdi
callq 0x46e8
leaq 0x167(%rsp), %rdi
callq 0x43b0
leaq 0x190(%rsp), %rdi
callq 0x46e8
leaq 0x18f(%rsp), %rdi
callq 0x43b0
leaq 0x1b8(%rsp), %rdi
callq 0x46e8
leaq 0x1b7(%rsp), %rdi
callq 0x43b0
movq 0x58(%rsp), %rax
movl $0x2, 0x10(%rax)
movq $0x0, 0x18(%rax)
jmp 0x9e1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0xa048
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
leaq 0x278(%rsp), %rdi
callq 0x46e8
jmp 0xa048
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x46e8
jmp 0xa048
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0x9e08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0x9dee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0x9dd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0x9dc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0xd490
leaq 0x168(%rsp), %rdi
callq 0x46e8
leaq 0x167(%rsp), %rdi
callq 0x43b0
leaq 0x190(%rsp), %rdi
callq 0x46e8
leaq 0x18f(%rsp), %rdi
callq 0x43b0
leaq 0x1b8(%rsp), %rdi
callq 0x46e8
leaq 0x1b7(%rsp), %rdi
callq 0x43b0
jmp 0xa048
movq 0x58(%rsp), %rsi
movq %rsi, %rdx
addq $0x18, %rdx
movq 0x298(%rsp), %rcx
movq 0x2c8(%rsp), %r8
leaq 0x148(%rsp), %rdi
callq 0x6770
jmp 0x9e45
leaq 0xbf(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x4600
movq 0x8(%rsp), %rdx
leaq 0x4728f(%rip), %rsi     # 0x510f2
leaq 0xc0(%rsp), %rdi
callq 0x4f10
jmp 0x9e72
movq 0x2d0(%rsp), %rsi
addq $0x10, %rsi
leaq 0x98(%rsp), %rdi
callq 0x4180
jmp 0x9e8d
leaq 0x77(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x4600
movq (%rsp), %rdx
leaq 0x47275(%rip), %rsi     # 0x5111b
leaq 0x78(%rsp), %rdi
callq 0x4f10
jmp 0x9eb2
leaq 0xe0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0x98(%rsp), %rdx
leaq 0x78(%rsp), %rcx
callq 0xd3b0
jmp 0x9ed6
leaq 0x148(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0xd380
jmp 0x9eed
leaq 0xe0(%rsp), %rdi
callq 0xd490
leaq 0x78(%rsp), %rdi
callq 0x46e8
leaq 0x77(%rsp), %rdi
callq 0x43b0
leaq 0x98(%rsp), %rdi
callq 0x46e8
leaq 0xc0(%rsp), %rdi
callq 0x46e8
leaq 0xbf(%rsp), %rdi
callq 0x43b0
movq 0x2d8(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0xd4d0
jmp 0x9f4c
leaq 0x148(%rsp), %rdi
callq 0xd550
leaq 0x2a0(%rsp), %rdi
callq 0x46e8
addq $0x2e8, %rsp            # imm = 0x2E8
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0xa018
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0xa00b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0x9ff4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0x9fea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0xd490
leaq 0x78(%rsp), %rdi
callq 0x46e8
leaq 0x77(%rsp), %rdi
callq 0x43b0
leaq 0x98(%rsp), %rdi
callq 0x46e8
leaq 0xc0(%rsp), %rdi
callq 0x46e8
leaq 0xbf(%rsp), %rdi
callq 0x43b0
jmp 0xa03b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
leaq 0x148(%rsp), %rdi
callq 0xd550
leaq 0x2a0(%rsp), %rdi
callq 0x46e8
movq 0x270(%rsp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)