// File: Merulo[P]CompilerJFTT/src/IRs/SecondIR.cpp
// Function: SecondIR::canRemoveRecursive(Block&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool SecondIR::canRemoveRecursive(Block& b, std::string name)
{
    if (b.visited)
    {
        return true;
    }
    b.visited = true;
    for (auto line = b.lines.begin(); 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 $0x288, %rsp            # imm = 0x288
movq %rdx, 0xb8(%rsp)
movq %rdi, 0x278(%rsp)
movq %rsi, 0x270(%rsp)
movq %rdx, 0x268(%rsp)
movq 0x278(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x270(%rsp), %rax
testb $0x1, 0x98(%rax)
je 0x303d5
movb $0x1, 0x287(%rsp)
jmp 0x30a55
movq 0x270(%rsp), %rax
movb $0x1, 0x98(%rax)
movq 0x270(%rsp), %rdi
addq $0x20, %rdi
callq 0xe3f0
movq %rax, 0x260(%rsp)
movq 0x270(%rsp), %rdi
addq $0x20, %rdi
callq 0xe380
movq %rax, 0x258(%rsp)
leaq 0x260(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0xec10
testb $0x1, %al
jne 0x30434
jmp 0x306ea
leaq 0x260(%rsp), %rdi
callq 0x30d40
movq 0xb8(%rsp), %rsi
movq %rax, %rdi
addq $0x40, %rdi
callq 0xd2c0
testb $0x1, %al
jne 0x3045b
jmp 0x30468
movb $0x0, 0x287(%rsp)
jmp 0x30a55
leaq 0x260(%rsp), %rdi
callq 0x30d40
movq 0xb8(%rsp), %rdx
addq $0x40, %rax
movq %rax, 0xa8(%rsp)
leaq 0x2223f(%rip), %rsi     # 0x526cf
leaq 0x218(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x5070
movq 0xb0(%rsp), %rsi
leaq 0x21080(%rip), %rdx     # 0x51534
leaq 0x238(%rsp), %rdi
callq 0x4fd0
jmp 0x304c3
movq 0xa8(%rsp), %rdi
leaq 0x238(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x46d0
movq %rax, 0xa0(%rsp)
leaq 0x238(%rsp), %rdi
callq 0x46e8
leaq 0x218(%rsp), %rdi
callq 0x46e8
movq 0xa0(%rsp), %rax
cmpq $-0x1, %rax
je 0x3053f
movb $0x0, 0x287(%rsp)
jmp 0x30a55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x46e8
jmp 0x30a66
leaq 0x260(%rsp), %rdi
callq 0x30d40
movq 0xb8(%rsp), %rdx
addq $0x20, %rax
movq %rax, 0x90(%rsp)
leaq 0x22168(%rip), %rsi     # 0x526cf
leaq 0x1c8(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x5070
movq 0x98(%rsp), %rsi
leaq 0x20fa9(%rip), %rdx     # 0x51534
leaq 0x1e8(%rsp), %rdi
callq 0x4fd0
jmp 0x3059a
movq 0x90(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x46d0
movq %rax, 0x88(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x46e8
leaq 0x1c8(%rsp), %rdi
callq 0x46e8
movq 0x88(%rsp), %rax
cmpq $-0x1, %rax
je 0x30616
movb $0x0, 0x287(%rsp)
jmp 0x30a55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x46e8
jmp 0x30a66
leaq 0x260(%rsp), %rdi
callq 0x30d40
movq 0xb8(%rsp), %rsi
movq %rax, %rdi
addq $0x20, %rdi
callq 0xd2c0
testb $0x1, %al
jne 0x30640
jmp 0x306cc
movq 0xc0(%rsp), %rax
addq $0xb8, %rax
movq %rax, 0x80(%rsp)
leaq 0x260(%rsp), %rdi
callq 0x30d40
movq 0x80(%rsp), %rdi
movq %rax, %rsi
callq 0x31110
movq 0xc0(%rsp), %rdi
movq %rax, 0x1c0(%rsp)
addq $0xb8, %rdi
callq 0x31150
movq %rax, 0x1b8(%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x310f0
testb $0x1, %al
jne 0x306b2
jmp 0x306bf
movb $0x0, 0x287(%rsp)
jmp 0x30a55
movb $0x1, 0x287(%rsp)
jmp 0x30a55
jmp 0x306ce
leaq 0x260(%rsp), %rdi
xorl %esi, %esi
callq 0x30e00
movq %rax, 0x1b0(%rsp)
jmp 0x303fd
movq 0x270(%rsp), %rdi
addq $0x78, %rdi
callq 0x45b0
testb $0x1, %al
jne 0x3080a
movq 0x270(%rsp), %rsi
addq $0x78, %rsi
leaq 0x188(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x4180
movq 0xc0(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq %rdi, %rdx
addq $0x10, %rdx
callq 0x3d720
movq %rax, 0x78(%rsp)
jmp 0x30741
leaq 0x188(%rsp), %rdi
callq 0x46e8
movq 0x78(%rsp), %rax
movq 0xb8(%rsp), %rsi
movq %rax, 0x1a8(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x168(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x4180
movq 0xc0(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
callq 0x30380
movb %al, 0x6f(%rsp)
jmp 0x3079f
movb 0x6f(%rsp), %al
andb $0x1, %al
movb %al, 0x287(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x46e8
jmp 0x30a55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x46e8
jmp 0x30a66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x46e8
jmp 0x30a66
movq 0x270(%rsp), %rdi
addq $0x58, %rdi
callq 0x45b0
testb $0x1, %al
jne 0x30a4b
movq 0x270(%rsp), %rsi
addq $0x58, %rsi
leaq 0x140(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x4180
movq 0xc0(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %rdi, %rdx
addq $0x10, %rdx
callq 0x3d720
movq %rax, 0x50(%rsp)
jmp 0x30861
leaq 0x140(%rsp), %rdi
callq 0x46e8
movq 0x50(%rsp), %rax
movq 0xb8(%rsp), %rsi
movq %rax, 0x160(%rsp)
movq 0x160(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x118(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x4180
movq 0xc0(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0x30380
movb %al, 0x47(%rsp)
jmp 0x308bf
leaq 0x118(%rsp), %rdi
callq 0x46e8
movb 0x47(%rsp), %al
andb $0x1, %al
movb %al, 0x13f(%rsp)
movq 0x270(%rsp), %rsi
addq $0x38, %rsi
leaq 0xf0(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x4180
movq 0xc0(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rdi, %rdx
addq $0x10, %rdx
callq 0x3d720
movq %rax, 0x28(%rsp)
jmp 0x30917
leaq 0xf0(%rsp), %rdi
callq 0x46e8
movq 0x28(%rsp), %rax
movq 0xb8(%rsp), %rsi
movq %rax, 0x110(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0xc8(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x4180
movq 0xc0(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x30380
movb %al, 0x1f(%rsp)
jmp 0x30975
leaq 0xc8(%rsp), %rdi
callq 0x46e8
movb 0x1f(%rsp), %al
andb $0x1, %al
movb %al, 0xef(%rsp)
xorl %eax, %eax
testb $0x1, 0x13f(%rsp)
movb %al, 0x7(%rsp)
je 0x309aa
movb 0xef(%rsp), %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
andb $0x1, %al
movb %al, 0x287(%rsp)
jmp 0x30a55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x46e8
jmp 0x30a66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x46e8
jmp 0x30a66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x46e8
jmp 0x30a66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x46e8
jmp 0x30a66
jmp 0x30a4d
movb $0x1, 0x287(%rsp)
movb 0x287(%rsp), %al
andb $0x1, %al
addq $0x288, %rsp            # imm = 0x288
retq
movq 0x210(%rsp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)
nopl (%rax)