// File: /workspace/github_cpp_makefile_star2_O3/realuptime[P]PolyDetector/PolyDetector.cpp
// Function: PolyCycle::pointConsumed(PolyDetector&, unsigned int) const
bool PolyCycle::pointConsumed(PolyDetector &pd, uint32_t pid) const
{
    auto &neigh = pd.pointToLines[pid];
    if (neigh.size() <= 1) // including self
    {
        if (pd.verbose)
            logoutf("pointConsumed(P%u) point with no neighbors! CAN be removed", pid);
        return true;
    }
    
    uint32_t lid1 = 0, lid2 = 0;
    uint32_t nValid = 0, nTaken = 0;
    for (auto &n : neigh)
    {
        auto l = pd.findLine(n);
        if (l)
        {
            nValid++;
            //if (l->took)
            if (l->took)
            {
#if 0
                //if (collinear)
                // if there is at least one collinear neighbor not taken, fail
                for (auto &nlid : _neighbors[l->id])
                {
                    auto ln = findLine(nlid);
                    //if (ln && ln->took < 2 && CollinearIdx(nlid, l->id))
                    if (ln && ln->took < 2)
                    {
                        return false;
                    }
                }
#endif
                if (nTaken == 0)
                    lid1 = l->id;
                else if (nTaken == 1)
                    lid2 = l->id;
                nTaken++;
            }
        }
    }
    
    //logoutf("P%u has nValid:%u taken:%u", pid, nValid, nTaken);
    
    if (nValid == 2 && nValid == nTaken)
    {
        //logoutf("l1:%u l2:%u", lid1, lid2);
        //if (collinear)
            //*collinear = CollinearIdx(lid1, lid2);
        if (pd.CollinearIdx(lid1, lid2))
            return false;
        
        // must be in the cycle!
        if (std::find(idx.begin(), idx.end(), lid1) == idx.end())
        {
            return false;
        }
        if (std::find(idx.begin(), idx.end(), lid2) == idx.end())
        {
            return false;
        }
        
        return true;
    }
    
    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r12
movq %rdi, %r14
leaq 0xc(%rsp), %rsi
movl %edx, (%rsi)
leaq 0xe0(%r12), %rdi
callq 0xb536
movq (%rax), %r13
movq 0x8(%rax), %rbx
movq %rbx, %rax
subq %r13, %rax
cmpq $0x5, %rax
jae 0x90bb
movb $0x1, %bpl
cmpl $0x0, 0x60(%r12)
je 0x9194
movl 0xc(%rsp), %esi
leaq 0x7d7d(%rip), %rdi      # 0x10e2c
xorl %eax, %eax
callq 0x2030
jmp 0x9194
xorl %ebp, %ebp
cmpq %rbx, %r13
je 0x9194
movq %r14, 0x10(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
movl $0x0, 0x8(%rsp)
movl (%r13), %esi
movq %r12, %rdi
movl $0x1, %edx
callq 0x5842
testq %rax, %rax
je 0x9112
incl %ebp
cmpl $0x0, 0x78(%rax)
je 0x9112
cmpl $0x1, %r14d
je 0x9108
testl %r14d, %r14d
jne 0x910f
movl 0x60(%rax), %r15d
jmp 0x910f
movl 0x60(%rax), %eax
movl %eax, 0x8(%rsp)
incl %r14d
addq $0x4, %r13
cmpq %rbx, %r13
jne 0x90d9
xorl $0x2, %ebp
xorl $0x2, %r14d
orl %ebp, %r14d
jne 0x9192
movq %r12, %rdi
movl %r15d, %esi
movl 0x8(%rsp), %r14d
movl %r14d, %edx
callq 0x8ff8
testb %al, %al
jne 0x9192
movq 0x10(%rsp), %rbx
movq 0x18(%rbx), %r12
addq $0x8, %rbx
cmpq %rbx, %r12
je 0x9192
movq %r12, %rax
xorl %ebp, %ebp
cmpl %r15d, 0x20(%rax)
je 0x916a
movq %rax, %rdi
callq 0x2180
cmpq %rbx, %rax
jne 0x9155
jmp 0x9194
cmpq %rbx, %rax
je 0x9192
cmpl %r14d, 0x20(%r12)
je 0x9189
movq %r12, %rdi
callq 0x2180
movq %rax, %r12
cmpq %rbx, %rax
jne 0x916f
movq %rbx, %r12
cmpq %rbx, %r12
setne %bpl
jmp 0x9194
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop