// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x1c(%rsp), %rsi
movl %edx, (%rsi)
leaq 0xe0(%r14), %rdi
callq 0x875e
movq (%rax), %r13
movq 0x8(%rax), %rbx
movq %rbx, %rax
subq %r13, %rax
cmpq $0x4, %rax
ja 0x7188
movb $0x1, %bl
cmpl $0x0, 0x60(%r14)
je 0x7255
movl 0x1c(%rsp), %esi
leaq 0x6c84(%rip), %rdi      # 0xde00
xorl %eax, %eax
callq 0x2040
jmp 0x7255
movq %r15, 0x20(%rsp)
andl $0x0, 0x18(%rsp)
andl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
pushq $0x1
popq %r12
movl $0x0, 0xc(%rsp)
xorl %ebp, %ebp
xorl %r15d, %r15d
cmpq %rbx, %r13
je 0x71fb
movl (%r13), %esi
movq %r14, %rdi
movl %r12d, %edx
callq 0x46ec
testq %rax, %rax
je 0x71f5
incl %r15d
cmpl $0x0, 0x78(%rax)
je 0x71f5
cmpl $0x1, %ebp
je 0x71e8
testl %ebp, %ebp
jne 0x71f3
movl 0x60(%rax), %eax
movl %eax, 0xc(%rsp)
movl %eax, 0x18(%rsp)
jmp 0x71f3
movl 0x60(%rax), %eax
movl %eax, 0x10(%rsp)
movl %eax, 0x14(%rsp)
incl %ebp
addq $0x4, %r13
jmp 0x71b0
xorl $0x2, %r15d
xorl $0x2, %ebp
orl %r15d, %ebp
jne 0x7253
movq %r14, %rdi
movl 0xc(%rsp), %esi
movl 0x10(%rsp), %edx
callq 0x70d8
testb %al, %al
jne 0x7253
movq 0x20(%rsp), %rbx
movq 0x18(%rbx), %rdi
leaq 0x8(%rbx), %r14
leaq 0x18(%rsp), %rdx
movq %r14, %rsi
callq 0x9712
cmpq %r14, %rax
je 0x7253
movq 0x18(%rbx), %rdi
leaq 0x14(%rsp), %rdx
movq %r14, %rsi
callq 0x9712
cmpq %r14, %rax
setne %bl
jmp 0x7255
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq