// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd8, %rsp
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r14
cmpl $0x0, 0x60(%rdi)
je 0x85c6
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4d08
movq (%r12), %r12
leaq 0xb8(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x4d08
leaq 0xc8(%rsp), %rbx
movq -0x10(%rbx), %rdx
leaq 0x8697(%rip), %rdi      # 0x10c32
movq %r12, %rsi
xorl %eax, %eax
callq 0x2030
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x85b3
callq 0x2140
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x85c6
callq 0x2140
cmpq %r13, %r15
je 0x8a95
movl $0x80, %eax
movl 0x80(%r15), %edx
leaq (%rax,%r13), %rbx
movl 0x80(%r13), %ecx
cmpl %ecx, %edx
je 0x85f5
movl 0x84(%r13), %esi
cmpl %esi, %edx
jne 0x8609
movl $0x84, %eax
leaq (%r15,%rax), %rbp
addq %r13, %rax
cmpl %ecx, %edx
cmoveq %rax, %rbx
jmp 0x8630
addq %r15, %rax
movl 0x84(%r15), %edx
xorl %ebp, %ebp
cmpl %esi, %edx
cmovneq %rbp, %rbx
leaq 0x84(%r13), %rsi
cmoveq %rax, %rbp
cmpl %ecx, %edx
cmoveq %rsi, %rbx
cmoveq %rax, %rbp
movq %r13, 0x8(%rsp)
testq %rbp, %rbp
je 0x8ab4
testq %rbx, %rbx
je 0x8ab4
movl (%rbp), %esi
movl (%rbx), %edx
movq %r14, %r12
movq %r14, %rdi
movq %rsi, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
xorl %ecx, %ecx
callq 0x6ed4
movq %rax, %r13
testq %rax, %rax
je 0x86d6
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4d08
movq (%r14), %rsi
movl 0x6c(%r13), %edx
movl (%rbp), %ecx
movl (%rbx), %r8d
leaq 0x8610(%rip), %rdi      # 0x10ca2
xorl %eax, %eax
callq 0x2030
movq (%r14), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x86ab
callq 0x2140
leaq 0x8625(%rip), %rdx      # 0x10cd7
movq %r15, %rdi
movq %r12, %rsi
callq 0x8b08
leaq 0x8628(%rip), %rdx      # 0x10cec
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x8b08
jmp 0x8a7d
movq %r13, 0x18(%rsp)
xorps %xmm0, %xmm0
leaq 0x58(%rsp), %rax
movups %xmm0, -0x20(%rax)
xorl %ecx, %ecx
movq %rcx, -0x10(%rax)
movl %ecx, (%rax)
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
movaps 0x790a(%rip), %xmm1     # 0x10010
movups %xmm1, 0x30(%rax)
movl $0xffffffff, 0x40(%rax) # imm = 0xFFFFFFFF
movb $0x0, 0x44(%rax)
movups %xmm0, 0x48(%rax)
movl %ecx, 0x58(%rax)
movq 0x38(%r12), %rcx
subq 0x30(%r12), %rcx
shrq $0x4, %rcx
imull $0x38e38e39, %ecx, %edx # imm = 0x38E38E39
movl %edx, 0x30(%rax)
movq 0x10(%rsp), %rdi
movl %edi, 0x50(%rax)
movq 0x20(%rsp), %r8
movl %r8d, 0x54(%rax)
movq 0xc8(%r12), %rcx
movq (%rcx,%rdi,8), %rsi
movq %rsi, -0x30(%rax)
movq (%rcx,%r8,8), %rcx
movq %rcx, -0x28(%rax)
movss -0x2c(%rax), %xmm0
movss -0x24(%rax), %xmm1
ucomiss %xmm0, %xmm1
ja 0x87b7
movq %rdi, %rax
movq %r8, %rcx
ucomiss %xmm1, %xmm0
jne 0x8785
jp 0x8785
movss 0x30(%rsp), %xmm2
ucomiss 0x28(%rsp), %xmm2
ja 0x87b7
movss 0x28(%rsp), %xmm2
movss 0x30(%rsp), %xmm3
movss %xmm3, 0x28(%rsp)
movss %xmm2, 0x30(%rsp)
movss %xmm1, 0x2c(%rsp)
movss %xmm0, 0x34(%rsp)
movl %ecx, 0xa8(%rsp)
movl %eax, 0xac(%rsp)
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
addps %xmm0, %xmm1
mulps 0x7853(%rip), %xmm1     # 0x10020
movlps %xmm1, 0x80(%rsp)
movq %r15, %r13
movl 0x88(%r15), %eax
movl %eax, 0xb0(%rsp)
movq 0x6c(%r15), %rax
movq %rax, 0x94(%rsp)
movl 0xa8(%rsp), %esi
movq %r14, %r12
movq %r14, %rdi
callq 0x533a
movq 0x8(%rsp), %rbx
movl 0x88(%rsp), %edx
movl 0xac(%rsp), %esi
movq %r12, %rdi
callq 0x533a
leaq 0x30(%r12), %rax
movq %rax, 0x10(%rsp)
movl 0x60(%r13), %eax
movl %eax, 0xb8(%rsp)
movl 0x60(%rbx), %eax
movl %eax, 0xbc(%rsp)
leaq 0x68(%r12), %r13
xorl %ebp, %ebp
leaq (%rsp,%rbp), %rsi
addq $0xb8, %rsi
movq %r13, %rdi
callq 0xb3c8
movq (%rax), %r12
movq 0x8(%rax), %rbx
cmpq %rbx, %r12
je 0x8908
movl (%r12), %esi
cmpl 0x60(%r15), %esi
je 0x88ff
movq 0x8(%rsp), %rax
cmpl 0x60(%rax), %esi
je 0x88ff
movq %r14, %rdi
movl $0x1, %edx
callq 0x5706
testq %rax, %rax
je 0x88ff
movq %r13, %rdi
leaq 0x88(%rsp), %rsi
callq 0xb3c8
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x88bc
movl (%r12), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x88c7
movq %rax, %rdi
movq %r12, %rdx
callq 0xc93e
movq %r13, %rdi
movq %r12, %rsi
callq 0xb3c8
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x88ef
movl 0x88(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x88ff
movq %rax, %rdi
leaq 0x88(%rsp), %rdx
callq 0xc93e
addq $0x4, %r12
jmp 0x885f
addq $0x4, %rbp
cmpq $0x8, %rbp
jne 0x8845
movq 0xb0(%r14), %r12
leaq 0xa0(%r14), %rbx
cmpq %rbx, %r12
je 0x8978
movl 0x20(%r12), %eax
cmpl 0x60(%r15), %eax
je 0x8950
movq 0x8(%rsp), %rcx
cmpl 0x60(%rcx), %eax
je 0x8950
movq %r12, %rdi
callq 0x20f0
movq %rax, %r12
cmpq %rbx, %rax
jne 0x8929
jmp 0x8978
movq 0x28(%r12), %r13
movq 0x30(%r12), %rbp
cmpq %rbp, %r13
je 0x893e
movl 0x88(%rsp), %esi
movl (%r13), %edx
movq %r14, %rdi
callq 0x8074
addq $0x4, %r13
jmp 0x895a
cmpl $0x0, 0x60(%r14)
movq 0x8(%rsp), %r13
je 0x899a
movl 0x60(%r15), %esi
movl 0x60(%r13), %edx
leaq 0x836e(%rip), %rdi      # 0x10d01
xorl %eax, %eax
callq 0x2030
leaq 0x837c(%rip), %rdx      # 0x10d1d
movq %r15, %rdi
movq %r14, %rsi
callq 0x8b08
leaq 0x8379(%rip), %rdx      # 0x10d2c
movq %r13, %rdi
movq %r14, %rsi
callq 0x8b08
movq 0x30(%r14), %r12
movq 0x38(%r14), %rbx
leaq 0x110(%r14), %rdi
leaq 0x88(%rsp), %rsi
callq 0xe85e
subq %r12, %rbx
shrq $0x4, %rbx
imull $0x38e38e39, %ebx, %ecx # imm = 0x38E38E39
movl %ecx, (%rax)
leaq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0xb42c
movq $-0x90, %rdi
addq 0x38(%r14), %rdi
movq %r14, %rsi
callq 0x7fce
cmpl $0x0, 0x60(%r14)
je 0x8a5d
movq $-0x90, %rsi
addq 0x38(%r14), %rsi
leaq 0xb8(%rsp), %rdi
movq %r14, %rdx
callq 0x4d08
leaq 0xc8(%rsp), %rbx
movq -0x10(%rbx), %rsi
movl 0x60(%r15), %edx
movl 0x60(%r13), %ecx
leaq 0x82f3(%rip), %rdi      # 0x10d3b
xorl %eax, %eax
callq 0x2030
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x8a5d
callq 0x2140
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0xc16e
movq -0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x8a78
callq 0x2140
movq 0x18(%rsp), %r13
testq %r13, %r13
sete %al
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7b2c(%rip), %rdi      # 0x105c8
leaq 0x768d(%rip), %rsi      # 0x10130
leaq 0x81b2(%rip), %rcx      # 0x10c5c
movl $0x956, %edx            # imm = 0x956
callq 0x20e0
leaq 0x81de(%rip), %rdi      # 0x10c99
leaq 0x766e(%rip), %rsi      # 0x10130
leaq 0x8193(%rip), %rcx      # 0x10c5c
movl $0x965, %edx            # imm = 0x965
callq 0x20e0
jmp 0x8af3
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8b00
callq 0x2140
jmp 0x8b00
jmp 0x8af3
jmp 0x8af3
jmp 0x8af3
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xb3aa
movq %rbx, %rdi
callq 0x2200