// File: /workspace/github_cpp_makefile_star2_O2/Merulo[P]CompilerJFTT/src/IRs/FourthIR.cpp
// Function: FourthIR::alignRegisters(Pair&, Pair&, RegisterBlock&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void FourthIR::alignRegisters(Pair& pair, Pair& next, RegisterBlock& rb, std::string name)
{
    Block handle = generateBlock();
    RegisterBlock copy(pair.endRegisterBlock);
    handle.blockJump = next.block.blockName;
    copy.exitBlock(handle, next.startRegisterBlock, *this);

    Block& grr = getBlockByName(pair.block.blockName, _blocks);

    for(auto& l : grr.lines)
    {
        if (l.two == "#" + name)
        {
            l.two = "#" + handle.blockName;
        }
        if (l.operation.find(name) != std::string::npos)
        {
            l.operation.replace(l.operation.find(name), name.length(), handle.blockName);
        }        
    }
    handle.lines.push_back({"JUMP", "", "#" +  next.block.blockName});
    _blocks.push_back(handle);
            
    convertBlockToAssembler(next, copy);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %r8, %r12
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %rsi
leaq 0xa8(%rsp), %rdi
movq %rsi, 0x10(%rsp)
callq 0x1af06
leaq 0xa0(%rbx), %rsi
leaq 0x1b0(%rsp), %rdi
callq 0x4c30
leaq 0x120(%rsp), %rdi
movq %r14, %rsi
callq 0x4180
leaq 0x128(%r14), %rdx
leaq 0x1b0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
movq 0x10(%rsp), %rcx
callq 0x4e04
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
callq 0x4390
movq 0x10(%rsp), %rdi
leaq 0x10(%rdi), %rdx
leaq 0x88(%rsp), %rsi
movq %rdx, 0x18(%rsp)
callq 0x1b1b0
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4548
movq 0x20(%rbx), %r13
movq 0x28(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0x148(%rsp), %r15
cmpq 0x20(%rsp), %r13
je 0x19945
movq %r15, %rdi
leaq 0x9ca6(%rip), %rsi      # 0x2355b
movq %r12, %rdx
callq 0x4acd
leaq 0x40(%r13), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x8141
movl %eax, %ebx
movq %r15, %rdi
callq 0x4548
testb %bl, %bl
je 0x19904
movq %r15, %rdi
leaq 0x9c77(%rip), %rsi      # 0x2355b
leaq 0xa8(%rsp), %rdx
callq 0x4acd
movq %rbp, %rdi
movq %r15, %rsi
callq 0x4340
movq %r15, %rdi
callq 0x4548
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x4530
cmpq $-0x1, %rax
je 0x1993c
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x4530
movq 0x8(%r12), %rdx
movq %r13, %rdi
movq %rax, %rsi
leaq 0xa8(%rsp), %rcx
callq 0x4110
addq $0x68, %r13
jmp 0x198a0
leaq 0x9840(%rip), %rsi      # 0x2318c
leaq 0x68(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x4a54
leaq 0x9781(%rip), %rsi      # 0x230e3
leaq 0x48(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x4a54
leaq 0x9be3(%rip), %rsi      # 0x2355b
leaq 0x28(%rsp), %rdi
movq %r14, %rdx
callq 0x4acd
leaq 0x148(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x48(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x816a
leaq 0xc8(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x8f90
leaq 0x148(%rsp), %rdi
callq 0x81fe
leaq 0x28(%rsp), %rdi
callq 0x4548
leaq 0x48(%rsp), %rdi
callq 0x4548
leaq 0x68(%rsp), %rdi
callq 0x4548
leaq 0xa8(%rsp), %rsi
movq 0x18(%rsp), %rdi
callq 0x13a6a
leaq 0x1b0(%rsp), %rdx
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x16c54
leaq 0x1b0(%rsp), %rdi
callq 0x19d86
leaq 0xa8(%rsp), %rdi
callq 0x13ad2
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x81fe
jmp 0x19a49
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4548
jmp 0x19a58
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x4548
jmp 0x19a67
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x19a7b
jmp 0x19a8f
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4548
jmp 0x19a92
movq %rax, %rbx
jmp 0x19a9f
jmp 0x19a8f
jmp 0x19a8f
jmp 0x19a8f
jmp 0x19a8f
movq %rax, %rbx
leaq 0x1b0(%rsp), %rdi
callq 0x19d86
leaq 0xa8(%rsp), %rdi
callq 0x13ad2
movq %rbx, %rdi
callq 0x4490