// File: /workspace/github_cpp_makefile_star2_O2/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 $0x168, %rsp            # imm = 0x168
leaq 0x18(%rdi), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rdi), %rbx
movq %rdi, 0x18(%rsp)
movq 0x20(%rdi), %r14
movq %r14, %rax
subq %rbx, %rax
movl $0x90, %ecx
cqto
idivq %rcx
movq %rax, %r15
cmpq %r14, %rbx
je 0x2fb4
movq %rbx, %rdi
callq 0x2868
addq $0x90, %rbx
jmp 0x2f9e
xorps %xmm0, %xmm0
leaq 0x108(%rsp), %rax
andq $0x0, -0x10(%rax)
movups %xmm0, -0x20(%rax)
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movaps 0xa02c(%rip), %xmm1     # 0xd010
movups %xmm1, 0x30(%rax)
orl $-0x1, 0x40(%rax)
movb $0x0, 0x44(%rax)
movups %xmm0, 0x48(%rax)
andl $0x0, 0x58(%rax)
xorl %ecx, %ecx
movq %r15, 0x20(%rsp)
movl %r15d, %ebp
movq 0x10(%rsp), %r14
movl %ecx, %eax
imulq $0x90, %rax, %rbx
movl %ecx, 0xc(%rsp)
movq %rbx, 0x38(%rsp)
cmpl %ebp, %ecx
jae 0x32c4
movq (%r14), %r13
leaq (%rbx,%r13), %rax
addq $0x8, %rax
movq %rax, 0x40(%rsp)
addq %rbx, %r13
movl %ecx, %r12d
movq (%r14), %r15
leal 0x1(%r12), %eax
imulq $0x90, %rax, %rbx
addq $-0x90, %rbx
incl %r12d
cmpl %ebp, %r12d
jae 0x32b9
leaq (%r15,%rbx), %rsi
addq $0x90, %rsi
addq $0x90, %rbx
movq %r13, %rdi
callq 0x4184
testb %al, %al
je 0x304d
leaq (%r15,%rbx), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x234a
testb %al, %al
je 0x30a3
leaq 0xd8(%rsp), %rdi
movq %r13, %rsi
callq 0x8d9c
pushq $0x1
popq %r14
jmp 0x31a3
movq %r14, %rdi
movq %r13, %rsi
callq 0x234a
testb %al, %al
je 0x30cb
leaq 0xd8(%rsp), %rdi
movq %r14, %rsi
callq 0x8d9c
pushq $0x2
popq %r14
jmp 0x31a3
leaq (%r15,%rbx), %rdx
addq $0x8, %rdx
movq %rdx, 0x30(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x238d
leaq 0x8(%r13), %rcx
testb %al, %al
cmoveq %r13, %rcx
movq (%rcx), %rax
movq %rax, 0x28(%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq 0x40(%rsp), %rdx
callq 0x238d
testb %al, %al
cmovneq 0x30(%rsp), %r14
movq (%r14), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x48(%rsp)
movq %rax, 0x50(%rsp)
leaq 0x58(%rsp), %rax
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andl $0x0, 0x78(%rsp)
andq $0x0, 0x80(%rsp)
leaq 0x78(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq %rcx, 0x90(%rsp)
andq $0x0, 0x98(%rsp)
movaps 0x9eae(%rip), %xmm1     # 0xd010
movups %xmm1, 0xa8(%rsp)
orl $-0x1, 0xb8(%rsp)
movb $0x0, 0xbc(%rsp)
movups %xmm0, 0x68(%rax)
andl $0x0, 0x78(%rax)
leaq 0xd8(%rsp), %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0x8dfa
movq %r14, %rdi
callq 0x8736
pushq $0x3
popq %r14
movq 0x18(%rsp), %rax
cmpl $0x4, 0x60(%rax)
jb 0x31fb
cvtss2sd (%r13), %xmm0
cvtss2sd 0x4(%r13), %xmm1
cvtss2sd 0x8(%r13), %xmm2
movl 0x60(%r13), %esi
cvtss2sd 0xc(%r13), %xmm3
movl 0x60(%r15,%rbx), %edx
cvtss2sd (%r15,%rbx), %xmm4
cvtss2sd 0x4(%r15,%rbx), %xmm5
cvtss2sd 0x8(%r15,%rbx), %xmm6
cvtss2sd 0xc(%r15,%rbx), %xmm7
leaq 0xa14a(%rip), %rdi      # 0xd33b
movl %r14d, %ecx
movb $0x8, %al
callq 0x2040
cmpl $0x1, %r14d
jne 0x323c
movq 0x18(%rsp), %rax
cmpl $0x2, 0x60(%rax)
jb 0x321f
movl 0x60(%r15,%rbx), %esi
leaq 0xa16f(%rip), %rdi      # 0xd387
xorl %eax, %eax
callq 0x2040
movq 0x10(%rsp), %r14
addq (%r14), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8758
decl %r12d
decl %ebp
jmp 0x3037
cmpl $0x2, %r14d
movq 0x10(%rsp), %r14
je 0x329b
movl 0x60(%r13), %edx
movl %edx, 0x138(%rsp)
movq 0x18(%rsp), %rax
cmpl $0x0, 0x60(%rax)
je 0x3272
movl 0x60(%r15,%rbx), %ecx
leaq 0xa12e(%rip), %rdi      # 0xd397
movl %edx, %esi
xorl %eax, %eax
callq 0x2040
addq (%r14), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8758
leaq 0xd8(%rsp), %rbx
movq %rbx, %rdi
callq 0x2868
movq %r14, %rdi
movq %rbx, %rsi
callq 0x97a4
movq (%r14), %rsi
movq 0x38(%rsp), %rbx
addq %rbx, %rsi
movq %r14, %rdi
callq 0x8758
decl %ebp
movl 0xc(%rsp), %ecx
jmp 0x3019
movl 0xc(%rsp), %ecx
incl %ecx
jmp 0x3007
movq 0x20(%rsp), %rsi
cmpl %esi, %ebp
je 0x32dd
leaq 0xa0e9(%rip), %rdi      # 0xd3bd
movl %ebp, %edx
xorl %eax, %eax
callq 0x2040
leaq 0xd8(%rsp), %rdi
callq 0x8736
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3304
jmp 0x3304
jmp 0x3304
jmp 0x3304
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x8736
movq %rbx, %rdi
callq 0x2200