// File: /workspace/github_cpp_makefile_star2_O1/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 0x2b716
leaq 0xa0(%rbx), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x5614
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 0x59e2
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 0xca12
leaq 0x10(%r15), %rdx
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
movq %rdx, 0x8(%rsp)
callq 0x2be3a
movq %rax, %rbx
movq %r15, 0x10(%rsp)
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x2985e
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x20(%rbx), %r13
movq 0x28(%rbx), %rbx
cmpq %rbx, %r13
je 0x29995
addq $0x40, %r13
leaq 0xece1(%rip), %rbp      # 0x3855b
leaq 0x98(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x5474
movq 0x8(%r13), %rdx
cmpq 0xa0(%rsp), %rdx
jne 0x298bc
testq %rdx, %rdx
je 0x298c1
movq 0x98(%rsp), %rsi
movq (%r13), %rdi
callq 0x42b0
testl %eax, %eax
sete %r14b
jmp 0x298c4
xorl %r14d, %r14d
jmp 0x298c4
movb $0x1, %r14b
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x298e9
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x42a0
testb %r14b, %r14b
je 0x29931
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x100(%rsp), %rdx
callq 0x5474
movq %r13, %rdi
movq %r15, %rsi
callq 0x4380
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x29931
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 0x29981
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 0x29882
leaq 0x48(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xe7e7(%rip), %rsi      # 0x3818c
leaq 0xe7e4(%rip), %rdx      # 0x38190
leaq 0x38(%rsp), %rdi
callq 0x54fc
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xe71d(%rip), %rdx      # 0x380e3
leaq 0x18(%rsp), %rdi
movq %rdx, %rsi
callq 0x54fc
movq 0x10(%rsp), %rbx
leaq 0xeb7c(%rip), %rsi      # 0x3855b
leaq 0x78(%rsp), %rdi
movq (%rsp), %rdx
callq 0x5474
leaq 0x98(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x18(%rsp), %rdx
leaq 0x78(%rsp), %rcx
callq 0xbe58
leaq 0x120(%rsp), %r12
leaq 0x98(%rsp), %rsi
movq %r12, %rdi
callq 0xcf0e
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29a42
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29a63
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29a84
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29aa5
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x29abc
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
je 0x29ad3
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x100(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x1f9e8
leaq 0x1a0(%rsp), %rdx
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x249dc
leaq 0x208(%rsp), %rbx
movq %rbx, %rdi
callq 0xbe28
movq -0x28(%rbx), %rdi
leaq 0x1f0(%rsp), %rax
cmpq %rax, %rdi
je 0x29b2a
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x1d0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29b4b
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x1a8(%rsp), %rdi
testq %rdi, %rdi
je 0x29b5d
callq 0xc384
leaq 0x188(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29b7e
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x168(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29b9f
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29bc0
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %r12, %rdi
callq 0xbf5e
leaq 0x110(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29be9
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 0xbf10
jmp 0x29c10
movq %rax, %rbx
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29c36
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x29c36
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x29c52
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x29c52
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
je 0x29c91
movq 0x48(%rsp), %rsi
jmp 0x29c77
jmp 0x29c8e
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x29c91
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x29c91
movq %rax, %rbx
jmp 0x29c9e
jmp 0x29c8e
jmp 0x29c8e
jmp 0x29c8e
jmp 0x29c8e
movq %rax, %rbx
leaq 0x1a0(%rsp), %rdi
callq 0x2a05c
leaq 0x100(%rsp), %rdi
callq 0x1fa18
movq %rbx, %rdi
callq 0x44c0
nop