// File: Merulo[P]CompilerJFTT/src/Register/RegisterBlock.cpp
// Function: RegisterBlock::storeSameTable(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Block&)
void RegisterBlock::storeSameTable(std::string name, Block& b)
{
    std::string currentTable = name.substr(0, name.find("("));
    for(auto& reg : _registers)
    {
        if (reg.state != RegisterState::TABLE)
        {
            continue;
        }
        if (name == reg.variableName)
        {
            continue;
        }
        std::string registerTable = reg.variableName.substr(0, reg.variableName.find("("));
        if (registerTable == currentTable)
        {
            saveToMemory(b, reg, _addressRegister);
            reg.state = RegisterState::UNKNOWN;
            reg.variableName = "";
            continue;
        }
        std::string rest = reg.variableName.substr(reg.variableName.find("(") + 1, std::string::npos);
        rest.pop_back();
        if (name == rest)
        {
            saveToMemory(b, reg, _addressRegister);
            reg.state = RegisterState::UNKNOWN;
            reg.variableName = "";
            continue;            
        }
    }
}

// Assembly:
subq $0xd8, %rsp
movq %rsi, 0x18(%rsp)
movq %rdi, %rax
movq 0x18(%rsp), %rdi
movq %rdi, 0x20(%rsp)
movq %rax, 0xd0(%rsp)
movq %rdi, 0xc8(%rsp)
movq %rdx, 0xc0(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x4a3ba(%rip), %rsi     # 0x526cf
xorl %eax, %eax
movl %eax, %edx
callq 0x46b0
movq 0x20(%rsp), %rsi
movq %rax, %rcx
leaq 0xa0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
callq 0x4350
movq 0x28(%rsp), %rax
addq $0x68, %rax
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rdi
callq 0xd710
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %rdi
callq 0xd740
movq %rax, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0xd770
testb $0x1, %al
jne 0x8390
jmp 0x85c0
leaq 0x90(%rsp), %rdi
callq 0xd7b0
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
cmpl $0x3, (%rax)
je 0x83b7
jmp 0x85a2
movq 0x20(%rsp), %rdi
movq 0x80(%rsp), %rsi
addq $0x30, %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x83d3
jmp 0x83d8
jmp 0x85a2
movq 0x80(%rsp), %rdi
addq $0x30, %rdi
movq %rdi, 0x8(%rsp)
leaq 0x4a2df(%rip), %rsi     # 0x526cf
xorl %eax, %eax
movl %eax, %edx
movq %rdx, 0x10(%rsp)
callq 0x46b0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rax, %rcx
leaq 0x60(%rsp), %rdi
callq 0x4350
jmp 0x8417
leaq 0x60(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x842f
jmp 0x84ad
movq 0x28(%rsp), %rdi
movq 0xc0(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq %rdi, %rcx
addq $0x10, %rcx
callq 0x60a0
jmp 0x8452
movq 0x80(%rsp), %rax
movl $0x0, (%rax)
movq 0x80(%rsp), %rdi
addq $0x30, %rdi
leaq 0x48ca8(%rip), %rsi     # 0x5111b
callq 0x44a0
jmp 0x847a
movl $0x3, 0x50(%rsp)
jmp 0x858a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x85d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x85b4
movq 0x80(%rsp), %rdi
addq $0x30, %rdi
movq %rdi, (%rsp)
leaq 0x4a20b(%rip), %rsi     # 0x526cf
xorl %eax, %eax
movl %eax, %edx
callq 0x46b0
movq (%rsp), %rsi
movq %rax, %rdx
incq %rdx
leaq 0x30(%rsp), %rdi
movq $-0x1, %rcx
callq 0x4350
jmp 0x84ea
leaq 0x30(%rsp), %rdi
callq 0x4430
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x8509
jmp 0x8578
movq 0x28(%rsp), %rdi
movq 0xc0(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq %rdi, %rcx
addq $0x10, %rcx
callq 0x60a0
jmp 0x852c
movq 0x80(%rsp), %rax
movl $0x0, (%rax)
movq 0x80(%rsp), %rdi
addq $0x30, %rdi
leaq 0x48bce(%rip), %rsi     # 0x5111b
callq 0x44a0
jmp 0x8554
movl $0x3, 0x50(%rsp)
jmp 0x8580
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x46e8
jmp 0x85b4
movl $0x0, 0x50(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x46e8
leaq 0x60(%rsp), %rdi
callq 0x46e8
movl 0x50(%rsp), %eax
testl %eax, %eax
je 0x85a0
jmp 0x859e
jmp 0x85a2
jmp 0x85a2
leaq 0x90(%rsp), %rdi
callq 0xd7c0
jmp 0x8372
leaq 0x60(%rsp), %rdi
callq 0x46e8
jmp 0x85d5
leaq 0xa0(%rsp), %rdi
callq 0x46e8
addq $0xd8, %rsp
retq
leaq 0xa0(%rsp), %rdi
callq 0x46e8
movq 0x58(%rsp), %rdi
callq 0x45f0
nopl (%rax)