// File: 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:
subq $0xf8, %rsp
movq %rdi, 0xe8(%rsp)
movq %rsi, 0xe0(%rsp)
movl %edx, 0xdc(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x8(%rsp)
movb 0x74(%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x7556
jmp 0x7558
jmp 0x7577
leaq 0x1f1d6(%rip), %rdi     # 0x26735
leaq 0x1eb92(%rip), %rsi     # 0x260f8
movl $0x46a, %edx            # imm = 0x46A
leaq 0x1f1cb(%rip), %rcx     # 0x2673d
callq 0x2120
cmpl $0x2, 0xdc(%rsp)
jne 0x77ea
movq 0x8(%rsp), %rax
movl 0x80(%rax), %ecx
movl %ecx, 0xb8(%rsp)
movl 0x84(%rax), %eax
movl %eax, 0xbc(%rsp)
leaq 0xb8(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq $0x2, 0xc8(%rsp)
leaq 0xc0(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x13b00
movq %rax, 0xb0(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x13b10
movq %rax, 0xa8(%rsp)
movq 0xb0(%rsp), %rax
cmpq 0xa8(%rsp), %rax
je 0x77e8
movq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xe0(%rsp), %rdi
addq $0xe0, %rdi
movq 0xa0(%rsp), %rsi
callq 0x12dd0
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rdi
callq 0x12b80
cmpq $0x1, %rax
ja 0x7667
movl $0x1, 0xf4(%rsp)
jmp 0x78e5
movl $0x0, 0x94(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rdi
callq 0x128b0
movq %rax, 0x80(%rsp)
movq 0x88(%rsp), %rdi
callq 0x128e0
movq %rax, 0x78(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x134e0
testb $0x1, %al
jne 0x76c1
jmp 0x7730
leaq 0x80(%rsp), %rdi
callq 0x13520
movq %rax, 0x70(%rsp)
movq 0xe0(%rsp), %rdi
movq 0x70(%rsp), %rax
movl (%rax), %esi
movl $0x1, %edx
callq 0x7240
movq %rax, 0x68(%rsp)
cmpq $0x0, 0x68(%rsp)
je 0x771c
movq 0x8(%rsp), %rcx
movq 0x68(%rsp), %rax
movl 0x60(%rax), %eax
cmpl 0x60(%rcx), %eax
je 0x771c
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x771e
leaq 0x80(%rsp), %rdi
callq 0x13530
jmp 0x76a9
cmpl $0x0, 0x94(%rsp)
jne 0x77cd
movq 0xe0(%rsp), %rax
cmpl $0x0, 0x60(%rax)
je 0x77bd
movq 0x8(%rsp), %rsi
movq 0xe0(%rsp), %rdx
leaq 0x48(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x65a0
movq (%rsp), %rdi
callq 0x20b0
movq %rax, %rsi
movq 0xa0(%rsp), %rax
movl (%rax), %edx
movl 0x94(%rsp), %ecx
leaq 0x1eff5(%rip), %rdi     # 0x26780
xorl %eax, %eax
callq 0x2050
jmp 0x7794
leaq 0x48(%rsp), %rdi
callq 0x2100
jmp 0x77bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x2100
jmp 0x78f4
movl $0x1, 0xf4(%rsp)
jmp 0x78e5
jmp 0x77cf
movq 0xb0(%rsp), %rax
addq $0x4, %rax
movq %rax, 0xb0(%rsp)
jmp 0x75fa
jmp 0x77ea
cmpl $0x0, 0xdc(%rsp)
jne 0x78da
movq 0x8(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jb 0x78d8
movq 0x8(%rsp), %rsi
movq 0xe0(%rsp), %rdi
addq $0x68, %rdi
addq $0x60, %rsi
callq 0x12dd0
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
callq 0x128b0
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rdi
callq 0x128e0
movq %rax, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x134e0
testb $0x1, %al
jne 0x7859
jmp 0x78cb
leaq 0x28(%rsp), %rdi
callq 0x13520
movq %rax, 0x18(%rsp)
movq 0xe0(%rsp), %rdi
movq 0x18(%rsp), %rax
movl (%rax), %esi
movl $0x1, %edx
callq 0x7240
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x78ba
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movl 0x60(%rax), %eax
cmpl 0x60(%rcx), %eax
je 0x78ba
movq 0x10(%rsp), %rax
cmpl $0x0, 0x78(%rax)
jae 0x78b8
movl $0x0, 0xf4(%rsp)
jmp 0x78e5
jmp 0x78ba
jmp 0x78bc
leaq 0x28(%rsp), %rdi
callq 0x13530
jmp 0x7844
movl $0x1, 0xf4(%rsp)
jmp 0x78e5
jmp 0x78da
movl $0x0, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
addq $0xf8, %rsp
retq
movq 0x40(%rsp), %rdi
callq 0x2280
nop