// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq 0x18(%rdi), %rcx
movq 0x20(%rdi), %rax
cmpq %rax, %rcx
je 0x2be2
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 0xd529(%rip), %xmm1     # 0x10030
movdqa 0xd531(%rip), %xmm2     # 0x10040
movdqa 0xd539(%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 0x2b68
movl %eax, -0x1b0(%rcx)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x2b80
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 0x2bbe
leal 0x2(%rax), %esi
movl %esi, -0x90(%rcx)
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0x2bce
leal 0x3(%rax), %esi
movl %esi, (%rcx)
addq $0x4, %rax
addq $0x240, %rcx            # imm = 0x240
cmpq %rax, %rdx
jne 0x2b1f
movq %rbx, %rdi
callq 0x335c
movq %rbx, %rdi
callq 0x33cc
movq %rbx, %rdi
callq 0x39f0
testl %eax, %eax
je 0x32a8
cmpl $0x0, 0x60(%rbx)
je 0x2c38
leaq 0xd4c6(%rip), %rdi      # 0x100d5
movl %eax, %esi
xorl %eax, %eax
callq 0x2030
movq 0x20(%rbx), %rax
subq 0x18(%rbx), %rax
shrq $0x4, %rax
imull $0x38e38e39, %eax, %esi # imm = 0x38E38E39
leaq 0xd4bf(%rip), %rdi      # 0x100f0
xorl %eax, %eax
callq 0x2030
leaq 0x30(%rbx), %rdi
movq 0x30(%rbx), %rsi
movq %rdi, 0x28(%rsp)
callq 0xc2ca
movq 0x18(%rbx), %r14
movq 0x20(%rbx), %rax
movq %rax, 0x30(%rsp)
cmpq %rax, %r14
movq %rbx, 0x10(%rsp)
je 0x300b
cmpb $0x0, 0x74(%r14)
jne 0x2ff9
movq 0x18(%r14), %rax
subq 0x10(%r14), %rax
cmpq $0x5, %rax
jb 0x2ff9
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2926
cmpl $0x2, 0x60(%rbx)
jb 0x2cb1
movl 0x60(%r14), %esi
movq 0x18(%r14), %rdx
subq 0x10(%r14), %rdx
shrq $0x2, %rdx
leaq 0xd46d(%rip), %rdi      # 0x10117
xorl %eax, %eax
callq 0x2030
movq 0x10(%r14), %rax
movq 0x18(%r14), %rcx
subq %rax, %rcx
cmpq $0x5, %rcx
movss 0xd3c8(%rip), %xmm6     # 0x10090
jb 0x2ff9
movl $0x1, %ebp
movl $0x1, %ecx
movq %r14, 0x18(%rsp)
leal -0x1(%rbp), %edx
movq %rdx, 0x20(%rsp)
movl (%rax,%rdx,4), %r12d
movl (%rax,%rcx,4), %r13d
cmpl %r13d, %r12d
je 0x32bc
movq 0xc8(%rbx), %r15
movss (%r15,%r12,8), %xmm0
movss 0x4(%r15,%r12,8), %xmm1
movss (%r15,%r13,8), %xmm3
movss 0x4(%r15,%r13,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 0x2d93
movl 0x60(%r14), %ecx
leaq 0xd431(%rip), %rdi      # 0x10172
movl %r12d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x2030
movss 0xd33a(%rip), %xmm6     # 0x10090
movss (%r15,%r12,8), %xmm0
movss 0x4(%r15,%r12,8), %xmm1
movss (%r15,%r13,8), %xmm3
movss 0x4(%r15,%r13,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
jb 0x32fa
unpcklps %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movq %r15, (%rsp)
movq %rbp, 0x8(%rsp)
movss (%r14), %xmm2
movss 0x4(%r14), %xmm3
shufps $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
movaps %xmm0, %xmm4
subps %xmm2, %xmm4
shufps $0x0, %xmm3, %xmm3      # xmm3 = xmm3[0,0,0,0]
movaps %xmm1, %xmm2
subps %xmm3, %xmm2
mulps %xmm2, %xmm2
mulps %xmm4, %xmm4
addps %xmm2, %xmm4
movaps %xmm4, %xmm2
shufps $0x55, %xmm4, %xmm2     # xmm2 = xmm2[1,1],xmm4[1,1]
ucomiss %xmm4, %xmm2
jb 0x32db
movq 0x30(%rbx), %r15
movq 0x38(%rbx), %rbp
cmpq %rbp, %r15
je 0x2e94
cmpl %r12d, %r13d
movl %r12d, %r14d
cmovbl %r13d, %r14d
movl %r13d, %ebx
cmovbl %r12d, %ebx
xorl %eax, %eax
addq $0x90, %r15
movl -0x10(%r15), %edx
movl -0xc(%r15), %ecx
cmpl %edx, %ecx
movl %edx, %esi
cmovbl %ecx, %esi
cmovbl %edx, %ecx
cmpl %r14d, %esi
jne 0x2e20
cmpl %ebx, %ecx
je 0x2e31
leaq 0x90(%r15), %rcx
cmpq %rbp, %r15
movq %rcx, %r15
jne 0x2e05
jmp 0x2e66
movq 0x18(%rsp), %rax
movl 0x60(%rax), %r8d
movl -0x30(%r15), %esi
movl -0x24(%r15), %r9d
leaq 0xd390(%rip), %rdi      # 0x101d9
movl %r14d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2030
movss 0xd233(%rip), %xmm6     # 0x10090
movb $0x1, %al
cmpq %rbp, %r15
jne 0x2dfe
jmp 0x2e6a
testb $0x1, %al
je 0x2ead
movq 0x10(%rsp), %rbx
cmpl $0x0, 0x60(%rbx)
movq 0x18(%rsp), %r14
movq 0x8(%rsp), %rbp
movq (%rsp), %r15
je 0x2fdc
movl 0x60(%r14), %esi
leaq 0xd3b2(%rip), %rdi      # 0x10244
jmp 0x2f08
movaps %xmm0, %xmm2
shufps $0x55, %xmm0, %xmm2     # xmm2 = xmm2[1,1],xmm0[1,1]
movaps %xmm1, %xmm3
shufps $0x55, %xmm1, %xmm3     # xmm3 = xmm3[1,1],xmm1[1,1]
movq 0x8(%rsp), %rbp
movq (%rsp), %r15
jmp 0x2eda
movq (%rsp), %r15
movss (%r15,%r12,8), %xmm0
movss 0x4(%r15,%r12,8), %xmm1
movss (%r15,%r13,8), %xmm2
movss 0x4(%r15,%r13,8), %xmm3
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
movq 0x8(%rsp), %rbp
subss %xmm3, %xmm1
subss %xmm2, %xmm0
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
ucomiss %xmm6, %xmm0
jae 0x2f17
cmpl $0x0, 0x60(%rbx)
je 0x2fdc
movl 0x60(%r14), %esi
leaq 0xd36f(%rip), %rdi      # 0x10277
movl %r12d, %edx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2030
jmp 0x2f5e
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq 0x20(%rsp), %rdx
movl %ebp, %ecx
movq %r14, %r8
callq 0x29c6
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0xc334
leaq 0x80(%rsp), %rdi
callq 0xc2b6
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x2f5a
callq 0x2140
movq (%rsp), %r15
cmpl $0x4, 0x60(%rbx)
movss 0xd126(%rip), %xmm6     # 0x10090
jb 0x2fdc
movl 0x60(%r14), %esi
xorps %xmm0, %xmm0
cvtss2sd (%r14), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%r14), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%r14), %xmm2
xorps %xmm3, %xmm3
cvtss2sd 0xc(%r14), %xmm3
cmpl %r13d, %r12d
movl %r13d, %ecx
cmovbl %r12d, %ecx
movl %r13d, %r8d
cmoval %r12d, %r8d
xorps %xmm4, %xmm4
cvtss2sd (%r15,%r12,8), %xmm4
cvtss2sd 0x4(%r15,%r12,8), %xmm5
xorps %xmm6, %xmm6
cvtss2sd (%r15,%r13,8), %xmm6
cvtss2sd 0x4(%r15,%r13,8), %xmm7
leaq 0xd2d7(%rip), %rdi      # 0x102a2
movl %ebp, %edx
movb $0x8, %al
callq 0x2030
movss 0xd0b4(%rip), %xmm6     # 0x10090
incl %ebp
movq 0x10(%r14), %rax
movq 0x18(%r14), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
movq %rbp, %rcx
cmpq %rbp, %rdx
ja 0x2cdd
addq $0x90, %r14
cmpq 0x30(%rsp), %r14
jne 0x2c65
movq 0x30(%rbx), %rax
movq 0x38(%rbx), %rcx
movq %rcx, %rdx
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
subq %rax, %rdx
je 0x327a
xorl %esi, %esi
xorl %edi, %edi
movl %edi, %edx
movq %rdx, 0x20(%rsp)
leal 0x1(%rdx), %r9d
movl %r9d, %edi
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r8, %rdx
cmpq %rdi, %rdx
movq %rdi, 0x18(%rsp)
movl %r9d, 0x28(%rsp)
jbe 0x3266
leaq (%rsi,%rsi,8), %rsi
shlq $0x4, %rsi
addq %rax, %rsi
movl %r9d, %r12d
movq %rsi, (%rsp)
leaq (%rdi,%rdi,8), %rdi
shlq $0x4, %rdi
leaq (%rax,%rdi), %r15
movl 0x80(%rsi), %r9d
movl 0x84(%rsi), %ecx
cmpl %r9d, %ecx
movl %r9d, %r14d
cmovbl %ecx, %r14d
movl %ecx, %ebp
cmovbl %r9d, %ebp
movl 0x80(%rax,%rdi), %edx
movl 0x84(%rax,%rdi), %eax
cmpl %edx, %eax
movl %edx, %r13d
cmovbl %eax, %r13d
movl %eax, %ebx
cmovbl %edx, %ebx
cmpl %edx, %r9d
je 0x318d
cmpl %eax, %r9d
je 0x318d
cmpl %eax, %ecx
je 0x318d
cmpl %edx, %ecx
je 0x318d
movq %rsi, %rdi
movq %r15, %rsi
callq 0x4cda
movq (%rsp), %rsi
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
testb %al, %al
je 0x318d
leaq 0x58(%rsp), %rdi
movq 0x10(%rsp), %rdx
callq 0x4e48
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
callq 0x4e48
movq 0x38(%rsp), %r8
movq (%rsp), %rax
movl 0x6c(%rax), %r9d
movl 0x6c(%r15), %r10d
subq $0x8, %rsp
leaq 0xd19b(%rip), %rdi      # 0x102d8
movq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl %r12d, %ecx
xorl %eax, %eax
pushq %r10
callq 0x2030
addq $0x10, %rsp
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x316b
callq 0x2140
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x317f
callq 0x2140
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
movq (%rsp), %rsi
cmpl %r13d, %r14d
jne 0x323c
cmpl %ebx, %ebp
jne 0x323c
movq %rbp, 0x8(%rsp)
leaq 0x58(%rsp), %rdi
movq 0x10(%rsp), %r13
movq %r13, %rdx
movq %rsi, %rbp
callq 0x4e48
movq 0x58(%rsp), %rbx
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4e48
movq 0x38(%rsp), %r8
movl 0x6c(%rbp), %r10d
movl 0x6c(%r15), %r11d
subq $0x8, %rsp
leaq 0xd11f(%rip), %rdi      # 0x10304
movq 0x28(%rsp), %rsi
movq %rbx, %rdx
movl %r12d, %ecx
movl %r14d, %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 0x321a
callq 0x2140
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x322e
callq 0x2140
movabsq $-0x71c71c71c71c71c7, %r8 # imm = 0x8E38E38E38E38E39
movq (%rsp), %rsi
incl %r12d
movq 0x10(%rsp), %rbx
movq 0x30(%rbx), %rax
movq 0x38(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r8, %rdx
movq %r12, %rdi
cmpq %r12, %rdx
ja 0x306e
movq 0x18(%rsp), %rsi
cmpq %rsi, %rdx
movl 0x28(%rsp), %edi
ja 0x302d
jmp 0x3282
sarq $0x4, %rdx
imulq %r8, %rdx
cmpl $0x0, 0x60(%rbx)
je 0x32a8
movq 0x20(%rbx), %rax
subq 0x18(%rbx), %rax
shrq $0x4, %rax
imull $0x38e38e39, %eax, %esi # imm = 0x38E38E39
leaq 0xd0a4(%rip), %rdi      # 0x10345
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 0xce70(%rip), %rdi      # 0x10133
leaq 0xce76(%rip), %rsi      # 0x10140
leaq 0xce80(%rip), %rcx      # 0x10151
movl $0x1bb, %edx            # imm = 0x1BB
callq 0x20e0
leaq 0xcec8(%rip), %rdi      # 0x101aa
leaq 0xce57(%rip), %rsi      # 0x10140
leaq 0xce61(%rip), %rcx      # 0x10151
movl $0x1c5, %edx            # imm = 0x1C5
callq 0x20e0
leaq 0xce94(%rip), %rdi      # 0x10195
leaq 0xce38(%rip), %rsi      # 0x10140
leaq 0xce42(%rip), %rcx      # 0x10151
movl $0x1c2, %edx            # imm = 0x1C2
callq 0x20e0
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0xb518
jmp 0x3353
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x3353
jmp 0x334e
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x3353
callq 0x2140
movq %rbx, %rdi
callq 0x2200
nop