// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movb $0x1, %bpl
cmpb $0x0, 0x98(%rsi)
jne 0x165af
movq %rdx, %r14
movq %rdi, 0x8(%rsp)
movb $0x1, 0x98(%rsi)
movq 0x20(%rsi), %r12
leaq 0xe286(%rip), %r15      # 0x245bd
leaq 0xd8(%rsp), %rbx
movq %rsi, 0x10(%rsp)
cmpq 0x28(%rsi), %r12
je 0x16441
leaq 0x40(%r12), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x8141
testb %al, %al
jne 0x1643a
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4acd
leaq 0xf8(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
leaq 0xd17b(%rip), %rdx      # 0x23504
callq 0x4a8f
movq %rbp, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x4530
movq %rax, %rbp
movq %r13, %rdi
callq 0x4548
movq %rbx, %rdi
callq 0x4548
cmpq $-0x1, %rbp
jne 0x1643a
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rsi
callq 0x4acd
movq %r13, %rdi
movq %rbx, %rsi
leaq 0xd131(%rip), %rdx      # 0x23504
callq 0x4a8f
movq %r13, %r15
movq %r12, %r13
leaq 0x20(%r12), %rbp
movq %rbp, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x4530
movq %r15, %rdi
movq %rax, %r15
callq 0x4548
movq %rbx, %r12
movq %rbx, %rdi
callq 0x4548
cmpq $-0x1, %r15
jne 0x1643a
movq %rbp, %rdi
movq %r14, %rsi
callq 0x8141
testb %al, %al
jne 0x164bd
addq $0x68, %r13
movq 0x10(%rsp), %rsi
leaq 0xe18e(%rip), %r15      # 0x245bd
movq %r12, %rbx
movq %r13, %r12
jmp 0x16344
xorl %ebp, %ebp
jmp 0x165af
cmpq $0x0, 0x80(%rsi)
je 0x164e4
addq $0x78, %rsi
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
callq 0x4390
movq 0x8(%rsp), %r12
leaq 0x10(%r12), %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1b1b0
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x4548
leaq 0x98(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x4390
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x162fc
movl %eax, %ebp
leaq 0x98(%rsp), %rdi
callq 0x4548
jmp 0x165af
movq 0x8(%rsp), %rbx
leaq 0xb8(%rbx), %rdi
movq %r13, %rsi
callq 0x16974
addq $0xc0, %rbx
cmpq %rbx, %rax
sete %bpl
jmp 0x165af
cmpq $0x0, 0x60(%rsi)
movq 0x8(%rsp), %r13
movb $0x1, %bpl
je 0x165af
addq $0x58, %rsi
leaq 0x78(%rsp), %r15
movq %r15, %rdi
callq 0x4390
leaq 0x10(%r13), %rbx
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1b1b0
movq %rax, %r12
leaq 0x78(%rsp), %rdi
callq 0x4548
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x4390
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x162fc
movl %eax, %ebp
leaq 0x58(%rsp), %rdi
callq 0x4548
movq 0x10(%rsp), %rsi
addq $0x38, %rsi
leaq 0x38(%rsp), %r15
movq %r15, %rdi
callq 0x4390
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1b1b0
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x4548
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x4390
movq %r13, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x162fc
movl %eax, %ebx
leaq 0x18(%rsp), %rdi
callq 0x4548
andb %bl, %bpl
movl %ebp, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
jmp 0x16612
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x16612
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0x16612
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x16612
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x16612
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0x16612
jmp 0x16607
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x4548
movq %rbx, %rdi
callq 0x4490
nop