// File: /workspace/github_cpp_makefile_star2_O3/Merulo[P]CompilerJFTT/src/IRs/FifthIR.cpp
// Function: FifthIR::removeJumps()
void FifthIR::removeJumps()
{
    for(auto b = _blocks.begin(); b != _blocks.end(); b++)
    {
        if (onlyComments(*b))
        {
            if ((*b).lines.back().operation == "JUMP")
            {
                std::string arg = (*b).lines.back().two;
                arg.erase(0, 1);
                Block& current = getBlockByName(arg, _blocks);
                replaceJump((*b), current);  
                b = _blocks.erase(b);
                b--;
            }
        }
    }
    for(auto it = _blocks.begin() + 1; it != _blocks.end(); it++)
    {
        Block& previous = *(it-1);
        Block& current = *it;
        if(previous.lines.back().two == "#" + current.blockName)
        {
            previous.lines.erase(previous.lines.end() - 1);
            if (onlyComments(previous))
            {
                replaceJump(previous, current);
            }
        }
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %r14
cmpq 0x18(%rdi), %r14
je 0x2c81b
leaq 0x10(%rbx), %r15
leaq 0xaa74(%rip), %r12      # 0x3718c
leaq 0x28(%rsp), %rbp
movq %r14, %rsi
callq 0x2d174
testb %al, %al
je 0x2c805
movq 0x28(%r14), %rdi
addq $-0x68, %rdi
movq %r12, %rsi
callq 0x40d0
testl %eax, %eax
jne 0x2c805
movq 0x28(%r14), %rax
leaq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movq -0x28(%rax), %rsi
movq -0x20(%rax), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0xc7aa
movl $0x1, %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x4090
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0xc7aa
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x2bb9e
movq %rax, %r13
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x2c7c6
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2d1da
movq %r15, %rdi
movq %r14, %rsi
callq 0x23f22
movq %rax, %r14
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2c7fe
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
addq $-0xa0, %r14
addq $0xa0, %r14
cmpq 0x18(%rbx), %r14
jne 0x2c71d
movq (%r15), %r15
jmp 0x2c81e
movq %r14, %r15
leaq 0xa0(%r15), %rax
cmpq %r14, %rax
je 0x2c8e4
leaq 0x8(%rsp), %r12
movq %r15, %r13
addq $0xa0, %r15
movq 0x28(%r13), %r14
movq %r12, %rdi
leaq 0xad10(%rip), %rsi      # 0x3755b
movq %r15, %rdx
callq 0x5344
movq -0x20(%r14), %rdx
cmpq 0x10(%rsp), %rdx
jne 0x2c87c
movq 0x8(%rsp), %rbp
testq %rdx, %rdx
je 0x2c886
movq -0x28(%r14), %rdi
movq %rbp, %rsi
callq 0x42b0
testl %eax, %eax
sete %r14b
jmp 0x2c889
movq 0x8(%rsp), %rbp
xorl %r14d, %r14d
jmp 0x2c889
movb $0x1, %r14b
leaq 0x18(%rsp), %rax
cmpq %rax, %rbp
je 0x2c8a3
movq 0x18(%rsp), %rsi
incq %rsi
movq %rbp, %rdi
callq 0x42a0
testb %r14b, %r14b
je 0x2c8d3
leaq 0x20(%r13), %rdi
movq 0x28(%r13), %rsi
addq $-0x68, %rsi
callq 0x24050
movq %r13, %rsi
callq 0x2d174
testb %al, %al
je 0x2c8d3
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2d1da
addq $0x140, %r13            # imm = 0x140
cmpq 0x18(%rbx), %r13
jne 0x2c833
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2c918
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x2c91b
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x2c91b
jmp 0x2c918
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2c937
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %rbx, %rdi
callq 0x44c0
nop