// File: /workspace/github_cpp_makefile_star2_O3/realuptime[P]PolyDetector/PolyDetector.cpp
// Function: PolyDetector::RemoveOverlappings()
void PolyDetector::RemoveOverlappings()
{
    uint32_t i, j, count = uint32_t(origLines.size());
    
    //logoutf("RemoveOverlappings");
    
    for (auto &l : origLines)
    {
        l.calcCenter();
    }
    
    PolyLine line;

    // lets find overlapping lines
    uint32_t countBefore = count;
    for (i = 0; i < count; i++)
    {
        auto &line_i = origLines[i];

        for(j = i + 1; j < count; j++)
        {
            auto &line_j = origLines[j];
            if (overlap(line_i, line_j))
            {
                int ret = simplifiedLine(line_i, line_j, line);
                
                if (verbose > 3)
                    logoutf("origLine #%u {%f %f %f %f} overlaps with origLine #%u {%f %f %f %f} ret:%d",
                            line_i.id, line_i.a.x, line_i.a.y, line_i.b.x, line_i.b.y,
                            line_j.id, line_j.a.x, line_j.a.y, line_j.b.x, line_j.b.y,
                            ret);

                if (ret == 1)
                {
                    // must remove line_j
                    if (verbose > 1)
                        logoutf("rm origLine %u", line_j.id);
                    origLines.erase(origLines.begin() + j);
                    j--;
                    count--;
                    
                    //i = 0; break;
                }
                else
                {
                    if (ret != 2)
                    {
                        //line.id = uint32_t(origLines.size());
                        line.id = line_i.id;
                        
                        if (verbose)
                            logoutf("new origLine %u by merging %u and %u", line.id, line_i.id, line_j.id);
                        
                        // must remove both line_i and line_j and add a new one
                        origLines.erase(origLines.begin() + j);
                        
                        line.calcCenter();
                        origLines.push_back(std::move(line));
                    }

                    // must remove line_i
                    origLines.erase(origLines.begin() + i);

                    // update counters
                    i--;
                    count--;

                    // skip inner loop an go to next step of outer loop
                    break;
                }
            }
        }
    }
    
    if (countBefore != count)
        logoutf("orig: countBefore:%u count:%u", countBefore, count);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rdi, %r15
movq 0x18(%rdi), %rbx
movq 0x20(%rdi), %r14
movq %r14, %rax
subq %rbx, %rax
shrq $0x4, %rax
imull $0x38e38e39, %eax, %ebp # imm = 0x38E38E39
cmpq %rbx, %r14
je 0x3428
movq %rbx, %rdi
callq 0x54f0
movsd (%rbx), %xmm0
movsd 0x8(%rbx), %xmm1
addps %xmm0, %xmm1
mulps 0xcc08(%rip), %xmm1     # 0x10020
movlps %xmm1, 0x58(%rbx)
addq $0x90, %rbx
cmpq %r14, %rbx
jne 0x33fd
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %rax
movaps %xmm0, -0x20(%rax)
xorl %r12d, %r12d
movq %r12, -0x10(%rax)
movl %r12d, (%rax)
movq %r12, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %r12, 0x20(%rax)
movaps 0xcbb8(%rip), %xmm1     # 0x10010
movaps %xmm1, 0x30(%rax)
movl $0xffffffff, 0x40(%rax) # imm = 0xFFFFFFFF
movb $0x0, 0x44(%rax)
movups %xmm0, 0x48(%rax)
movl %r12d, 0x58(%rax)
testl %ebp, %ebp
je 0x398a
leaq 0x18(%r15), %rax
movq %rax, 0x8(%rsp)
xorl %ecx, %ecx
movl %ebp, %r12d
movl %ebp, 0x10(%rsp)
movq %r15, 0x38(%rsp)
leal 0x1(%rcx), %r13d
cmpl %r12d, %r13d
jae 0x389e
movl %ecx, %eax
leaq (%rax,%rax,8), %rsi
shlq $0x4, %rsi
movq 0x8(%rsp), %rax
movq (%rax), %rbp
movq %rsi, 0x30(%rsp)
addq %rsi, %rbp
leaq 0x10(%rbp), %rax
movq %rax, 0x50(%rsp)
leaq 0x28(%rbp), %rax
movq %rax, 0x48(%rsp)
leaq 0x58(%rbp), %rax
movq %rax, 0x40(%rsp)
movl %r13d, 0x14(%rsp)
movq %rcx, 0x28(%rsp)
movq %rcx, 0x58(%rsp)
movl %r13d, %eax
leaq (%rax,%rax,8), %rbx
shlq $0x4, %rbx
movq 0x8(%rsp), %rax
movq (%rax), %r14
addq %rbx, %r14
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4cda
testb %al, %al
je 0x356f
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2408
testb %al, %al
je 0x3577
movups (%rbp), %xmm0
movaps %xmm0, 0x60(%rsp)
leaq 0x70(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0xbba2
leaq 0x88(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0xbca6
movq 0x40(%rsp), %rdx
movl 0x30(%rdx), %eax
leaq 0x70(%rsp), %rcx
movl %eax, 0x78(%rcx)
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups 0x20(%rdx), %xmm2
movups %xmm2, 0x68(%rcx)
movups %xmm1, 0x58(%rcx)
movups %xmm0, 0x48(%rcx)
movl $0x1, %r13d
jmp 0x37f5
movl %r13d, %ecx
jmp 0x3882
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2408
testb %al, %al
je 0x35e3
movups (%r14), %xmm0
movaps %xmm0, 0x60(%rsp)
leaq 0x10(%r14), %rsi
leaq 0x70(%rsp), %rdi
callq 0xbba2
leaq 0x28(%r14), %rsi
leaq 0x88(%rsp), %rdi
callq 0xbca6
movl 0x88(%r14), %eax
leaq 0x70(%rsp), %rcx
movl %eax, 0x78(%rcx)
movups 0x58(%r14), %xmm0
movups 0x68(%r14), %xmm1
movups 0x78(%r14), %xmm2
movups %xmm2, 0x68(%rcx)
movups %xmm1, 0x58(%rcx)
movups %xmm0, 0x48(%rcx)
movl $0x2, %r13d
jmp 0x37f5
movss (%rbp), %xmm0
movss 0x4(%rbp), %xmm1
movss (%r14), %xmm2
movss 0x4(%r14), %xmm3
movss 0x8(%r14), %xmm4
movss 0xc(%r14), %xmm5
movss %xmm0, 0x24(%rsp)
movss %xmm1, 0x20(%rsp)
movss %xmm2, 0x1c(%rsp)
movss %xmm3, 0x18(%rsp)
callq 0x249a
movq 0x8(%rbp), %rcx
movq %rcx, %r13
testb %al, %al
jne 0x3630
movq (%rbp), %r13
leaq 0x8(%r14), %r15
movd %ecx, %xmm4
shrq $0x20, %rcx
movd %ecx, %xmm5
movss 0x1c(%rsp), %xmm0
movss 0x18(%rsp), %xmm1
movss 0x24(%rsp), %xmm2
movss 0x20(%rsp), %xmm3
callq 0x249a
testb %al, %al
cmoveq %r14, %r15
movq (%r15), %rax
movq %r13, 0xf8(%rsp)
movq %rax, 0x100(%rsp)
movl $0x0, %edx
movl %edx, 0x128(%rsp)
movq %rdx, 0x130(%rsp)
leaq 0x128(%rsp), %rax
movq %rax, 0x138(%rsp)
movq %rax, 0x140(%rsp)
movq %rdx, 0x148(%rsp)
movaps 0xc95f(%rip), %xmm0     # 0x10010
movups %xmm0, 0x158(%rsp)
movl $0xffffffff, 0x168(%rsp) # imm = 0xFFFFFFFF
movb $0x0, 0x16c(%rsp)
leaq 0x108(%rsp), %rcx
movl %edx, 0x78(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x68(%rcx)
movq 0xf8(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x70(%rsp), %rdi
leaq 0x70(%rsp), %rax
movq %rdx, 0x10(%rax)
movaps %xmm0, (%rax)
movq %rdx, 0x10(%rcx)
movups %xmm0, (%rcx)
testq %rdi, %rdi
je 0x371a
callq 0x2140
leaq 0x88(%rsp), %rdi
callq 0xbfc0
movq 0x130(%rsp), %rax
testq %rax, %rax
movq 0x38(%rsp), %r15
je 0x37a5
movl 0x128(%rsp), %ecx
movl %ecx, 0x90(%rsp)
movq %rax, 0x98(%rsp)
movups 0x138(%rsp), %xmm0
movaps %xmm0, 0xa0(%rsp)
leaq 0x90(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x148(%rsp), %rax
movq %rax, 0xb0(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x130(%rsp)
leaq 0x128(%rsp), %rax
movq %rax, 0x138(%rsp)
movq %rax, 0x140(%rsp)
movq %rcx, 0x148(%rsp)
leaq 0x108(%rsp), %rdx
movl 0x78(%rdx), %eax
leaq 0x70(%rsp), %rcx
movl %eax, 0x78(%rcx)
movups 0x48(%rdx), %xmm0
movups 0x58(%rdx), %xmm1
movups 0x68(%rdx), %xmm2
movups %xmm2, 0x68(%rcx)
movups %xmm1, 0x58(%rcx)
movups %xmm0, 0x48(%rcx)
leaq 0x120(%rsp), %rdi
callq 0xc2b6
movq 0x108(%rsp), %rdi
testq %rdi, %rdi
je 0x37ef
callq 0x2140
movl $0x3, %r13d
cmpl $0x4, 0x60(%r15)
jb 0x384b
xorps %xmm0, %xmm0
cvtss2sd (%rbp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rbp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rbp), %xmm2
movl 0x60(%rbp), %esi
xorps %xmm3, %xmm3
cvtss2sd 0xc(%rbp), %xmm3
movl 0x60(%r14), %edx
cvtss2sd (%r14), %xmm4
cvtss2sd 0x4(%r14), %xmm5
cvtss2sd 0x8(%r14), %xmm6
cvtss2sd 0xc(%r14), %xmm7
leaq 0xcb26(%rip), %rdi      # 0x10367
movl %r13d, %ecx
movb $0x8, %al
callq 0x2030
cmpl $0x1, %r13d
jne 0x38a6
cmpl $0x2, 0x60(%r15)
jb 0x386a
movl 0x60(%r14), %esi
leaq 0xcb50(%rip), %rdi      # 0x103b3
xorl %eax, %eax
callq 0x2030
movq 0x8(%rsp), %rdi
addq (%rdi), %rbx
movq %rbx, %rsi
callq 0xc6c0
decl %r12d
movq 0x58(%rsp), %rcx
leal 0x1(%rcx), %r13d
cmpl %r12d, %r13d
jb 0x34da
movl 0x14(%rsp), %eax
movl %eax, %ecx
movl 0x10(%rsp), %ebp
jmp 0x3981
movl %r13d, %ecx
jmp 0x3981
cmpl $0x2, %r13d
je 0x3963
movl 0x60(%rbp), %edx
movl %edx, 0xc0(%rsp)
cmpl $0x0, 0x60(%r15)
je 0x38d5
movl 0x60(%r14), %ecx
leaq 0xcaf7(%rip), %rdi      # 0x103c3
movl %edx, %esi
xorl %eax, %eax
callq 0x2030
movq 0x8(%rsp), %rdi
addq (%rdi), %rbx
movq %rbx, %rsi
callq 0xc6c0
movsd 0x60(%rsp), %xmm1
movsd 0x68(%rsp), %xmm0
movaps %xmm1, %xmm2
shufps $0x55, %xmm1, %xmm2     # xmm2 = xmm2[1,1],xmm1[1,1]
movaps %xmm0, %xmm3
shufps $0x55, %xmm0, %xmm3     # xmm3 = xmm3[1,1],xmm0[1,1]
ucomiss %xmm2, %xmm3
ja 0x393c
movaps %xmm1, %xmm4
cmpltps %xmm0, %xmm4
cmpeqps %xmm3, %xmm2
andps %xmm4, %xmm2
movd %xmm2, %eax
testb $0x1, %al
jne 0x393c
movlhps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movaps %xmm0, 0x60(%rsp)
movq 0xe0(%rsp), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0xe0(%rsp)
movaps %xmm1, %xmm0
movsd 0x60(%rsp), %xmm1
addps %xmm0, %xmm1
mulps 0xc6d4(%rip), %xmm1     # 0x10020
movlps %xmm1, 0xb8(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xc334
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq (%rdi), %rsi
callq 0xc6c0
decl %r12d
movl 0x10(%rsp), %ebp
movq 0x28(%rsp), %rcx
cmpl %r12d, %ecx
jb 0x348e
cmpl %ebp, %r12d
je 0x39a2
leaq 0xca53(%rip), %rdi      # 0x103e9
movl %ebp, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2030
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
callq 0xc2b6
movq -0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x39c0
callq 0x2140
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x39da
jmp 0x39da
jmp 0x39da
jmp 0x39da
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xb518
movq %rbx, %rdi
callq 0x2200
nop