// File: Merulo[P]CompilerJFTT/src/Register/RegisterBlock.cpp
// Function: RegisterBlock::saveToMemory(Block&, Register&, Register&)
void RegisterBlock::saveToMemory(Block& b, Register& r, Register& freeRegister)
{
    if ((r.state == RegisterState::VARIABLE || r.state == RegisterState::CONSTVARIABLE) && !r.variableName.empty())
    {
        if (r.variableName == "IF_CONTROL_VARIABLE")
        {
            return;
        }
        if (r.needToSafe)
        {
            saveVariableToMemory(b, r, freeRegister);
        }
    }
    else if (r.state == RegisterState::TABLE)
    {
        std::string rest = r.variableName.substr(r.variableName.find("(") + 1, std::string::npos);
        rest.pop_back();
        if (isDigits(rest))
        {
            saveConstTableToMemory(b, r, freeRegister, std::stoull(rest));
        }
        else 
        {
            saveVarTableToMemory(b, r, freeRegister, rest);
        }
    }
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movq %rdx, 0xb0(%rsp)
movq %rcx, 0xa8(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0xb0(%rsp), %rax
cmpl $0x1, (%rax)
je 0x60ee
movq 0xb0(%rsp), %rax
cmpl $0x4, (%rax)
jne 0x615b
movq 0xb0(%rsp), %rdi
addq $0x30, %rdi
callq 0x45b0
testb $0x1, %al
jne 0x615b
movq 0xb0(%rsp), %rdi
addq $0x30, %rdi
leaq 0x4afc8(%rip), %rsi     # 0x510de
callq 0xdd10
testb $0x1, %al
jne 0x6121
jmp 0x6126
jmp 0x62fb
movq 0xb0(%rsp), %rax
testb $0x1, 0x50(%rax)
je 0x6156
movq 0x50(%rsp), %rdi
movq 0xb8(%rsp), %rsi
movq 0xb0(%rsp), %rdx
movq 0xa8(%rsp), %rcx
callq 0x9540
jmp 0x62fb
movq 0xb0(%rsp), %rax
cmpl $0x3, (%rax)
jne 0x62f9
movq 0xb0(%rsp), %rdi
addq $0x30, %rdi
movq %rdi, 0x38(%rsp)
leaq 0x4c54b(%rip), %rsi     # 0x526cf
xorl %eax, %eax
movl %eax, %edx
callq 0x46b0
movq 0x38(%rsp), %rsi
movq %rax, %rdx
incq %rdx
leaq 0x88(%rsp), %rdi
movq %rdi, 0x40(%rsp)
movq $-0x1, %rcx
callq 0x4350
movq 0x40(%rsp), %rdi
callq 0x4430
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0xdd40
movb %al, 0x4f(%rsp)
jmp 0x61d0
movb 0x4f(%rsp), %al
testb $0x1, %al
jne 0x61da
jmp 0x6259
movq 0xb8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x28(%rsp)
xorl %eax, %eax
movl %eax, %esi
leaq 0x88(%rsp), %rdi
movl $0xa, %edx
callq 0xdd90
movq %rax, 0x30(%rsp)
jmp 0x621e
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x50(%rsp), %rdi
callq 0x9a40
jmp 0x623e
jmp 0x62db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
jmp 0x62ea
movq 0xb8(%rsp), %rax
movq %rax, (%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x4180
jmp 0x6293
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdx
movq (%rsp), %rsi
movq 0x50(%rsp), %rdi
leaq 0x58(%rsp), %r8
callq 0xa070
jmp 0x62b2
leaq 0x58(%rsp), %rdi
callq 0x46e8
jmp 0x62db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x46e8
jmp 0x62ea
leaq 0x88(%rsp), %rdi
callq 0x46e8
jmp 0x62f9
leaq 0x88(%rsp), %rdi
callq 0x46e8
jmp 0x6303
jmp 0x62fb
addq $0xc8, %rsp
retq
movq 0x80(%rsp), %rdi
callq 0x45f0