// File: 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:
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x140(%rsp)
movq 0x140(%rsp), %rdi
movq %rdi, 0x38(%rsp)
addq $0x10, %rdi
callq 0x29fd0
movq %rax, 0x138(%rsp)
movq 0x38(%rsp), %rdi
addq $0x10, %rdi
callq 0x2a870
movq %rax, 0x130(%rsp)
leaq 0x138(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x30be0
testb $0x1, %al
jne 0x3eb31
jmp 0x3ed29
leaq 0x138(%rsp), %rdi
callq 0x2bda0
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x3f7a0
testb $0x1, %al
jne 0x3eb54
jmp 0x3ed0b
leaq 0x138(%rsp), %rdi
callq 0x2bda0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x11660
movq %rax, %rdi
leaq 0x1264d(%rip), %rsi     # 0x511c4
callq 0xdd10
testb $0x1, %al
jne 0x3eb85
jmp 0x3ed09
leaq 0x138(%rsp), %rdi
callq 0x2bda0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x11660
movq %rax, %rsi
addq $0x40, %rsi
leaq 0x110(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x4180
movq 0x30(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x40b0
jmp 0x3ebcc
leaq 0xd8(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x4180
jmp 0x3ebe3
movq 0x38(%rsp), %rdi
movq %rdi, %rdx
addq $0x10, %rdx
leaq 0xd8(%rsp), %rsi
callq 0x3d720
movq %rax, 0x28(%rsp)
jmp 0x3ec03
leaq 0xd8(%rsp), %rdi
callq 0x46e8
movq 0x28(%rsp), %rax
movq %rax, 0xf8(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x2bda0
movq 0x38(%rsp), %rdi
movq %rax, %rsi
movq 0xf8(%rsp), %rdx
callq 0x3f860
jmp 0x3ec41
movq 0x38(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x18(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x2a040
movq 0x18(%rsp), %rdi
movq 0xc8(%rsp), %rsi
callq 0x30c50
movq %rax, 0x20(%rsp)
jmp 0x3ec7d
movq 0x20(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x138(%rsp)
leaq 0x138(%rsp), %rdi
xorl %esi, %esi
callq 0x30cc0
movq %rax, 0xc0(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x46e8
jmp 0x3ed09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x3ecf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x46e8
leaq 0x110(%rsp), %rdi
callq 0x46e8
jmp 0x3eee1
jmp 0x3ed0b
jmp 0x3ed0d
leaq 0x138(%rsp), %rdi
xorl %esi, %esi
callq 0x30d00
movq %rax, 0xb8(%rsp)
jmp 0x3eafd
movq 0x38(%rsp), %rdi
addq $0x10, %rdi
callq 0x29fd0
movq %rax, 0xa8(%rsp)
leaq 0xa8(%rsp), %rdi
movl $0x1, %esi
callq 0x2a000
movq %rax, 0xb0(%rsp)
movq 0x38(%rsp), %rdi
addq $0x10, %rdi
callq 0x2a870
movq %rax, 0xa0(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x30be0
testb $0x1, %al
jne 0x3ed8d
jmp 0x3eed9
leaq 0xb0(%rsp), %rdi
movl $0x1, %esi
callq 0x2bd50
movq %rax, 0x90(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x2bda0
movq %rax, 0x98(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x2bda0
movq %rax, 0x88(%rsp)
movq 0x98(%rsp), %rdi
addq $0x20, %rdi
callq 0x11660
addq $0x40, %rax
movq %rax, 0x8(%rsp)
movq 0x88(%rsp), %rdx
leaq 0x68(%rsp), %rdi
leaq 0x1279d(%rip), %rsi     # 0x5159c
callq 0x5070
movq 0x8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0xd2c0
movb %al, 0x17(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x46e8
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x3ee2e
jmp 0x3eebe
movq 0x98(%rsp), %rax
addq $0x20, %rax
movq %rax, (%rsp)
movq 0x98(%rsp), %rdi
addq $0x20, %rdi
callq 0xe380
movq %rax, 0x50(%rsp)
leaq 0x50(%rsp), %rdi
movl $0x1, %esi
callq 0x118b0
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xe3b0
movq (%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x30d50
movq 0x38(%rsp), %rdi
movq %rax, 0x48(%rsp)
movq 0x98(%rsp), %rsi
callq 0x3f7a0
testb $0x1, %al
jne 0x3eea2
jmp 0x3eebc
movq 0x38(%rsp), %rdi
movq 0x98(%rsp), %rsi
movq 0x88(%rsp), %rdx
callq 0x3f860
jmp 0x3eebe
jmp 0x3eec0
leaq 0xb0(%rsp), %rdi
xorl %esi, %esi
callq 0x30d00
movq %rax, 0x40(%rsp)
jmp 0x3ed59
addq $0x148, %rsp            # imm = 0x148
retq
movq 0x108(%rsp), %rdi
callq 0x45f0
nop