// File: /workspace/github_cpp_makefile_star2_O2/realuptime[P]PolyDetector/PolyDetector.cpp
// Function: PolyDetector::CreateLines()
bool PolyDetector::CreateLines()
{
    //logoutf("Line creation");
    
    uint32_t n = 0;
    for (auto &l : origLines)
    {
        l.id = n++;
    }
    
    // prior to removing overlapping, one must
    // remove all zero length line, otherwise the results
    // will be unpredictable
    RemoveZeroLengthLines();

    // then we must remove line overlapping
    RemoveOverlappings();

    // finally we detect intersections between lines
    int intersection_count = DetectAllIntersections();
    if (intersection_count == 0)
        return true;
    if (verbose)
    {
        logoutf("Detected %d intersections", intersection_count);
        logoutf("%u lines after intersection detection", uint32_t(origLines.size()));
    }

    // sweep all lines
    lines.clear();
    for (auto &line : origLines)
    {
        if (line.ignore) continue;
        
        // check if current line has intersections
        if (line.intersections.size() >= 2)
        {
            line.SortIntersectionsList(*this);
            if (verbose > 1)
                logoutf("line #%u nIntersections:%u", line.id, uint32_t(line.intersections.size()));
            
            for (uint32_t i = 1; i < line.intersections.size(); ++i)
            {
                bool foundDup = false;
                auto
                    aIdx = line.intersections[i - 1],
                    bIdx = line.intersections[i];
                
                assert(aIdx != bIdx);
                
                auto &p1 = intersectionPoints[aIdx];
                auto &p2 = intersectionPoints[bIdx];
                if (!pointsDiffer(p1, p2))
                {
                    logoutf("P%u P%u are the same for line #%u", aIdx, bIdx, line.id);
                    assert(pointsDiffer(p1, p2));
                }
                
                assert(p1.squaredist(line.a) <= p2.squaredist(line.a));

                for (auto &lDup : lines)
                {
                    if ((lDup.minPid() == std::min(aIdx, bIdx)) &&
                         lDup.maxPid() == std::max(aIdx, bIdx))
                    {
                        //if (verbose)
                            logoutf("WARN: Identical lines detected! procLine:%u [P%u P%u]. Means origLine:#%u and origLine:#%u are collinear!", lDup.id,
                                    lDup.minPid(), lDup.maxPid(), line.id, lDup.origLine);
                        //assert(false);
                        foundDup = true;
                    }
                }
                
                if (foundDup)
                {
                    if (verbose)
                        logoutf("WARN: line #%u has duplicate procLines! [P%u P%u]", line.id, aIdx, bIdx);
                }
                else if (!pointsDiffer(p1, p2))
                {
                    if (verbose)
                        logoutf("WARN: line #%u has zero length! [P%u P%u]", line.id, aIdx, bIdx);
                }
                else
                {
                    lines.push_back(newLine(i - 1, i, line));
                }
                
                if (verbose > 3)
                {
                    logoutf("[L#%u][%f %f, %f %f] -> %u [P%u P%u] [%f %f] [%f %f]",
                            line.id,
                            line.a.x, line.a.y, line.b.x, line.b.y,
                            i,
                            aIdx < bIdx ? aIdx : bIdx, aIdx < bIdx ? bIdx : aIdx,
                            p1.x, p1.y,
                            p2.x, p2.y);
                }
            }
        }
    }
    
#if 1
    for (uint32_t i = 0; i < lines.size(); i++)
    {
        auto &l1 = lines[i];
        
        //if (!pointsDiffer(l1.a, l1.b)) // find a zero length line
        //    logoutf("line %s points are the same!", l1.toString(*this).c_str());
        
        for (uint32_t j = i + 1; j < lines.size(); j++)
        {
            auto &l2 = lines[j];
            
            auto aIdx1 = l1.minPid();
            auto bIdx1 = l1.maxPid();
            
            auto aIdx2 = l2.minPid();
            auto bIdx2 = l2.maxPid();
            
            if (!l1.HasCommonIdxPoints(l2) && overlap(l1, l2))
            {
                logoutf("%u:%s and %u:%s overlap! olid:#%u olid:#%u", i, l1.toString(*this).c_str(), j, l2.toString(*this).c_str(), l1.origLine, l2.origLine);
            }
            
            if (aIdx1 == aIdx2 && bIdx1 == bIdx2)
            {
                logoutf("%u:%s and %u:%s have same points! [P%u P%u] olid1:#%u olid2:#%u", i, l1.toString(*this).c_str(), j, l2.toString(*this).c_str(), aIdx1, bIdx1, l1.origLine, l2.origLine);
                //assert(0);
                
                //dumpLines("commonPts");
            }
        }
    }
#endif
    
    if (verbose)
        logoutf("nOrigLines:%u nLines:%u", uint32_t(origLines.size()), uint32_t(lines.size()));

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdi, %r13
movq 0x18(%rdi), %rax
movq 0x20(%rdi), %rcx
xorl %edx, %edx
cmpq %rcx, %rax
je 0x28ba
movl %edx, 0x60(%rax)
incl %edx
addq $0x90, %rax
jmp 0x28a8
movq %r13, %rdi
callq 0x2f06
movq %r13, %rdi
callq 0x2f64
movq %r13, %rdi
callq 0x331c
testl %eax, %eax
je 0x2e6f
cmpl $0x0, 0x60(%r13)
je 0x2913
leaq 0xa7c1(%rip), %rdi      # 0xd0a9
movl %eax, %esi
xorl %eax, %eax
callq 0x2040
movq 0x20(%r13), %rax
subq 0x18(%r13), %rax
movl $0x90, %ecx
cqto
idivq %rcx
leaq 0xa7ba(%rip), %rdi      # 0xd0c4
movl %eax, %esi
xorl %eax, %eax
callq 0x2040
leaq 0x30(%r13), %rdi
movq %rdi, 0x30(%rsp)
callq 0x8750
movq 0x18(%r13), %r15
movq 0x20(%r13), %rax
movq %rax, 0x28(%rsp)
movq %r13, 0x10(%rsp)
cmpq 0x28(%rsp), %r15
je 0x2c61
cmpb $0x0, 0x74(%r15)
jne 0x2c55
movq 0x18(%r15), %rax
subq 0x10(%r15), %rax
cmpq $0x5, %rax
jb 0x2c55
movq %r15, %rdi
movq %r13, %rsi
callq 0x274c
cmpl $0x2, 0x60(%r13)
jb 0x298b
movl 0x60(%r15), %esi
movq 0x18(%r15), %rdx
subq 0x10(%r15), %rdx
shrq $0x2, %rdx
leaq 0xa767(%rip), %rdi      # 0xd0eb
xorl %eax, %eax
callq 0x2040
pushq $0x1
popq %rax
movl %eax, %r14d
movss 0xa6c7(%rip), %xmm0     # 0xd060
movl %r14d, %r14d
movq 0x10(%r15), %rax
movq 0x18(%r15), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r14, %rcx
jbe 0x2c55
leal -0x1(%r14), %ecx
movl (%rax,%rcx,4), %ebx
movl (%rax,%r14,4), %ebp
cmpl %ebp, %ebx
je 0x2e83
movq %rcx, 0x20(%rsp)
movq 0xc8(%r13), %r12
movaps %xmm0, %xmm6
movss (%r12,%rbx,8), %xmm0
movss 0x4(%r12,%rbx,8), %xmm1
movss (%r12,%rbp,8), %xmm3
movss 0x4(%r12,%rbp,8), %xmm2
movaps %xmm0, %xmm4
subss %xmm3, %xmm4
movaps %xmm1, %xmm5
subss %xmm2, %xmm5
mulss %xmm5, %xmm5
mulss %xmm4, %xmm4
addss %xmm5, %xmm4
ucomiss %xmm6, %xmm4
jae 0x2a66
movl 0x60(%r15), %ecx
leaq 0xa72c(%rip), %rdi      # 0xd146
movl %ebx, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x2040
movss (%r12,%rbx,8), %xmm0
movss 0x4(%r12,%rbx,8), %xmm1
movss (%r12,%rbp,8), %xmm3
movss 0x4(%r12,%rbp,8), %xmm2
movaps %xmm0, %xmm4
subss %xmm3, %xmm4
movaps %xmm1, %xmm5
subss %xmm2, %xmm5
mulss %xmm5, %xmm5
mulss %xmm4, %xmm4
addss %xmm5, %xmm4
ucomiss 0xa600(%rip), %xmm4     # 0xd060
jb 0x2ec1
unpcklps %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movss (%r15), %xmm2
movss 0x4(%r15), %xmm3
shufps $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
subps %xmm2, %xmm0
shufps $0x0, %xmm3, %xmm3      # xmm3 = xmm3[0,0,0,0]
subps %xmm3, %xmm1
mulps %xmm1, %xmm1
mulps %xmm0, %xmm0
addps %xmm1, %xmm0
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
ucomiss %xmm0, %xmm1
jb 0x2ea2
movq %r12, 0x18(%rsp)
movq %r14, (%rsp)
movq 0x30(%r13), %r14
movq 0x38(%r13), %r13
cmpl %ebx, %ebp
movl %ebx, %r12d
cmovbl %ebp, %r12d
movq %rbx, %rax
movl %ebp, %ebx
movq %rax, 0x8(%rsp)
cmovbl %eax, %ebx
xorl %eax, %eax
cmpq %r13, %r14
je 0x2b17
movl 0x80(%r14), %edx
movl 0x84(%r14), %ecx
cmpl %edx, %ecx
movl %edx, %esi
cmovbl %ecx, %esi
cmovbl %edx, %ecx
cmpl %r12d, %esi
jne 0x2b0e
cmpl %ebx, %ecx
jne 0x2b0e
movl 0x60(%r15), %r8d
movl 0x60(%r14), %esi
movl 0x6c(%r14), %r9d
leaq 0xa6ad(%rip), %rdi      # 0xd1ad
movl %r12d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2040
movb $0x1, %al
addq $0x90, %r14
jmp 0x2ac7
testb $0x1, %al
je 0x2b44
movq 0x10(%rsp), %r13
cmpl $0x0, 0x60(%r13)
movss 0xa533(%rip), %xmm0     # 0xd060
movq (%rsp), %r14
je 0x2c4d
movl 0x60(%r15), %esi
leaq 0xa6d6(%rip), %rdi      # 0xd218
jmp 0x2b9f
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
movss (%rcx,%rax,8), %xmm0
subss (%rcx,%rbp,8), %xmm0
movss 0x4(%rcx,%rax,8), %xmm1
subss 0x4(%rcx,%rbp,8), %xmm1
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
movss 0xa4e8(%rip), %xmm1     # 0xd060
ucomiss %xmm1, %xmm0
movq 0x10(%rsp), %r13
jae 0x2baf
movaps %xmm1, %xmm0
cmpl $0x0, 0x60(%r13)
movq (%rsp), %r14
je 0x2c4d
movl 0x60(%r15), %esi
leaq 0xa6ac(%rip), %rdi      # 0xd24b
movq 0x8(%rsp), %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2040
jmp 0x2be4
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq 0x20(%rsp), %rdx
movq (%rsp), %rcx
movq %r15, %r8
callq 0x27ec
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x97a4
movq %r14, %rdi
callq 0x8736
movq (%rsp), %r14
cmpl $0x4, 0x60(%r13)
movss 0xa46f(%rip), %xmm0     # 0xd060
jb 0x2c4d
movl 0x60(%r15), %esi
cvtss2sd (%r15), %xmm0
cvtss2sd 0x4(%r15), %xmm1
cvtss2sd 0x8(%r15), %xmm2
cvtss2sd 0xc(%r15), %xmm3
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
cvtss2sd (%rcx,%rax,8), %xmm4
cvtss2sd 0x4(%rcx,%rax,8), %xmm5
cvtss2sd (%rcx,%rbp,8), %xmm6
cvtss2sd 0x4(%rcx,%rbp,8), %xmm7
leaq 0xa641(%rip), %rdi      # 0xd276
movl %r14d, %edx
movl %r12d, %ecx
movl %ebx, %r8d
movb $0x8, %al
callq 0x2040
movss 0xa413(%rip), %xmm0     # 0xd060
incl %r14d
jmp 0x2999
addq $0x90, %r15
jmp 0x2933
movq 0x30(%r13), %rsi
movq 0x38(%r13), %rdi
xorl %eax, %eax
movl %eax, %r8d
movq %rdi, %rax
subq %rsi, %rax
cqto
movl $0x90, %ecx
idivq %rcx
cmpq %r8, %rax
jbe 0x2e41
imulq $0x90, %r8, %rbx
addq %rsi, %rbx
movq %r8, 0x18(%rsp)
leal 0x1(%r8), %eax
movl %eax, 0x20(%rsp)
movl %eax, %r12d
movl %r12d, %r12d
movq %rdi, %rax
subq %rsi, %rax
cqto
movl $0x90, %ecx
idivq %rcx
cmpq %r12, %rax
jbe 0x2e38
imulq $0x90, %r12, %rax
leaq (%rsi,%rax), %r14
movl 0x80(%rbx), %ebp
movl 0x84(%rbx), %ecx
cmpl %ebp, %ecx
movl %ebp, %edx
cmovbl %ecx, %edx
movl %edx, 0x8(%rsp)
cmovael %ecx, %ebp
movl 0x80(%rsi,%rax), %ecx
movl 0x84(%rsi,%rax), %r15d
cmpl %ecx, %r15d
movl %ecx, %r13d
cmovbl %r15d, %r13d
cmovbl %ecx, %r15d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x271a
testb %al, %al
jne 0x2d92
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4184
testb %al, %al
je 0x2d92
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
callq 0x4208
movq 0x58(%rsp), %rax
movq %rax, (%rsp)
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
callq 0x4208
movq 0x38(%rsp), %r8
movl 0x6c(%rbx), %r9d
movl 0x6c(%r14), %r10d
subq $0x8, %rsp
leaq 0xa546(%rip), %rdi      # 0xd2ac
movq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdx
movl %r12d, %ecx
xorl %eax, %eax
pushq %r10
callq 0x2040
popq %rcx
popq %rdx
leaq 0x38(%rsp), %rdi
callq 0x20b0
leaq 0x58(%rsp), %rdi
callq 0x20b0
movq %r14, (%rsp)
cmpl %r13d, 0x8(%rsp)
movq 0x10(%rsp), %r13
jne 0x2e28
cmpl %r15d, %ebp
jne 0x2e28
movq %rbx, %rsi
movq %r13, %r14
leaq 0x58(%rsp), %rdi
movq %r13, %rdx
callq 0x4208
movq 0x58(%rsp), %r15
leaq 0x38(%rsp), %rdi
movq (%rsp), %r13
movq %r13, %rsi
movq %r14, %rdx
callq 0x4208
movq 0x38(%rsp), %r8
movl 0x6c(%rbx), %r10d
movl 0x6c(%r13), %r11d
subq $0x8, %rsp
leaq 0xa4e9(%rip), %rdi      # 0xd2d8
movq 0x20(%rsp), %rsi
movq %r15, %rdx
movl %r12d, %ecx
movl 0x10(%rsp), %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %rbp
callq 0x2040
addq $0x20, %rsp
leaq 0x38(%rsp), %rdi
callq 0x20b0
leaq 0x58(%rsp), %rdi
callq 0x20b0
movq 0x10(%rsp), %r13
incl %r12d
movq 0x30(%r13), %rsi
movq 0x38(%r13), %rdi
jmp 0x2ca1
movl 0x20(%rsp), %eax
jmp 0x2c6b
cmpl $0x0, 0x60(%r13)
je 0x2e6f
movq %rax, %rcx
movq 0x20(%r13), %rax
subq 0x18(%r13), %rax
movl $0x90, %esi
cqto
idivq %rsi
leaq 0xa4b5(%rip), %rdi      # 0xd319
movl %eax, %esi
movl %ecx, %edx
xorl %eax, %eax
callq 0x2040
movb $0x1, %al
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa27d(%rip), %rdi      # 0xd107
leaq 0xa283(%rip), %rsi      # 0xd114
leaq 0xa28d(%rip), %rcx      # 0xd125
movl $0x1bb, %edx            # imm = 0x1BB
callq 0x20f0
leaq 0xa2d5(%rip), %rdi      # 0xd17e
leaq 0xa264(%rip), %rsi      # 0xd114
leaq 0xa26e(%rip), %rcx      # 0xd125
movl $0x1c5, %edx            # imm = 0x1C5
callq 0x20f0
leaq 0xa2a1(%rip), %rdi      # 0xd169
leaq 0xa245(%rip), %rsi      # 0xd114
leaq 0xa24f(%rip), %rcx      # 0xd125
movl $0x1c2, %edx            # imm = 0x1C2
callq 0x20f0
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x8736
jmp 0x2efe
jmp 0x2ef1
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2200