// File: /workspace/github_cpp_makefile_star2_O3/realuptime[P]PolyDetector/PolyDetector.cpp
// Function: PolyDetector::dissolveCollinear(PolyLine&, PolyLine&)
bool PolyDetector::dissolveCollinear(PolyLine &l1, PolyLine &l2)
{
    if (verbose)
        logoutf("Dissolving collinear neighbors %s and %s", l1.toString(*this).c_str(), l2.toString(*this).c_str());
    
    assert(&l1 != &l2);
    
    uint32_t *p1 = nullptr, *p2 = nullptr;
    if (l1.aIdx == l2.aIdx || l1.aIdx == l2.bIdx)
    {
        p1 = &l1.bIdx; // other point (B)
        p2 = l1.aIdx == l2.aIdx ? &l2.bIdx : &l2.aIdx; // aidx is common point. other point
    }
    else if (l1.bIdx == l2.aIdx || l1.bIdx == l2.bIdx)
    {
        p1 = &l1.aIdx; // other point (A)
        p2 = l1.bIdx == l2.aIdx ? &l2.bIdx : &l2.aIdx; // bidx is common point. other point
    }
    if (!p1 || !p2)
    {
        assert(p1 && p2);
        return false;
    }

#if 1
    auto search = findLine(*p1, *p2, false);
    if (search)
    {
        logoutf("A line %s origLine:#%u already exists with P%u P%u!", search->toString(*this).c_str(), search->origLine, *p1, *p2);
        //assert(false);
        
        l1.setIgnore(*this, "rmCollinear.l1 (dup)");
        l2.setIgnore(*this, "rmCollinear.l2 (dup)");
        
        return false;
    }
#endif

    PolyLine nl;
    nl.id = uint32_t(lines.size());
    nl.aIdx = *p1;
    nl.bIdx = *p2;
    nl.a = intersectionPoints[nl.aIdx];
    nl.b = intersectionPoints[nl.bIdx];
    nl.calcCenter(); // calls CalculateFirstAndLastPoint
    nl.origLine = l1.origLine; // will be used to construct collinearLineMap
    nl.lastDissolveStep = l1.lastDissolveStep;
    nl.attr0 = l1.attr0;
    
    // build point to lines link
    addPointToLine(nl.aIdx, nl.id);
    addPointToLine(nl.bIdx, nl.id);
    
    // build neighbors
    for (auto &id : {l1.id, l2.id})
    {
        for (auto &n : _neighbors[id])
        {
            if (n != l1.id && n != l2.id)
            {
                auto l = findLine(n);
                if (l)
                {
                    _neighbors[nl.id].push_back(n);
                    _neighbors[n].push_back(nl.id);
                }
            }
        }
    }
    
    // set proper collinearities
    for (auto &kv : collinearLineMap)
    {
        if (kv.first == l1.id || kv.first == l2.id)
        {
            for (auto &c : kv.second)
                setCollinear(nl.id, c);
        }
    }
    
    // after neigh built!
    if (verbose)
        logoutf("ignore line %u and line %u", l1.id, l2.id);
    l1.setIgnore(*this, "rmCollinear.l1");
    l2.setIgnore(*this, "rmCollinear.l2");
    
    //return false; // test
    
    lineIdToIdx[nl.id] = uint32_t(lines.size());
    lines.push_back(nl);
    lines.back().sortNeigh(*this);
    if (verbose)
        logoutf("added new line %s by merging %u and %u", lines.back().toString(*this).c_str(), l1.id, l2.id);
    
    // it can be removed
    //dissolveCollinearLine(lines.back());
    
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r15
cmpl $0x0, 0x60(%rdi)
je 0x864e
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4e48
movq (%r12), %r12
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x4e48
leaq 0x28(%rsp), %rbx
movq -0x10(%rbx), %rdx
leaq 0x861f(%rip), %rdi      # 0x10c42
movq %r12, %rsi
xorl %eax, %eax
callq 0x2030
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x863b
callq 0x2140
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x864e
callq 0x2140
cmpq %r13, %r14
je 0x8b60
movl $0x80, %ebp
movl 0x80(%r14), %ecx
movq %r13, %rbx
addq %rbp, %rbx
movl 0x80(%r13), %eax
cmpl %eax, %ecx
je 0x867f
movl 0x84(%r13), %esi
cmpl %esi, %ecx
jne 0x86a1
movl $0x84, %edx
leaq (%r14,%rdx), %rbp
addq %r13, %rdx
xorl %esi, %esi
cmpl %eax, %ecx
sete %sil
cmoveq %rdx, %rbx
movl 0x80(%r13,%rsi,4), %esi
jmp 0x86cf
movl 0x84(%r14), %ecx
cmpl %eax, %ecx
setne %dl
cmpl %esi, %ecx
setne %dil
testb %dil, %dl
jne 0x8b7f
addq %r14, %rbp
leaq 0x84(%r13), %rdx
cmpl %eax, %ecx
cmovnel %eax, %esi
cmoveq %rdx, %rbx
movl (%rbp), %eax
cmpl %eax, %esi
movl %eax, %edi
cmovbl %esi, %edi
movl %esi, %r8d
cmovbl %eax, %r8d
movq 0x30(%r15), %rdx
movq 0x38(%r15), %rcx
cmpq %rcx, %rdx
je 0x8728
movq %rdx, %r12
movl 0x80(%r12), %r10d
movl 0x84(%r12), %r9d
cmpl %r10d, %r9d
movl %r10d, %r11d
cmovbl %r9d, %r11d
cmovbl %r10d, %r9d
cmpl %edi, %r11d
jne 0x871c
cmpl %r8d, %r9d
je 0x87ed
addq $0x90, %r12
cmpq %rcx, %r12
jne 0x86f0
xorps %xmm0, %xmm0
leaq 0x68(%rsp), %r8
movups %xmm0, -0x20(%r8)
xorl %edi, %edi
movq %rdi, -0x10(%r8)
movl %edi, (%r8)
movq %rdi, 0x8(%r8)
movq %r8, 0x10(%r8)
movq %r8, 0x18(%r8)
movq %rdi, 0x20(%r8)
movaps 0x792b(%rip), %xmm1     # 0x10080
movups %xmm1, 0x34(%r8)
movb $0x0, 0x44(%r8)
movups %xmm0, 0x48(%r8)
movl %edi, 0x58(%r8)
subq %rdx, %rcx
shrq $0x4, %rcx
imull $0x38e38e39, %ecx, %edx # imm = 0x38E38E39
movl %edx, 0x30(%r8)
movl %eax, 0x50(%r8)
movl %esi, 0x54(%r8)
movq 0xc8(%r15), %rcx
movq (%rcx,%rax,8), %rdi
movq %rdi, -0x30(%r8)
movl %esi, %r9d
movq (%rcx,%r9,8), %rcx
movq %rcx, -0x28(%r8)
movd %edi, %xmm0
movq %rdi, %r8
shrq $0x20, %r8
movd %r8d, %xmm1
movd %ecx, %xmm4
movq %rcx, %r9
shrq $0x20, %r9
movd %r9d, %xmm5
ucomiss %xmm1, %xmm5
ja 0x87d8
ucomiss %xmm5, %xmm1
jne 0x8862
jp 0x8862
ucomiss %xmm0, %xmm4
jbe 0x8862
movdqa %xmm1, %xmm2
movdqa %xmm0, %xmm3
movl %eax, %esi
movaps %xmm5, %xmm1
movaps %xmm4, %xmm0
jmp 0x888b
movq %r13, 0x8(%rsp)
leaq 0x38(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x4e48
movq (%r13), %rsi
movl 0x6c(%r12), %edx
movl (%rbp), %ecx
movl (%rbx), %r8d
leaq 0x8497(%rip), %rdi      # 0x10cb2
xorl %eax, %eax
callq 0x2030
movq (%r13), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x8835
callq 0x2140
leaq 0x84ab(%rip), %rdx      # 0x10ce7
movq %r14, %rdi
movq %r15, %rsi
callq 0x8bd4
leaq 0x84ae(%rip), %rdx      # 0x10cfc
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x8bd4
xorl %eax, %eax
jmp 0x8b4e
movl %ecx, 0x38(%rsp)
movl %edi, 0x40(%rsp)
movl %r9d, 0x3c(%rsp)
movl %r8d, 0x44(%rsp)
movl %esi, 0xb8(%rsp)
movl %eax, 0xbc(%rsp)
movd %ecx, %xmm3
movd %r9d, %xmm2
addss %xmm1, %xmm2
addss %xmm0, %xmm3
movss 0x7801(%rip), %xmm0     # 0x1009c
mulss %xmm0, %xmm3
movss %xmm3, 0x90(%rsp)
mulss %xmm0, %xmm2
movss %xmm2, 0x94(%rsp)
movl 0x88(%r14), %eax
movl %eax, 0xc0(%rsp)
movq %r14, 0x8(%rsp)
movq 0x6c(%r14), %rax
movq %rax, 0xa4(%rsp)
movq %r15, %rdi
callq 0x5474
movl 0x98(%rsp), %edx
movl 0xbc(%rsp), %esi
movq %r15, %rdi
callq 0x5474
leaq 0x30(%r15), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
movl 0x60(%rax), %eax
movl %eax, 0x18(%rsp)
movq %r15, %rcx
movq %r13, %r15
movl 0x60(%r13), %eax
movl %eax, 0x1c(%rsp)
movq %rcx, %r14
leaq 0x68(%rcx), %rbp
xorl %r13d, %r13d
leaq (%rsp,%r13), %rsi
addq $0x18, %rsi
movq %rbp, %rdi
callq 0xb536
movq (%rax), %r12
movq 0x8(%rax), %rbx
cmpq %rbx, %r12
je 0x89df
movl (%r12), %esi
movq 0x8(%rsp), %rax
cmpl 0x60(%rax), %esi
je 0x89d6
cmpl 0x60(%r15), %esi
je 0x89d6
movq %r14, %rdi
movl $0x1, %edx
callq 0x5842
testq %rax, %rax
je 0x89d6
movq %rbp, %rdi
leaq 0x98(%rsp), %rsi
callq 0xb536
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x8993
movl (%r12), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x899e
movq %rax, %rdi
movq %r12, %rdx
callq 0xcab4
movq %rbp, %rdi
movq %r12, %rsi
callq 0xb536
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x89c6
movl 0x98(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x89d6
movq %rax, %rdi
leaq 0x98(%rsp), %rdx
callq 0xcab4
addq $0x4, %r12
jmp 0x8936
addq $0x4, %r13
cmpq $0x8, %r13
jne 0x891f
movq 0xb0(%r14), %r12
leaq 0xa0(%r14), %rbx
cmpq %rbx, %r12
je 0x8a4f
movl 0x20(%r12), %eax
movq 0x8(%rsp), %rcx
cmpl 0x60(%rcx), %eax
je 0x8a27
cmpl 0x60(%r15), %eax
je 0x8a27
movq %r12, %rdi
callq 0x20f0
movq %rax, %r12
cmpq %rbx, %rax
jne 0x8a00
jmp 0x8a4f
movq 0x28(%r12), %r13
movq 0x30(%r12), %rbp
cmpq %rbp, %r13
je 0x8a15
movl 0x98(%rsp), %esi
movl (%r13), %edx
movq %r14, %rdi
callq 0x8168
addq $0x4, %r13
jmp 0x8a31
cmpl $0x0, 0x60(%r14)
movq 0x8(%rsp), %rbx
je 0x8a70
movl 0x60(%rbx), %esi
movl 0x60(%r15), %edx
leaq 0x82a8(%rip), %rdi      # 0x10d11
xorl %eax, %eax
callq 0x2030
leaq 0x82b6(%rip), %rdx      # 0x10d2d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8bd4
leaq 0x82b3(%rip), %rdx      # 0x10d3c
movq %r15, %rdi
movq %r14, %rsi
callq 0x8bd4
movq 0x30(%r14), %r12
movq 0x38(%r14), %rbx
leaq 0x110(%r14), %rdi
leaq 0x98(%rsp), %rsi
callq 0xeacc
subq %r12, %rbx
shrq $0x4, %rbx
imull $0x38e38e39, %ebx, %ecx # imm = 0x38E38E39
movl %ecx, (%rax)
leaq 0x38(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0xb59c
movq $-0x90, %rdi
addq 0x38(%r14), %rdi
movq %r14, %rsi
callq 0x80c2
cmpl $0x0, 0x60(%r14)
je 0x8b31
movq $-0x90, %rsi
addq 0x38(%r14), %rsi
leaq 0x18(%rsp), %rdi
movq %r14, %rdx
callq 0x4e48
leaq 0x28(%rsp), %rbx
movq -0x10(%rbx), %rsi
movq 0x8(%rsp), %rax
movl 0x60(%rax), %edx
movl 0x60(%r15), %ecx
leaq 0x822f(%rip), %rdi      # 0x10d4b
xorl %eax, %eax
callq 0x2030
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x8b31
callq 0x2140
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
callq 0xc2b6
movq -0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x8b4c
callq 0x2140
movb $0x1, %al
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7a71(%rip), %rdi      # 0x105d8
leaq 0x75d2(%rip), %rsi      # 0x10140
leaq 0x80f7(%rip), %rcx      # 0x10c6c
movl $0x956, %edx            # imm = 0x956
callq 0x20e0
leaq 0x8123(%rip), %rdi      # 0x10ca9
leaq 0x75b3(%rip), %rsi      # 0x10140
leaq 0x80d8(%rip), %rcx      # 0x10c6c
movl $0x965, %edx            # imm = 0x965
callq 0x20e0
jmp 0x8bbe
movq %rax, %rbx
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8bcb
callq 0x2140
jmp 0x8bcb
jmp 0x8bbe
jmp 0x8bbe
jmp 0x8bbe
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xb518
movq %rbx, %rdi
callq 0x2200
nop