// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq 0x18(%rdi), %rcx
movq 0x20(%rdi), %rax
cmpq %rax, %rcx
je 0x2b9c
subq %rcx, %rax
addq $-0x90, %rax
movabsq $-0x1c71c71c71c71c71, %rdx # imm = 0xE38E38E38E38E38F
mulq %rdx
movq %rdx, %xmm0
shrq $0x7, %rdx
addq $0x4, %rdx
andq $-0x4, %rdx
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
psrlq $0x7, %xmm0
addq $0x210, %rcx            # imm = 0x210
xorl %eax, %eax
movdqa 0xd56f(%rip), %xmm1     # 0x10030
movdqa 0xd577(%rip), %xmm2     # 0x10040
movdqa 0xd57f(%rip), %xmm3     # 0x10050
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movq %rax, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
movdqa %xmm5, %xmm6
por %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0x2b22
movl %eax, -0x1b0(%rcx)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x2b3a
leal 0x1(%rax), %esi
movl %esi, -0x120(%rcx)
por %xmm1, %xmm5
pxor %xmm3, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
pxor %xmm4, %xmm5
pextrw $0x0, %xmm5, %esi
testb $0x1, %sil
je 0x2b78
leal 0x2(%rax), %esi
movl %esi, -0x90(%rcx)
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0x2b88
leal 0x3(%rax), %esi
movl %esi, (%rcx)
addq $0x4, %rax
addq $0x240, %rcx            # imm = 0x240
cmpq %rax, %rdx
jne 0x2ad9
movq %r15, %rdi
callq 0x32c0
movq %r15, %rdi
callq 0x332a
movq %r15, %rdi
callq 0x399a
testl %eax, %eax
je 0x320d
cmpl $0x0, 0x60(%r15)
je 0x2bf3
leaq 0xd4fb(%rip), %rdi      # 0x100c5
movl %eax, %esi
xorl %eax, %eax
callq 0x2030
movq 0x20(%r15), %rax
subq 0x18(%r15), %rax
shrq $0x4, %rax
imull $0x38e38e39, %eax, %esi # imm = 0x38E38E39
leaq 0xd4f4(%rip), %rdi      # 0x100e0
xorl %eax, %eax
callq 0x2030
leaq 0x30(%r15), %rdi
movq 0x30(%r15), %rsi
movq %rdi, 0x30(%rsp)
callq 0xc182
movq 0x18(%r15), %r13
movq 0x20(%r15), %rax
movq %rax, 0x28(%rsp)
cmpq %rax, %r13
movq %r15, 0x10(%rsp)
je 0x2f63
cmpb $0x0, 0x74(%r13)
jne 0x2f51
movq 0x18(%r13), %rax
subq 0x10(%r13), %rax
cmpq $0x5, %rax
jb 0x2f51
movq %r13, %rdi
movq %r15, %rsi
callq 0x28e0
cmpl $0x2, 0x60(%r15)
jb 0x2c6d
movl 0x60(%r13), %esi
movq 0x18(%r13), %rdx
subq 0x10(%r13), %rdx
shrq $0x2, %rdx
leaq 0xd4a1(%rip), %rdi      # 0x10107
xorl %eax, %eax
callq 0x2030
movq 0x10(%r13), %rax
movq 0x18(%r13), %rcx
subq %rax, %rcx
cmpq $0x5, %rcx
jb 0x2f51
movl $0x1, %r14d
movl $0x1, %ecx
leal -0x1(%r14), %r12d
movl (%rax,%r12,4), %ebx
movl (%rax,%rcx,4), %ecx
cmpl %ecx, %ebx
je 0x3221
movq 0xc8(%r15), %rbp
movss (%rbp,%rbx,8), %xmm0
subss (%rbp,%rcx,8), %xmm0
movss 0x4(%rbp,%rbx,8), %xmm1
subss 0x4(%rbp,%rcx,8), %xmm1
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
ucomiss 0xd3ae(%rip), %xmm0     # 0x10080
movq %rcx, (%rsp)
jae 0x2d25
movl 0x60(%r13), %ecx
leaq 0xd47f(%rip), %rdi      # 0x10162
movl %ebx, %esi
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x2030
movq (%rsp), %rcx
movss (%rbp,%rbx,8), %xmm0
subss (%rbp,%rcx,8), %xmm0
movss 0x4(%rbp,%rbx,8), %xmm1
subss 0x4(%rbp,%rcx,8), %xmm1
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
ucomiss 0xd361(%rip), %xmm0     # 0x10080
jb 0x325f
movq %r12, 0x20(%rsp)
movss (%rbp,%rcx,8), %xmm0
movss 0x4(%rbp,%rcx,8), %xmm1
movss (%rbp,%rbx,8), %xmm2
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
movq %rbx, 0x8(%rsp)
movss 0x4(%rbp,%rbx,8), %xmm0
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movss (%r13), %xmm1
movss 0x4(%r13), %xmm3
shufps $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
subps %xmm1, %xmm2
shufps $0x0, %xmm3, %xmm3      # xmm3 = xmm3[0,0,0,0]
subps %xmm3, %xmm0
mulps %xmm0, %xmm0
mulps %xmm2, %xmm2
addps %xmm0, %xmm2
movaps %xmm2, %xmm0
shufps $0x55, %xmm2, %xmm0     # xmm0 = xmm0[1,1],xmm2[1,1]
ucomiss %xmm2, %xmm0
jb 0x3240
movq 0x30(%r15), %rbx
movq 0x38(%r15), %r12
cmpq %r12, %rbx
je 0x2e2b
movq %r14, 0x18(%rsp)
movq %r13, %r14
movq 0x8(%rsp), %rax
cmpl %eax, %ecx
movl %eax, %r15d
cmovbl %ecx, %r15d
movl %ecx, %r13d
cmovbl %eax, %r13d
xorl %eax, %eax
movl 0x80(%rbx), %esi
movl 0x84(%rbx), %ecx
cmpl %esi, %ecx
movl %esi, %edx
cmovbl %ecx, %edx
cmpl %r15d, %edx
jne 0x2ded
cmpl %ecx, %esi
cmoval %esi, %ecx
cmpl %r13d, %ecx
jne 0x2ded
movl 0x60(%r14), %r8d
movl 0x60(%rbx), %esi
movl 0x6c(%rbx), %r9d
leaq 0xd3e5(%rip), %rdi      # 0x101c9
xorl %eax, %eax
callq 0x2030
movb $0x1, %al
addq $0x90, %rbx
cmpq %r12, %rbx
jne 0x2db0
testb $0x1, %al
movq 0x10(%rsp), %r15
movq %r14, %r13
movq 0x18(%rsp), %r14
movq (%rsp), %rcx
je 0x2e2b
cmpl $0x0, 0x60(%r15)
movq 0x8(%rsp), %r12
je 0x2ec5
movl 0x60(%r13), %esi
leaq 0xd40b(%rip), %rdi      # 0x10234
jmp 0x2e71
movq 0x8(%rsp), %r12
movss (%rbp,%r12,8), %xmm0
subss (%rbp,%rcx,8), %xmm0
movss 0x4(%rbp,%r12,8), %xmm1
subss 0x4(%rbp,%rcx,8), %xmm1
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
ucomiss 0xd223(%rip), %xmm0     # 0x10080
jae 0x2e81
cmpl $0x0, 0x60(%r15)
je 0x2ec5
movl 0x60(%r13), %esi
leaq 0xd3f6(%rip), %rdi      # 0x10267
movl %r12d, %edx
movq (%rsp), %rcx
xorl %eax, %eax
callq 0x2030
jmp 0x2ec5
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
movl %r14d, %ecx
movq %r13, %r8
callq 0x2980
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0xc1ec
leaq 0x80(%rsp), %rdi
callq 0xc16e
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x2ec5
callq 0x2140
cmpl $0x4, 0x60(%r15)
jb 0x2f33
movl 0x60(%r13), %esi
xorps %xmm0, %xmm0
cvtss2sd (%r13), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%r13), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%r13), %xmm2
xorps %xmm3, %xmm3
cvtss2sd 0xc(%r13), %xmm3
movq (%rsp), %rax
cmpl %eax, %r12d
movl %eax, %ecx
cmovbl %r12d, %ecx
movl %eax, %r8d
cmoval %r12d, %r8d
cvtss2sd (%rbp,%r12,8), %xmm4
cvtss2sd 0x4(%rbp,%r12,8), %xmm5
cvtss2sd (%rbp,%rax,8), %xmm6
cvtss2sd 0x4(%rbp,%rax,8), %xmm7
leaq 0xd369(%rip), %rdi      # 0x10292
movl %r14d, %edx
movb $0x8, %al
callq 0x2030
incl %r14d
movq 0x10(%r13), %rax
movq 0x18(%r13), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
movq %r14, %rcx
cmpq %r14, %rdx
ja 0x2c8d
addq $0x90, %r13
cmpq 0x28(%rsp), %r13
jne 0x2c20
movq 0x30(%r15), %rsi
movq 0x38(%r15), %rdx
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
subq %rsi, %rdx
je 0x31de
xorl %ecx, %ecx
xorl %eax, %eax
movq %rax, 0x20(%rsp)
leal 0x1(%rax), %edi
movq 0x30(%r15), %rax
movq 0x38(%r15), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r8, %rdx
movq %rdi, 0x18(%rsp)
cmpq %rdi, %rdx
jbe 0x31b9
leaq (%rcx,%rcx,8), %rcx
shlq $0x4, %rcx
addq %rcx, %rsi
movq 0x18(%rsp), %r13
movq %r13, %rcx
movq %rsi, (%rsp)
leaq (%rcx,%rcx,8), %rdi
shlq $0x4, %rdi
leaq (%rax,%rdi), %r12
movl 0x80(%rsi), %r9d
movl 0x84(%rsi), %ecx
cmpl %r9d, %ecx
movl %r9d, %r15d
cmovbl %ecx, %r15d
movl %ecx, %ebx
cmovbl %r9d, %ebx
movl 0x80(%rax,%rdi), %edx
movl 0x84(%rax,%rdi), %eax
cmpl %edx, %eax
movl %edx, %r14d
cmovbl %eax, %r14d
movl %eax, %ebp
cmovbl %edx, %ebp
cmpl %edx, %r9d
je 0x30e2
cmpl %eax, %r9d
je 0x30e2
cmpl %eax, %ecx
je 0x30e2
cmpl %edx, %ecx
je 0x30e2
movq %rsi, %rdi
movq %r12, %rsi
callq 0x4c39
movq (%rsp), %rsi
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
testb %al, %al
je 0x30e2
leaq 0x58(%rsp), %rdi
movq 0x10(%rsp), %rdx
callq 0x4d08
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x38(%rsp), %rdi
movq %r12, %rsi
movq 0x10(%rsp), %rdx
callq 0x4d08
movq 0x38(%rsp), %r8
movq (%rsp), %rax
movl 0x6c(%rax), %r9d
movl 0x6c(%r12), %r10d
subq $0x8, %rsp
leaq 0xd236(%rip), %rdi      # 0x102c8
movq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl %r13d, %ecx
xorl %eax, %eax
pushq %r10
callq 0x2030
addq $0x10, %rsp
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x30c0
callq 0x2140
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x30d4
callq 0x2140
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
movq (%rsp), %rsi
cmpl %r14d, %r15d
jne 0x3192
cmpl %ebp, %ebx
jne 0x3192
movq %rbx, 0x8(%rsp)
leaq 0x58(%rsp), %rdi
movq 0x10(%rsp), %r14
movq %r14, %rdx
movq %rsi, %rbx
callq 0x4d08
movq 0x58(%rsp), %rbp
leaq 0x38(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x4d08
movq 0x38(%rsp), %r8
movl 0x6c(%rbx), %r10d
movl 0x6c(%r12), %r11d
subq $0x8, %rsp
leaq 0xd1b9(%rip), %rdi      # 0x102f4
movq 0x28(%rsp), %rsi
movq %rbp, %rdx
movl %r13d, %ecx
movl %r15d, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
pushq 0x20(%rsp)
callq 0x2030
addq $0x20, %rsp
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x3170
callq 0x2140
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x3184
callq 0x2140
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
movq (%rsp), %rsi
incl %r13d
movq 0x10(%rsp), %r15
movq 0x30(%r15), %rax
movq 0x38(%r15), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r8, %rdx
movq %r13, %rcx
cmpq %r13, %rdx
ja 0x2fc2
movq 0x18(%rsp), %rax
movl %eax, %ecx
movq 0x30(%r15), %rsi
movq 0x38(%r15), %rdx
subq %rsi, %rdx
sarq $0x4, %rdx
imulq %r8, %rdx
cmpq %rcx, %rdx
ja 0x2f82
jmp 0x31e6
sarq $0x4, %rdx
imulq %r8, %rdx
cmpl $0x0, 0x60(%r15)
je 0x320d
movq 0x20(%r15), %rax
subq 0x18(%r15), %rax
shrq $0x4, %rax
imull $0x38e38e39, %eax, %esi # imm = 0x38E38E39
leaq 0xd12f(%rip), %rdi      # 0x10335
xorl %eax, %eax
callq 0x2030
movb $0x1, %al
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xcefb(%rip), %rdi      # 0x10123
leaq 0xcf01(%rip), %rsi      # 0x10130
leaq 0xcf0b(%rip), %rcx      # 0x10141
movl $0x1bb, %edx            # imm = 0x1BB
callq 0x20e0
leaq 0xcf53(%rip), %rdi      # 0x1019a
leaq 0xcee2(%rip), %rsi      # 0x10130
leaq 0xceec(%rip), %rcx      # 0x10141
movl $0x1c5, %edx            # imm = 0x1C5
callq 0x20e0
leaq 0xcf1f(%rip), %rdi      # 0x10185
leaq 0xcec3(%rip), %rsi      # 0x10130
leaq 0xcecd(%rip), %rcx      # 0x10141
movl $0x1c2, %edx            # imm = 0x1C2
callq 0x20e0
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0xb3aa
jmp 0x32b8
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x32b8
jmp 0x32b3
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x32b8
callq 0x2140
movq %rbx, %rdi
callq 0x2200