// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rcx, %r12
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
leaq 0xe8(%rsp), %r13
leaq 0xd50d(%rip), %rbx      # 0x23504
leaq 0x108(%rsp), %rbp
movq %rdx, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
leaq 0x68(%r15), %rax
cmpq 0x28(%rdx), %rax
je 0x16136
movq %rax, 0x20(%rsp)
leaq 0xa8(%r15), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x8141
testb %al, %al
jne 0x1612e
movq %r13, %rdi
leaq 0xe57d(%rip), %rsi      # 0x245bd
movq %r12, %rdx
callq 0x4acd
movq %rbp, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x4a8f
xorl %r12d, %r12d
movq %r14, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4530
movq %rax, %r14
movq %rbp, %rdi
callq 0x4548
movq %r13, %rdi
callq 0x4548
cmpq $-0x1, %r14
jne 0x16288
movq %r13, %rdi
leaq 0xe530(%rip), %rsi      # 0x245bd
movq 0x18(%rsp), %rdx
callq 0x4acd
movq %rbp, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x4a8f
addq $0x88, %r15
movq %r15, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4530
movq %rax, %r12
movq %rbp, %r14
movq %rbp, %rdi
callq 0x4548
movq %r13, %rbx
movq %r13, %rdi
callq 0x4548
cmpq $-0x1, %r12
jne 0x1612e
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq %rsi, %r12
callq 0x8141
movq 0x20(%rsp), %rsi
movq %rsi, %r15
testb %al, %al
movq 0x10(%rsp), %rdx
movq %rbx, %r13
leaq 0xd403(%rip), %rbx      # 0x23504
movq %r14, %rbp
je 0x16009
movq 0x8(%rsp), %r14
leaq 0xb8(%r14), %rdi
callq 0x16974
addq $0xc0, %r14
cmpq %r14, %rax
sete %r12b
jmp 0x16288
xorl %r12d, %r12d
jmp 0x16288
cmpq $0x0, 0x80(%rdx)
je 0x161b1
addq $0x78, %rdx
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x4390
movq 0x8(%rsp), %r15
leaq 0x10(%r15), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1b1b0
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x4548
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x4390
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x162fc
movl %eax, %r12d
leaq 0xa8(%rsp), %rdi
callq 0x4548
jmp 0x16288
cmpq $0x0, 0x60(%rdx)
movq 0x8(%rsp), %r13
je 0x16285
leaq 0x58(%rdx), %rsi
leaq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0x4390
leaq 0x10(%r13), %rbx
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1b1b0
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x4548
leaq 0x68(%rsp), %r15
movq %r15, %rdi
movq %r12, %rbp
movq %r12, %rsi
callq 0x4390
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x162fc
movl %eax, %r12d
leaq 0x68(%rsp), %rdi
callq 0x4548
movq 0x10(%rsp), %rsi
addq $0x38, %rsi
leaq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0x4390
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1b1b0
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x4548
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4390
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x162fc
movl %eax, %ebx
leaq 0x28(%rsp), %rdi
callq 0x4548
andb %bl, %r12b
jmp 0x16288
movb $0x1, %r12b
movl %r12d, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x162ef
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x162ef
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x162ef
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x162ef
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x162ef
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x162ef
jmp 0x162e4
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x4548
movq %rbx, %rdi
callq 0x4490