// File: /workspace/github_cpp_makefile_star2_O3/realuptime[P]PolyDetector/PolyDetector.cpp
// Function: PolyLine::canBeRemoved(PolyDetector&, RmLinesType) const
uint32_t PolyLine::canBeRemoved(PolyDetector &pd, RmLinesType type) const
{
    assert(!ignore);
    
    //if (type == 1 && verbose)
    //    logoutf("canBeRemoved(%s) type:%d", toString(pd).c_str(), type);
    
    if (type == RmLinesType::NoPointNeigh)
    {
        // Remove lines having points with no neighbors
        for (auto &abId : {aIdx, bIdx})
        {
            auto &neigh = pd.pointToLines[abId];
            if (neigh.size() <= 1) // including self
            {
                //if (pd.verbose)
                //    logoutf("canBeRemoved(%s) point with no neighbors! CAN be removed", toString(pd).c_str());
                return true;
            }
            
            // check also ignore flag
            uint32_t nNeigh = 0;
            for (auto &n : neigh)
            {
                auto l = pd.findLine(n);
                if (l && l->id != id)
                    nNeigh++;
            }
            if (nNeigh == 0)
            {
                if (pd.verbose)
                    logoutf("canBeRemoved(%s) point P%u with no neighbors (%u) (check ignore flag)! CAN be removed", toString(pd).c_str(), abId, nNeigh);
                return true;
            }
        }
    }
    if (type == RmLinesType::TakenTwice)
    {
        if (took >= 2)
        {
            for (auto &lid : pd._neighbors[id])
            {
                auto l = pd.findLine(lid);
                if (l && l->id != id)
                {
                    //if (pd.verbose)
                    //    logoutf("nlid %s", l->toString(pd).c_str());
                    
                    //if (!l->took)
                    if (l->took < 0)
                    {
                        return false;
                    }
                }
            }
            //logoutf("canBeRemoved(%s) line tooked 2 times! CAN be removed", toString(pd).c_str());
            return true;
        }
    }
    
    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpb $0x1, 0x74(%rdi)
je 0x5ac2
movq %rsi, %rbx
movq %rdi, %r14
xorl %ebp, %ebp
testl %edx, %edx
je 0x5a1f
cmpl $0x2, %edx
jne 0x5ab1
movq 0x80(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rbx), %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
leaq (%rsp,%r13), %r12
addq $0x10, %r12
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0xb536
movq (%rax), %rbp
movq 0x8(%rax), %r15
movq %r15, %rax
subq %rbp, %rax
cmpq $0x5, %rax
jb 0x5aac
movq %r12, (%rsp)
cmpq %r15, %rbp
je 0x5a66
xorl %r12d, %r12d
movl (%rbp), %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5842
testq %rax, %rax
je 0x5a00
movl 0x60(%rax), %eax
xorl %ecx, %ecx
cmpl 0x60(%r14), %eax
setne %cl
addl %ecx, %r12d
addq $0x4, %rbp
cmpq %r15, %rbp
jne 0x59dc
testl %r12d, %r12d
je 0x5a66
addq $0x4, %r13
cmpq $0x8, %r13
jne 0x59a0
xorl %ebp, %ebp
jmp 0x5ab1
cmpl $0x2, 0x78(%r14)
jb 0x5ab1
leaq 0x68(%rbx), %rdi
addq $0x60, %r14
movq %r14, %rsi
callq 0xb536
movq (%rax), %r14
movq 0x8(%rax), %r15
cmpq %r15, %r14
je 0x5aac
movl $0x1, %ebp
movl (%r14), %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5842
addq $0x4, %r14
cmpq %r15, %r14
jne 0x5a4b
jmp 0x5ab1
cmpl $0x0, 0x60(%rbx)
movq (%rsp), %r12
je 0x5aac
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x4e48
movq (%r15), %rsi
movl (%r12), %edx
leaq 0xad37(%rip), %rdi      # 0x107c8
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x2030
movq (%r15), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x5aac
callq 0x2140
movl $0x1, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xacb4(%rip), %rdi      # 0x1077d
leaq 0xa670(%rip), %rsi      # 0x10140
leaq 0xacae(%rip), %rcx      # 0x10785
movl $0x46a, %edx            # imm = 0x46A
callq 0x20e0
nop