// File: Merulo[P]CompilerJFTT/src/IRs/SecondIR.cpp
// Function: SecondIR::removeEmptyBlocks()
void SecondIR::removeEmptyBlocks()
{
    for(auto& b : _blocks)
    {
        if (b.lines.size() == 0)
        {
            std::string jumpBlockName = b.blockJump;
            for(auto& bb : _blocks)
            {
                if (bb.blockJump == b.blockName)
                {
                    bb.blockJump = jumpBlockName;
                    continue;
                }
                if (bb.blockIfTrue == b.blockName)
                {
                    bb.blockIfTrue = jumpBlockName;
                    continue;
                }
                if (bb.blockIfFalse == b.blockName)
                {
                    bb.blockIfFalse = jumpBlockName;
                    continue;
                }
            }
        }
    }
    for(auto it = _blocks.begin(); it != _blocks.end(); it++)
    {
        if (it->lines.size() == 0)
        {
            it = _blocks.erase(it);
            it--;
        }
    }
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x8(%rsp)
addq $0x10, %rax
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x29fd0
movq %rax, 0xa0(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x2a870
movq %rax, 0x98(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x30be0
testb $0x1, %al
jne 0x2c6c0
jmp 0x2c841
leaq 0xa0(%rsp), %rdi
callq 0x2bda0
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rdi
addq $0x20, %rdi
callq 0xfbf0
cmpq $0x0, %rax
jne 0x2c82d
movq 0x90(%rsp), %rsi
addq $0x78, %rsi
leaq 0x70(%rsp), %rdi
callq 0x4180
movq 0x8(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rdi
callq 0x29fd0
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rdi
callq 0x2a870
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x30be0
testb $0x1, %al
jne 0x2c74a
jmp 0x2c823
leaq 0x60(%rsp), %rdi
callq 0x2bda0
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rdi
addq $0x78, %rdi
movq 0x90(%rsp), %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x2c775
jmp 0x2c7ac
movq 0x50(%rsp), %rdi
addq $0x78, %rdi
leaq 0x70(%rsp), %rsi
callq 0x4050
jmp 0x2c78a
jmp 0x2c814
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x46e8
jmp 0x2c902
movq 0x50(%rsp), %rdi
addq $0x38, %rdi
movq 0x90(%rsp), %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x2c7c8
jmp 0x2c7df
movq 0x50(%rsp), %rdi
addq $0x38, %rdi
leaq 0x70(%rsp), %rsi
callq 0x4050
jmp 0x2c7dd
jmp 0x2c814
movq 0x50(%rsp), %rdi
addq $0x58, %rdi
movq 0x90(%rsp), %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x2c7fb
jmp 0x2c812
movq 0x50(%rsp), %rdi
addq $0x58, %rdi
leaq 0x70(%rsp), %rsi
callq 0x4050
jmp 0x2c810
jmp 0x2c814
jmp 0x2c814
leaq 0x60(%rsp), %rdi
callq 0x30c20
jmp 0x2c732
leaq 0x70(%rsp), %rdi
callq 0x46e8
jmp 0x2c82f
leaq 0xa0(%rsp), %rdi
callq 0x30c20
jmp 0x2c6a2
movq 0x8(%rsp), %rdi
addq $0x10, %rdi
callq 0x29fd0
movq %rax, 0x38(%rsp)
movq 0x8(%rsp), %rdi
addq $0x10, %rdi
callq 0x2a870
movq %rax, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x30be0
testb $0x1, %al
jne 0x2c87c
jmp 0x2c8fa
leaq 0x38(%rsp), %rdi
callq 0x30c40
movq %rax, %rdi
addq $0x20, %rdi
callq 0xfbf0
cmpq $0x0, %rax
jne 0x2c8e2
movq 0x8(%rsp), %rax
addq $0x10, %rax
movq %rax, (%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x2a040
movq (%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x30c50
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
callq 0x30cc0
movq %rax, 0x18(%rsp)
jmp 0x2c8e4
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
callq 0x30d00
movq %rax, 0x10(%rsp)
jmp 0x2c854
addq $0xb8, %rsp
retq
movq 0x48(%rsp), %rdi
callq 0x45f0
nopl (%rax)