// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
cmpb $0x1, 0x74(%rdi)
je 0x5a00
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
testl %edx, %edx
je 0x5942
cmpl $0x2, %edx
jne 0x59ee
movl %edx, 0x4(%rsp)
movq 0x80(%r14), %rax
movq %rax, 0x20(%rsp)
leaq 0xe0(%rbx), %rax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
leaq (%rsp,%rbp), %rsi
addq $0x20, %rsi
movq 0x18(%rsp), %rdi
movq %rsi, 0x10(%rsp)
callq 0xb3c8
movq (%rax), %r15
movq 0x8(%rax), %r13
movq %r13, %rax
subq %r15, %rax
cmpq $0x5, %rax
jb 0x5998
movq %r12, 0x8(%rsp)
cmpq %r13, %r15
je 0x594e
xorl %r12d, %r12d
movl (%r15), %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5706
testq %rax, %rax
je 0x5920
movl 0x60(%rax), %eax
xorl %ecx, %ecx
cmpl 0x60(%r14), %eax
setne %cl
addl %ecx, %r12d
addq $0x4, %r15
cmpq %r13, %r15
jne 0x58fc
testl %r12d, %r12d
je 0x594e
addq $0x4, %rbp
cmpq $0x8, %rbp
sete %r12b
jne 0x58c1
movl 0x4(%rsp), %eax
jmp 0x59a8
cmpl $0x2, 0x78(%r14)
jae 0x59b6
jmp 0x59ee
cmpl $0x0, 0x60(%rbx)
movq 0x8(%rsp), %r12
je 0x5998
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x4d08
movq (%r15), %rsi
movq 0x10(%rsp), %rax
movl (%rax), %edx
leaq 0xae3b(%rip), %rdi      # 0x107b8
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x2030
movq (%r15), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x5998
callq 0x2140
movl $0x1, %r15d
testb $0x1, %r12b
movl 0x4(%rsp), %eax
je 0x59ee
xorl %r15d, %r15d
testl %eax, %eax
jne 0x59ee
cmpl $0x1, 0x78(%r14)
jbe 0x59ee
leaq 0x68(%rbx), %rdi
addq $0x60, %r14
movq %r14, %rsi
callq 0xb3c8
movq (%rax), %r14
movq 0x8(%rax), %r12
movl $0x1, %r15d
cmpq %r12, %r14
je 0x59ee
movl (%r14), %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5706
addq $0x4, %r14
jmp 0x59d3
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xad66(%rip), %rdi      # 0x1076d
leaq 0xa722(%rip), %rsi      # 0x10130
leaq 0xad60(%rip), %rcx      # 0x10775
movl $0x46a, %edx            # imm = 0x46A
callq 0x20e0
nop