// File: /workspace/github_cpp_makefile_star2_O3/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 $0x228, %rsp            # imm = 0x228
movq %r8, %r12
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x100(%rsp), %rdi
movq %r15, %rsi
callq 0x2b47a
leaq 0xa0(%rbx), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x54ec
leaq 0x178(%rsp), %rdi
movq %r14, %rsi
callq 0x4170
leaq 0x128(%r14), %rdx
leaq 0x1a0(%rsp), %rdi
leaq 0x100(%rsp), %rsi
movq %r15, %rcx
callq 0x58ba
movq %r14, (%rsp)
leaq 0x68(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0xc7aa
leaq 0x10(%r15), %rdx
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
movq %rdx, 0x8(%rsp)
callq 0x2bb9e
movq %rax, %rbx
movq %r15, 0x10(%rsp)
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x295a6
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x20(%rbx), %r13
movq 0x28(%rbx), %rbx
cmpq %rbx, %r13
je 0x296e3
addq $0x40, %r13
leaq 0x98(%rsp), %r15
movq %r15, %rdi
leaq 0xdf8e(%rip), %rsi      # 0x3755b
movq %r12, %rdx
callq 0x5344
movq 0x8(%r13), %rdx
cmpq 0xa0(%rsp), %rdx
jne 0x29604
movq 0x98(%rsp), %r14
testq %rdx, %rdx
je 0x29610
movq (%r13), %rdi
movq %r14, %rsi
callq 0x42b0
testl %eax, %eax
sete %bpl
jmp 0x29613
movq 0x98(%rsp), %r14
xorl %ebp, %ebp
jmp 0x29613
movb $0x1, %bpl
leaq 0xa8(%rsp), %rax
cmpq %rax, %r14
je 0x29633
movq 0xa8(%rsp), %rsi
incq %rsi
movq %r14, %rdi
callq 0x42a0
testb %bpl, %bpl
je 0x2967f
movq %r15, %rdi
leaq 0xdf19(%rip), %rsi      # 0x3755b
leaq 0x100(%rsp), %rdx
callq 0x5344
movq %r13, %rdi
movq %r15, %rsi
callq 0x4380
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x2967f
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq -0x40(%r13), %r14
movq (%r12), %rsi
movq 0x8(%r12), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x44a0
cmpq $-0x1, %rax
je 0x296cf
movq (%r12), %rsi
movq 0x8(%r12), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x44a0
movq 0x8(%r12), %rdx
movq 0x100(%rsp), %rcx
movq 0x108(%rsp), %r8
movq %r14, %rdi
movq %rax, %rsi
callq 0x4300
leaq 0x68(%r13), %rax
addq $0x28, %r13
cmpq %rbx, %r13
movq %rax, %r13
jne 0x295c3
leaq 0x48(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xda99(%rip), %rsi      # 0x3718c
leaq 0xda96(%rip), %rdx      # 0x37190
leaq 0x38(%rsp), %rdi
callq 0x53cc
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xd9cf(%rip), %rdx      # 0x370e3
leaq 0x18(%rsp), %rdi
movq %rdx, %rsi
callq 0x53cc
movq 0x10(%rsp), %rbx
leaq 0xde2e(%rip), %rsi      # 0x3755b
leaq 0x78(%rsp), %rdi
movq (%rsp), %rdx
callq 0x5344
leaq 0x98(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x18(%rsp), %rdx
leaq 0x78(%rsp), %rcx
callq 0xbbea
leaq 0x120(%rsp), %r12
leaq 0x98(%rsp), %rsi
movq %r12, %rdi
callq 0xccac
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29790
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x297b1
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x297d2
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x297f3
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x2980a
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
je 0x29821
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x100(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x1f720
leaq 0x1a0(%rsp), %rdx
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x2475c
leaq 0x208(%rsp), %rbx
movq %rbx, %rdi
callq 0xbbba
movq -0x28(%rbx), %rdi
leaq 0x1f0(%rsp), %rax
cmpq %rax, %rdi
je 0x29878
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x1d0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29899
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x1a8(%rsp), %rdi
testq %rdi, %rdi
je 0x298ab
callq 0xc11c
leaq 0x188(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x298cc
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x168(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x298ed
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2990e
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %r12, %rdi
callq 0xbcf0
leaq 0x110(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29937
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x42a0
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0xbca2
jmp 0x2995e
movq %rax, %rbx
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29984
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x29984
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x299a0
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x299a0
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
je 0x299df
movq 0x48(%rsp), %rsi
jmp 0x299c5
jmp 0x299dc
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x299df
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x299df
movq %rax, %rbx
jmp 0x299ec
jmp 0x299dc
jmp 0x299dc
jmp 0x299dc
jmp 0x299dc
movq %rax, %rbx
leaq 0x1a0(%rsp), %rdi
callq 0x29daa
leaq 0x100(%rsp), %rdi
callq 0x1f750
movq %rbx, %rdi
callq 0x44c0
nop