// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rdi, %rbx
leaq 0xc(%rsp), %rsi
movl %edx, (%rsi)
leaq 0xe0(%r15), %rdi
callq 0xb3c8
movq (%rax), %r12
movq 0x8(%rax), %r13
movq %r13, %rax
subq %r12, %rax
cmpq $0x5, %rax
jae 0x900a
movb $0x1, %bl
cmpl $0x0, 0x60(%r15)
je 0x90e4
movl 0xc(%rsp), %esi
leaq 0x7e1e(%rip), %rdi      # 0x10e1c
xorl %eax, %eax
callq 0x2030
jmp 0x90e4
cmpq %r13, %r12
je 0x9078
movq %rbx, 0x10(%rsp)
xorl %ebp, %ebp
xorl %ebx, %ebx
xorl %r14d, %r14d
movl $0x0, 0x8(%rsp)
movl (%r12), %esi
movq %r15, %rdi
movl $0x1, %edx
callq 0x5706
testq %rax, %rax
je 0x9059
incl %ebp
cmpl $0x0, 0x78(%rax)
je 0x9059
cmpl $0x1, %ebx
je 0x9050
testl %ebx, %ebx
jne 0x9057
movl 0x60(%rax), %r14d
jmp 0x9057
movl 0x60(%rax), %eax
movl %eax, 0x8(%rsp)
incl %ebx
addq $0x4, %r12
cmpq %r13, %r12
jne 0x9023
xorl $0x2, %ebp
xorl $0x2, %ebx
orl %ebp, %ebx
sete %al
movq 0x10(%rsp), %rbx
movl 0x8(%rsp), %ebp
jmp 0x907f
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %eax, %eax
testb %al, %al
je 0x90e2
movq %r15, %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x8f3a
testb %al, %al
jne 0x90e2
movq 0x18(%rbx), %r15
addq $0x8, %rbx
movq %r15, %rax
cmpq %rbx, %r15
je 0x90ba
movq %r15, %rax
cmpl %r14d, 0x20(%rax)
je 0x90ba
movq %rax, %rdi
callq 0x2180
cmpq %rbx, %rax
jne 0x90a7
cmpq %rbx, %rax
je 0x90e2
cmpq %rbx, %r15
je 0x90da
cmpl %ebp, 0x20(%r15)
je 0x90da
movq %r15, %rdi
callq 0x2180
movq %rax, %r15
cmpq %rbx, %rax
jne 0x90c4
cmpq %rbx, %r15
setne %bl
jmp 0x90e4
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop