// File: Merulo[P]CompilerJFTT/src/IRs/SecondIR.cpp
// Function: SecondIR::canRemove(__gnu_cxx::__normal_iterator<Line*, std::vector<Line, std::allocator<Line>>>, Block&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool SecondIR::canRemove(std::vector<Line>::iterator line, Block& b, std::string name)
{
    line++;
    for (; line != b.lines.end(); line++)
    {
        if(line->two == name)
        {
            return false;
        }
        if (line->two.find("(" + name + ")") != std::string::npos)
        {
            return false;
        }
        if (line->one.find("(" + name + ")") != std::string::npos)
        {
            return false;
        }  
        if (line->one == name)
        {
            if (_banned.find(line->operation) != _banned.end())
            {
                return false;
            } 
            return true;
        }       
    }
    if (!b.blockJump.empty())
    {
        Block& nextBlock = getBlockByName(b.blockJump, _blocks);
        return canRemoveRecursive(nextBlock, name);
    }
    else if (!b.blockIfFalse.empty())
    {
        Block& blockTrue = getBlockByName(b.blockIfFalse, _blocks);
        bool r1 = canRemoveRecursive(blockTrue, name);  
        Block& blockFalse = getBlockByName(b.blockIfTrue, _blocks);
        bool r2 = canRemoveRecursive(blockFalse, name);  
        return r1 && r2;
    }
    return true;
}

// Assembly:
subq $0x298, %rsp            # imm = 0x298
movq %rcx, 0xc0(%rsp)
movq %rsi, 0x288(%rsp)
movq %rdi, 0x280(%rsp)
movq %rdx, 0x278(%rsp)
movq %rcx, 0x270(%rsp)
movq 0x280(%rsp), %rax
movq %rax, 0xc8(%rsp)
leaq 0x288(%rsp), %rdi
xorl %esi, %esi
callq 0x30e00
movq %rax, 0x268(%rsp)
movq 0x278(%rsp), %rdi
addq $0x20, %rdi
callq 0xe380
movq %rax, 0x260(%rsp)
leaq 0x288(%rsp), %rdi
leaq 0x260(%rsp), %rsi
callq 0xec10
testb $0x1, %al
jne 0x2fd2d
jmp 0x2ffe3
leaq 0x288(%rsp), %rdi
callq 0x30d40
movq 0xc0(%rsp), %rsi
movq %rax, %rdi
addq $0x40, %rdi
callq 0xd2c0
testb $0x1, %al
jne 0x2fd54
jmp 0x2fd61
movb $0x0, 0x297(%rsp)
jmp 0x30354
leaq 0x288(%rsp), %rdi
callq 0x30d40
movq 0xc0(%rsp), %rdx
addq $0x40, %rax
movq %rax, 0xb0(%rsp)
leaq 0x22946(%rip), %rsi     # 0x526cf
leaq 0x220(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x5070
movq 0xb8(%rsp), %rsi
leaq 0x21787(%rip), %rdx     # 0x51534
leaq 0x240(%rsp), %rdi
callq 0x4fd0
jmp 0x2fdbc
movq 0xb0(%rsp), %rdi
leaq 0x240(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x46d0
movq %rax, 0xa8(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x46e8
leaq 0x220(%rsp), %rdi
callq 0x46e8
movq 0xa8(%rsp), %rax
cmpq $-0x1, %rax
je 0x2fe38
movb $0x0, 0x297(%rsp)
jmp 0x30354
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
leaq 0x220(%rsp), %rdi
callq 0x46e8
jmp 0x30365
leaq 0x288(%rsp), %rdi
callq 0x30d40
movq 0xc0(%rsp), %rdx
addq $0x20, %rax
movq %rax, 0x98(%rsp)
leaq 0x2286f(%rip), %rsi     # 0x526cf
leaq 0x1d0(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x5070
movq 0xa0(%rsp), %rsi
leaq 0x216b0(%rip), %rdx     # 0x51534
leaq 0x1f0(%rsp), %rdi
callq 0x4fd0
jmp 0x2fe93
movq 0x98(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x46d0
movq %rax, 0x90(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0x46e8
leaq 0x1d0(%rsp), %rdi
callq 0x46e8
movq 0x90(%rsp), %rax
cmpq $-0x1, %rax
je 0x2ff0f
movb $0x0, 0x297(%rsp)
jmp 0x30354
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x46e8
jmp 0x30365
leaq 0x288(%rsp), %rdi
callq 0x30d40
movq 0xc0(%rsp), %rsi
movq %rax, %rdi
addq $0x20, %rdi
callq 0xd2c0
testb $0x1, %al
jne 0x2ff39
jmp 0x2ffc5
movq 0xc8(%rsp), %rax
addq $0xb8, %rax
movq %rax, 0x88(%rsp)
leaq 0x288(%rsp), %rdi
callq 0x30d40
movq 0x88(%rsp), %rdi
movq %rax, %rsi
callq 0x31110
movq 0xc8(%rsp), %rdi
movq %rax, 0x1c8(%rsp)
addq $0xb8, %rdi
callq 0x31150
movq %rax, 0x1c0(%rsp)
leaq 0x1c8(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x310f0
testb $0x1, %al
jne 0x2ffab
jmp 0x2ffb8
movb $0x0, 0x297(%rsp)
jmp 0x30354
movb $0x1, 0x297(%rsp)
jmp 0x30354
jmp 0x2ffc7
leaq 0x288(%rsp), %rdi
xorl %esi, %esi
callq 0x30e00
movq %rax, 0x1b8(%rsp)
jmp 0x2fcf6
movq 0x278(%rsp), %rdi
addq $0x78, %rdi
callq 0x45b0
testb $0x1, %al
jne 0x30109
movq 0x278(%rsp), %rsi
addq $0x78, %rsi
leaq 0x190(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x4180
movq 0xc8(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq %rdi, %rdx
addq $0x10, %rdx
callq 0x3d720
movq %rax, 0x80(%rsp)
jmp 0x3003d
leaq 0x190(%rsp), %rdi
callq 0x46e8
movq 0x80(%rsp), %rax
movq 0xc0(%rsp), %rsi
movq %rax, 0x1b0(%rsp)
movq 0x1b0(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x170(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x4180
movq 0xc8(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
callq 0x30380
movb %al, 0x77(%rsp)
jmp 0x3009e
movb 0x77(%rsp), %al
andb $0x1, %al
movb %al, 0x297(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x46e8
jmp 0x30354
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x46e8
jmp 0x30365
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x46e8
jmp 0x30365
movq 0x278(%rsp), %rdi
addq $0x58, %rdi
callq 0x45b0
testb $0x1, %al
jne 0x3034a
movq 0x278(%rsp), %rsi
addq $0x58, %rsi
leaq 0x148(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x4180
movq 0xc8(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq %rdi, %rdx
addq $0x10, %rdx
callq 0x3d720
movq %rax, 0x58(%rsp)
jmp 0x30160
leaq 0x148(%rsp), %rdi
callq 0x46e8
movq 0x58(%rsp), %rax
movq 0xc0(%rsp), %rsi
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x120(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x4180
movq 0xc8(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x30380
movb %al, 0x4f(%rsp)
jmp 0x301be
leaq 0x120(%rsp), %rdi
callq 0x46e8
movb 0x4f(%rsp), %al
andb $0x1, %al
movb %al, 0x147(%rsp)
movq 0x278(%rsp), %rsi
addq $0x38, %rsi
leaq 0xf8(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x4180
movq 0xc8(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %rdi, %rdx
addq $0x10, %rdx
callq 0x3d720
movq %rax, 0x30(%rsp)
jmp 0x30216
leaq 0xf8(%rsp), %rdi
callq 0x46e8
movq 0x30(%rsp), %rax
movq 0xc0(%rsp), %rsi
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xd0(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x4180
movq 0xc8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x30380
movb %al, 0x27(%rsp)
jmp 0x30274
leaq 0xd0(%rsp), %rdi
callq 0x46e8
movb 0x27(%rsp), %al
andb $0x1, %al
movb %al, 0xf7(%rsp)
xorl %eax, %eax
testb $0x1, 0x147(%rsp)
movb %al, 0xf(%rsp)
je 0x302a9
movb 0xf7(%rsp), %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
andb $0x1, %al
movb %al, 0x297(%rsp)
jmp 0x30354
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x46e8
jmp 0x30365
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x46e8
jmp 0x30365
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x46e8
jmp 0x30365
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x46e8
jmp 0x30365
jmp 0x3034c
movb $0x1, 0x297(%rsp)
movb 0x297(%rsp), %al
andb $0x1, %al
addq $0x298, %rsp            # imm = 0x298
retq
movq 0x218(%rsp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)