// File: /workspace/github_cpp_makefile_star2_O3/realuptime[P]PolyDetector/PolyDetector.cpp
// Function: PolyDetector::DetectAllIntersections()
uint32_t PolyDetector::DetectAllIntersections()
{
    uint32_t ret = 0;
    size_t counter = origLines.size();
    PointType intersection;
    
    intersectionPoints.clear();
    collinearLineMap.clear();
    
    for (auto &l : origLines)
    {
        l.calcCenter();
    }
    
    // sort to always have the same results
    std::sort(origLines.begin(), origLines.end(), PolyLine::bCompareLineOrder);
    
    uint32_t n = 0;
    for (auto &l : origLines)
    {
        l.id = n++;
        l.intersections.clear();
        l.intersectedLines.clear();
    }
    
    // intersected lines: remove lines with only one intersection
    for (uint32_t i = 0; i < counter; i++)
    {
        auto &l1 = origLines[i];
        for (uint32_t j = i + 1; j < counter; j++)
        {
            auto &l2 = origLines[j];
            if (doIntersect(l1.a, l1.b, l2.a, l2.b))
            {
                //if (verbose > 1)
                //    logoutf("line #%u intersects #%u", l1.id, l2.id);
                
                /*
                for (auto &l : {&l1, &l2})
                {
                    auto &otherLid = l->id == l1.id ? l2.id : l1.id;

                    if (l->intersectedLines.find(otherLid) != l->intersectedLines.end())
                    {
                        logoutf("WARN: origLine #%u already contains intersected origLine #%u", l->id, otherLid);
                    }
                    else
                    {
                        l->intersectedLines.insert(otherLid);
                    }
                }
                */
                
                //if (l1.intersectedLines.find(l2.id) != l1.intersectedLines.end())
                l1.intersectedLines.insert(l2.id);
                l2.intersectedLines.insert(l1.id);
            }
        }
    }
    
    for (uint32_t i = 0; i < counter; i++)
    {
        auto &l1 = origLines[i];
        if (l1.intersectedLines.size() == 1)
        {
            if (verbose)
                logoutf("line #%u has only %u intersectedLines", l1.id, uint32_t(l1.intersectedLines.size()));
            
            for (uint32_t j = 0; j < counter; j++)
            {
                if (i != j)
                {
                    auto &l2 = origLines[j];
                    
                    for (auto it = l2.intersectedLines.begin(); it != l2.intersectedLines.end(); )
                    {
                        if (*it == l1.id)
                        {
                            if (verbose)
                                logoutf("removed intersectedLine line #%u from line #%u", l1.id, l2.id);
                            it = l2.intersectedLines.erase(it);
                            i = 0; // recheck all lines
                        }
                        else
                            ++it;
                    }
                }
            }
            
            l1.intersectedLines.clear();
        }
    }
    
    if (verbose > 2)
    {
        for (auto &l : origLines)
        {
            //if (!l.intersectedLines.empty())
            {
                std::string str;
                for (auto &n : l.intersectedLines)
                    str += std::to_string(n) + " ";
                if (!str.empty())
                    str.pop_back();
                logoutf("line #%u has %u intersectedLines: [%s]", l.id, uint32_t(l.intersectedLines.size()), str.c_str());
            }
        }
    }
    
    // intersection points
    std::set<std::pair<uint32_t, uint32_t>> took;
    for (auto &l1 : origLines)
    {
        for (auto &lid2 : l1.intersectedLines)
        {
            auto &l2 = origLines[lid2];
            
            if (took.find(std::make_pair(l1.id, l2.id)) == took.end())
            {
                intersection = vec(0);
                if (l1.IntersectionPoint(l2, intersection)) // checks if not parallel
                {
                    uint32_t intersectionIdx = uint32_t(intersectionPoints.size());
                    
                    // Check if the same intersection point exists
                    bool dupPoint = false;
                    for (uint32_t pi = 0; pi < intersectionPoints.size(); ++pi)
                    {
                        auto &p = intersectionPoints[pi];
                        if (!pointsDiffer(p, intersection))
                        {
                            if (verbose > 3)
                            {
                                logoutf("WARN: origLine #%u intersects origLine #%u exactly in the same point P%u as:", l1.id, l2.id, pi);
                                for (auto &lDup : origLines)
                                {
                                    if (lDup.id != l1.id && lDup.id != l2.id)
                                    {
                                        for (auto &inters : lDup.intersections)
                                        {
                                            if (inters == pi)
                                            {
                                                logoutf("WARN:  origLine #%u", lDup.id);
                                            }
                                        }
                                    }
                                }
                            }
                            dupPoint = true;
                            intersectionIdx = pi;
                            intersection = p;
                            break;
                        }
                    }

                    if (!dupPoint)
                    {
                        intersectionPoints.push_back(intersection);
                    }
                    
                    if (verbose > 2)
                        logoutf("[P%u]: origLine #%u intersects origLine #%u. dup:%d", intersectionIdx, l1.id, l2.id, dupPoint);
                    
                    for (auto &l : {&l1, &l2})
                    {
                        if (std::find(l->intersections.begin(), l->intersections.end(), intersectionIdx) != l->intersections.end())
                        {
                            if (verbose > 1)
                                logoutf("WARN: duplicate intersectionIdx P%u in line #%u", intersectionIdx, l->id);
                        }
                        else
                        {
                            //auto d = obb::LineSegment(l->a, l->b).Distance(intersection);
                            //assert(d < .1f);
                            
                            //auto d1 = obb::LineSegment(l->a, l->b).Distance(intersectionPoints[intersectionIdx]);
                            //assert(d1 < .1f);
                            
                            l->intersections.push_back(intersectionIdx);
                        }
                    }
                    
                    //addPointToLine(intersectionIdx, l1.id);
                    //addPointToLine(intersectionIdx, l2.id);
                    
                    took.insert(std::make_pair(l1.id, l2.id));
                    took.insert(std::make_pair(l2.id, l1.id));
                    
                    ret++;
                }
            }
        }
    }
    if (verbose)
        logoutf("intersectionPoints:%u", uint32_t(intersectionPoints.size()));
    
    //return 0;
    
    if (verbose > 2)
    {
        for (auto &l : origLines)
        {
            //if (!l.intersections.empty())
            {
                std::string str;
                for (auto &n : l.intersections)
                    str += std::to_string(n) + " ";
                if (!str.empty())
                    str.pop_back();
                logoutf("line #%u has %u pts: [%s]", l.id, uint32_t(l.intersections.size()), str.c_str());
            }
        }
    }
    
#if 1
    
    uint32_t nCol = 0;
    std::vector<uint32_t> pids;
    
    uint32_t times = 0;
    bool ok = false;
    do
    {
        took.clear();
        //nCol = 0;
        
        ok = true;
        
        for (auto &l1 : origLines)
        {
            if (l1.ignore) continue;
            if (l1.intersections.size() < 2) continue;
            
            //if (times == 1)
            //    l1.SortIntersectionsList(*this);
            
            float a, b, c;
            vec::line(vec(l1.a.x, l1.a.y), vec(l1.b.x, l1.b.y), a, b, c);
            if (a + b == 0.0f)
            {
                logoutf("l1:#%u l1.a: [%f %f] l1.b: [%f %f]", l1.id, l1.a.x, l1.a.y, l1.b.x, l1.b.y);
                assert(0);
                continue;
            }
            
            //obb::Line line = obb::LineSegment(l1.a, l1.b).ToLine();
        
            for (auto &l2 : origLines)
            {
                if (l2.ignore) continue;
                if (l2.intersections.size() < 2) continue;
                
                //if (took.find(std::make_pair(l1.id, l2.id)) == took.end())
                {
                    //if (k == 1)
                    //    l2.SortIntersectionsList(*this);
                    
                    took.insert(std::make_pair(l1.id, l2.id));
                    took.insert(std::make_pair(l2.id, l1.id));
                    
                    if (l1.id == l2.id) continue;
                    if (l2.intersections.empty()) continue;
                    assert(&l1 != &l2);
                    
                    uint32_t nFound = 0;
                    float maxLineDist = 0;
                    pids.clear();
                    for (auto &pid1 : l1.intersections)
                    {
                        for (auto &pid2 : l2.intersections)
                        {
                            if (pid1 == pid2)
                            {
                                nFound++;
                                pids.push_back(pid1);
                            }
                            
                            //float d = line.Distance(intersectionPoints[pid2]);
                            float d = vec::lineDist(a, b, c, vec(intersectionPoints[pid2].x, intersectionPoints[pid2].y));
                            if (d > maxLineDist)
                                maxLineDist = d;
                        }
                    }
                    
                    if (nFound >= 2)
                    {
                        ok = false;
                        
#if 1
                        if (maxLineDist <= minPointDiff)
                        {
                            logoutf("[%u]: line #%u is collinear with line #%u! nFound:%u lineDist:%f merging ...", times, l1.id, l2.id, nFound, maxLineDist);
                            
                            // TODO: merge point of l2 into l1
                            uint32_t nMerged = 0;
                            for (auto &pid : l2.intersections)
                            {
                                //logoutf("add P%u to l#%u", pid, l1.id);
                                if (std::find(l1.intersections.begin(), l1.intersections.end(), pid) == l1.intersections.end())
                                {
                                    //logoutf("add P%u to l#%u", pid, l1.id);
                                    l1.intersections.push_back(pid);
                                    nMerged++;
                                }
                            }
                            if (nMerged > 0)
                            {
                                logoutf("[%u]: merged %u points from line #%u into line #%u! dist:%f", times, nMerged, l2.id, l1.id, maxLineDist);
                            }
                            
                            //logoutf("line #%u with %u intersections ignored", l2.id, uint32_t(l2.intersections.size()));
                            l2.intersections.clear();
                            l2.a = l2.b = l2.center = vec(0);
                            l2.ignore = true;
                            
                            nCol++;
                        }
                        else
                        {
                            // merge points?
                            
                            // remove them
                            uint32_t nRm1 = 0, nRm2 = 0;
                            for (auto &pid : pids)
                            {
                                logoutf("[%u]]: P%u", times, pid);
                                for (auto it = l1.intersections.begin(); it != l1.intersections.end();)
                                {
                                    if (*it == pid)
                                    {
                                        it = l1.intersections.erase(it);
                                        nRm1++;
                                    }
                                    else
                                        ++it;
                                }
                                for (auto it = l2.intersections.begin(); it != l2.intersections.end();)
                                {
                                    if (*it == pid)
                                    {
                                        it = l2.intersections.erase(it);
                                        nRm2++;
                                    }
                                    else
                                        ++it;
                                }
                            }
                            auto keepPid = pids[0];
                            l1.intersections.push_back(keepPid);
                            l2.intersections.push_back(keepPid);
                            
                            logoutf("[%u]]: line #%u has common points(%u) with line #%u keeping just P%u nRm1:%u nRm2:%u rem1:%u rem2:%u lineDist:%f",
                                    times, l1.id, uint32_t(pids.size()), l2.id, keepPid, nRm1, nRm2,
                                    uint32_t(l1.intersections.size()),
                                    uint32_t(l2.intersections.size()),
                                    maxLineDist);
                        }
#endif
                    
                    }
                }
            }
        }
        if (ok && verbose)
            logoutf("[%u] ok!", times);
        times++;
    }
    while (!ok);
    
    logoutf("Number of col lines using intersection points: %u", uint32_t(nCol));
#endif

    for (auto &l : origLines)
    {
        if (l.intersections.size() == 1)
        {
            logoutf("WARN: line #%u has only %u intersections!", l.id, uint32_t(l.intersections.size()));
            //assert(false);
        }
    }
    
    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %r12
movq 0xc8(%rdi), %rax
cmpq %rax, 0xd0(%rdi)
je 0x3a1c
movq %rax, 0xd0(%r12)
movq 0x18(%r12), %rbp
movq 0x20(%r12), %rax
movq %rax, 0x88(%rsp)
leaq 0x98(%r12), %rdi
callq 0xcbcc
movq 0x18(%r12), %r14
movq 0x20(%r12), %r15
cmpq %r15, %r14
je 0x3a82
movq %r14, %rdi
callq 0x54f0
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
addps %xmm0, %xmm1
mulps 0xc5b9(%rip), %xmm1     # 0x10020
movlps %xmm1, 0x58(%r14)
addq $0x90, %r14
cmpq %r15, %r14
jne 0x3a4a
movq 0x18(%r12), %r14
movq 0x20(%r12), %r15
movabsq $-0x71c71c71c71c71c7, %r13 # imm = 0x8E38E38E38E38E39
cmpq %r15, %r14
movq %r12, 0x18(%rsp)
je 0x3ae3
movq %r15, %rax
subq %r14, %rax
sarq $0x4, %rax
imulq %r13, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x12a0(%rip), %r12     # 0x2818
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0xcc3e
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq 0x18(%rsp), %r12
callq 0xcdb7
movq 0x18(%r12), %r14
movq 0x20(%r12), %r15
cmpq %r15, %r14
je 0x3b13
xorl %ebx, %ebx
movl %ebx, 0x60(%r14)
movq 0x10(%r14), %rax
cmpq %rax, 0x18(%r14)
je 0x3afc
movq %rax, 0x18(%r14)
leaq 0x28(%r14), %rdi
callq 0xbfc0
addq $0x90, %r14
incl %ebx
cmpq %r15, %r14
jne 0x3aea
movq 0x88(%rsp), %rcx
cmpq %rbp, %rcx
je 0x3d08
movq %rbp, %rax
movq %rcx, %rbp
movq %rax, 0x98(%rsp)
subq %rax, %rbp
sarq $0x4, %rbp
imulq %r13, %rbp
xorl %eax, %eax
movl $0x2, %ebx
xorl %ecx, %ecx
movq %rbp, 0x10(%rsp)
incl %ecx
cmpq %rcx, %rbp
jbe 0x3bec
leaq (%rax,%rax,8), %r14
shlq $0x4, %r14
addq 0x18(%r12), %r14
leaq 0x8(%r14), %r15
leaq 0x28(%r14), %r12
leaq 0x60(%r14), %r13
movl %ebx, (%rsp)
movq %rcx, 0x20(%rsp)
movq %rcx, %rax
movq 0x18(%rsp), %rcx
movq 0x18(%rcx), %rcx
leaq (%rax,%rax,8), %rax
shlq $0x4, %rax
leaq (%rcx,%rax), %rbp
addq %rax, %rcx
addq $0x8, %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x251f
testb %al, %al
je 0x3bc3
leaq 0x60(%rbp), %rsi
movq %r12, %rdi
callq 0xe00a
addq $0x28, %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0xe00a
movl %ebx, %eax
incl %ebx
movq 0x10(%rsp), %rbp
cmpq %rax, %rbp
ja 0x3b7a
movl (%rsp), %ebx
incl %ebx
movq 0x20(%rsp), %rcx
movq %rcx, %rax
cmpq %rcx, %rbp
movq 0x18(%rsp), %r12
ja 0x3b4b
movq 0x88(%rsp), %rax
cmpq 0x98(%rsp), %rax
je 0x3d08
xorl %eax, %eax
xorl %r15d, %r15d
movq 0x18(%r12), %rbx
leaq (%rax,%rax,8), %r14
shlq $0x4, %r14
cmpq $0x1, 0x50(%rbx,%r14)
jne 0x3cf9
movq %r12, %rax
leaq (%rbx,%r14), %r12
cmpl $0x0, 0x60(%rax)
je 0x3c45
movl 0x60(%r12), %esi
leaq 0xc7cf(%rip), %rdi      # 0x10408
movl $0x1, %edx
xorl %eax, %eax
callq 0x2030
leaq (%rbx,%r14), %rax
addq $0x28, %rax
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
cmpl %r14d, %r15d
je 0x3cd9
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
leaq (%r14,%r14,8), %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rbx
addq $0x30, %rbx
movq 0x10(%rbx), %rbp
cmpq %rbx, %rbp
je 0x3cd9
leaq (%rax,%rcx), %rdx
movq %rdx, (%rsp)
leaq (%rax,%rcx), %r13
addq $0x28, %r13
movl 0x20(%rbp), %esi
cmpl 0x60(%r12), %esi
jne 0x3cc9
movq 0x18(%rsp), %rax
cmpl $0x0, 0x60(%rax)
je 0x3cb6
movq (%rsp), %rax
movl 0x60(%rax), %edx
leaq 0xc780(%rip), %rdi      # 0x1042f
xorl %eax, %eax
callq 0x2030
movq %r13, %rdi
movq %rbp, %rsi
callq 0xe118
movq %rax, %rbp
xorl %r15d, %r15d
jmp 0x3cd4
movq %rbp, %rdi
callq 0x2180
movq %rax, %rbp
cmpq %rbx, %rbp
jne 0x3c8c
incl %r14d
movq 0x10(%rsp), %rbp
cmpq %r14, %rbp
ja 0x3c55
movq 0x20(%rsp), %rdi
callq 0xbfc0
movq 0x18(%rsp), %r12
incl %r15d
movq %r15, %rax
cmpq %r15, %rbp
ja 0x3c07
leaq 0xc8(%r12), %r14
cmpl $0x2, 0x60(%r12)
movq 0x18(%r12), %rbp
movq 0x20(%r12), %rax
jbe 0x3f12
cmpq %rax, %rbp
je 0x4290
leaq 0xb8(%rsp), %r15
leaq 0x40(%rsp), %r13
movl $0xd1b71759, %ebx       # imm = 0xD1B71759
movq %rax, 0x8(%rsp)
movq %r15, 0xa8(%rsp)
movq $0x0, 0xb0(%rsp)
movb $0x0, 0xb8(%rsp)
movq %rbp, %rax
movq 0x40(%rbp), %rbp
movq %rax, 0x20(%rsp)
addq $0x30, %rax
movq %rax, (%rsp)
cmpq %rax, %rbp
je 0x3eb3
movl 0x20(%rbp), %r15d
movl $0x1, %eax
cmpl $0xa, %r15d
jb 0x3dce
movl $0x4, %eax
movl %r15d, %ecx
cmpl $0x63, %ecx
jbe 0x3dc7
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x3dcc
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x3dce
movl %ecx, %edx
imulq %rbx, %rdx
shrq $0x2d, %rdx
addl $0x4, %eax
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x3d96
addl $-0x3, %eax
jmp 0x3dce
addl $-0x2, %eax
jmp 0x3dce
decl %eax
movl %eax, %esi
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x58(%rsp), %r12
movq %r12, %rdi
xorl %edx, %edx
callq 0x2190
movq 0x58(%rsp), %rdi
movl 0x60(%rsp), %esi
movl %r15d, %edx
callq 0xbfed
movq %r12, %rdi
leaq 0xcc80(%rip), %rsi      # 0x10a84
callq 0x2220
movq %r13, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x3e2c
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x3e34
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0xa8(%rsp), %rdi
callq 0x2060
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x3e72
callq 0x2140
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x3e86
callq 0x2140
movq %rbp, %rdi
callq 0x2180
movq %rax, %rbp
cmpq (%rsp), %rax
jne 0x3d7f
cmpq $0x0, 0xb0(%rsp)
je 0x3eb3
leaq 0xa8(%rsp), %rdi
callq 0x21a0
movq 0x20(%rsp), %rbp
movl 0x50(%rbp), %edx
movl 0x60(%rbp), %esi
movq 0xa8(%rsp), %rcx
leaq 0xc592(%rip), %rdi      # 0x1045f
xorl %eax, %eax
callq 0x2030
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %r15
cmpq %r15, %rdi
je 0x3eee
callq 0x2140
addq $0x90, %rbp
movq 0x8(%rsp), %rax
cmpq %rax, %rbp
jne 0x3d46
movq 0x18(%rsp), %r12
movq 0x18(%r12), %rbp
movq 0x20(%r12), %rax
leaq 0xb0(%rsp), %rcx
movl $0x0, (%rcx)
xorl %edx, %edx
movq %rdx, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq $0x0, 0x90(%rsp)
movq %rdx, 0x20(%rcx)
cmpq %rax, %rbp
je 0x42bc
movq $0x0, 0x90(%rsp)
movq %rax, 0x8(%rsp)
movq 0x40(%rbp), %rax
leaq 0x30(%rbp), %r15
cmpq %r15, %rax
movq %r15, 0x98(%rsp)
je 0x4279
movq %rax, (%rsp)
movl 0x20(%rax), %eax
movq 0x18(%r12), %rcx
leaq (%rax,%rax,8), %rbx
shlq $0x4, %rbx
movl 0x60(%rbp), %eax
movq %rcx, %r13
movl 0x60(%rcx,%rbx), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x30(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xe150
leaq 0xb0(%rsp), %rcx
cmpq %rcx, %rax
jne 0x4267
addq %rbx, %r13
movq $0x0, 0x78(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
leaq 0x78(%rsp), %rdx
callq 0x2740
testb %al, %al
je 0x4267
movq %r13, 0x10(%rsp)
movq 0xc8(%r12), %rbx
movq 0xd0(%r12), %rsi
movq %rsi, %rcx
subq %rbx, %rcx
shrq $0x3, %rcx
movq %rsi, %rax
movl %ecx, 0x58(%rsp)
subq %rbx, %rax
je 0x4052
movss 0x78(%rsp), %xmm0
movss 0x7c(%rsp), %xmm1
sarq $0x3, %rax
xorl %r15d, %r15d
movss (%rbx,%r15,8), %xmm2
subss %xmm0, %xmm2
movss 0x4(%rbx,%r15,8), %xmm3
subss %xmm1, %xmm3
mulss %xmm3, %xmm3
mulss %xmm2, %xmm2
addss %xmm3, %xmm2
ucomiss 0xc048(%rip), %xmm2     # 0x10090
jb 0x4079
incl %r15d
cmpq %r15, %rax
ja 0x4020
cmpq 0xd8(%r12), %rsi
je 0x412f
movq 0x78(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0xd0(%r12)
xorl %r15d, %r15d
jmp 0x415a
cmpl $0x3, 0x60(%r12)
jbe 0x4146
movq %rbp, 0x20(%rsp)
movl 0x60(%rbp), %esi
movq 0x10(%rsp), %rax
movl 0x60(%rax), %edx
leaq 0xc3eb(%rip), %rdi      # 0x10487
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2030
movq 0x18(%r12), %rbp
movq 0x20(%r12), %rax
movq %rax, 0x88(%rsp)
cmpq %rax, %rbp
je 0x410f
movl 0x60(%rbp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x60(%rcx), %eax
je 0x40fe
movq 0x10(%rsp), %rcx
cmpl 0x60(%rcx), %eax
je 0x40fe
movq 0x10(%rbp), %r12
movq 0x18(%rbp), %r13
cmpq %r13, %r12
je 0x40fe
cmpl %r15d, (%r12)
jne 0x40f8
movl 0x60(%rbp), %esi
leaq 0xc3e4(%rip), %rdi      # 0x104d5
xorl %eax, %eax
callq 0x2030
addq $0x4, %r12
jmp 0x40dc
addq $0x90, %rbp
cmpq 0x88(%rsp), %rbp
jne 0x40bd
movl %r15d, 0x58(%rsp)
movq (%rbx,%r15,8), %rax
movq %rax, 0x78(%rsp)
movl $0x1, %r15d
movq 0x18(%rsp), %r12
movq 0x20(%rsp), %rbp
jmp 0x415a
xorl %r15d, %r15d
movq %r14, %rdi
leaq 0x78(%rsp), %rdx
callq 0xe1ae
movq 0x10(%rsp), %rbx
jmp 0x415f
movl %r15d, 0x58(%rsp)
movq (%rbx,%r15,8), %rax
movq %rax, 0x78(%rsp)
movl $0x1, %r15d
movq 0x10(%rsp), %rbx
cmpl $0x3, 0x60(%r12)
jb 0x4182
movl 0x58(%rsp), %esi
movl 0x60(%rbp), %edx
movl 0x60(%rbx), %ecx
leaq 0xc372(%rip), %rdi      # 0x104ea
movl %r15d, %r8d
xorl %eax, %eax
callq 0x2030
movq %rbp, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
xorl %ebx, %ebx
movq 0x30(%rsp,%rbx), %r15
movq 0x10(%r15), %rdi
movq 0x18(%r15), %rsi
leaq 0x58(%rsp), %rdx
callq 0xca0e
movq 0x18(%r15), %rsi
cmpq %rsi, %rax
je 0x41ce
cmpl $0x2, 0x60(%r12)
jb 0x41f5
movl 0x58(%rsp), %esi
movl 0x60(%r15), %edx
leaq 0xc35a(%rip), %rdi      # 0x1051f
xorl %eax, %eax
callq 0x2030
jmp 0x41f5
cmpq 0x20(%r15), %rax
je 0x41e4
movl 0x58(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%r15)
jmp 0x41f5
addq $0x10, %r15
movq %r15, %rdi
leaq 0x58(%rsp), %rdx
callq 0xcab4
addq $0x8, %rbx
cmpq $0x10, %rbx
jne 0x418e
movl 0x60(%rbp), %eax
movq 0x10(%rsp), %r13
movl 0x60(%r13), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x30(%rsp)
leaq 0xa8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %r15
movq %r15, %rsi
callq 0xe2ec
movl 0x60(%r13), %eax
movl 0x60(%rbp), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x30(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe2ec
movq 0x90(%rsp), %rax
incl %eax
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %r15
movq (%rsp), %rdi
callq 0x2180
cmpq %r15, %rax
jne 0x3f71
addq $0x90, %rbp
movq 0x8(%rsp), %rax
cmpq %rax, %rbp
jne 0x3f58
jmp 0x42bc
leaq 0xb0(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq $0x0, 0x90(%rsp)
movq %rcx, 0x20(%rax)
cmpl $0x0, 0x60(%r12)
je 0x44d5
movq 0x18(%rsp), %rbx
movq 0xd0(%rbx), %rsi
subq 0xc8(%rbx), %rsi
shrq $0x3, %rsi
leaq 0xc26a(%rip), %rdi      # 0x10550
xorl %eax, %eax
callq 0x2030
cmpl $0x3, 0x60(%rbx)
jb 0x44d5
movq 0x18(%rsp), %rax
movq 0x18(%rax), %r15
movq 0x20(%rax), %rax
movq %rax, 0x20(%rsp)
cmpq %rax, %r15
je 0x44d5
leaq 0x40(%rsp), %rbx
leaq 0x68(%rsp), %r12
movl $0xd1b71759, %r13d      # imm = 0xD1B71759
movq %rbx, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
movq 0x10(%r15), %rbx
movq %r15, 0x10(%rsp)
movq 0x18(%r15), %rax
movq %rax, (%rsp)
cmpq %rax, %rbx
je 0x4487
movl (%rbx), %r15d
movl $0x1, %eax
cmpl $0xa, %r15d
jb 0x439d
movl $0x4, %eax
movl %r15d, %ecx
cmpl $0x63, %ecx
jbe 0x4396
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x439b
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x439d
movl %ecx, %edx
imulq %r13, %rdx
shrq $0x2d, %rdx
addl $0x4, %eax
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x4365
addl $-0x3, %eax
jmp 0x439d
addl $-0x2, %eax
jmp 0x439d
decl %eax
movl %eax, %esi
leaq 0xf8(%rsp), %rax
movq %rax, 0xe8(%rsp)
leaq 0xe8(%rsp), %rbp
movq %rbp, %rdi
xorl %edx, %edx
callq 0x2190
movq 0xe8(%rsp), %rdi
movl 0xf0(%rsp), %esi
movl %r15d, %edx
callq 0xbfed
movq %rbp, %rdi
leaq 0xc6a2(%rip), %rsi      # 0x10a84
callq 0x2220
movq %r12, 0x58(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x440a
movq %rdx, 0x58(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x68(%rsp)
jmp 0x4412
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, 0x60(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0x30(%rsp), %rdi
callq 0x2060
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x444d
callq 0x2140
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0x4467
callq 0x2140
addq $0x4, %rbx
cmpq (%rsp), %rbx
jne 0x434f
cmpq $0x0, 0x38(%rsp)
je 0x4487
leaq 0x30(%rsp), %rdi
callq 0x21a0
movq 0x10(%rsp), %r15
movl 0x60(%r15), %esi
movq 0x18(%r15), %rdx
subq 0x10(%r15), %rdx
shrq $0x2, %rdx
movq 0x30(%rsp), %rcx
leaq 0xc0bf(%rip), %rdi      # 0x10567
xorl %eax, %eax
callq 0x2030
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rbx
cmpq %rbx, %rdi
je 0x44c3
callq 0x2140
addq $0x90, %r15
cmpq 0x20(%rsp), %r15
jne 0x4322
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rax
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0xa8(%rsp), %r15
leaq 0x58(%rsp), %r13
movl $0x0, 0x2c(%rsp)
movl $0x0, 0xa4(%rsp)
movq %r15, %rdi
callq 0xe42c
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rbp
movq 0x20(%rax), %rax
movq %rax, 0x110(%rsp)
cmpq %rax, %rbp
je 0x4abf
movb $0x1, %al
movl %eax, 0x54(%rsp)
cmpb $0x0, 0x74(%rbp)
jne 0x4aa8
movq 0x18(%rbp), %rax
subq 0x10(%rbp), %rax
cmpq $0x5, %rax
jb 0x4aa8
movss (%rbp), %xmm0
movss 0x4(%rbp), %xmm1
movss 0x8(%rbp), %xmm2
movss 0xc(%rbp), %xmm3
movaps %xmm1, %xmm5
subss %xmm3, %xmm5
movaps %xmm2, %xmm4
subss %xmm0, %xmm4
movss %xmm4, 0x20(%rsp)
movss %xmm5, 0x10(%rsp)
addss %xmm5, %xmm4
ucomiss 0xbb0f(%rip), %xmm4     # 0x10098
jne 0x4591
jnp 0x4bab
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rbx
movq 0x20(%rax), %r12
cmpq %r12, %rbx
je 0x4aa8
leaq 0x10(%rbp), %rax
movq %rax, 0xe0(%rsp)
movaps %xmm0, %xmm4
subss %xmm2, %xmm4
subss %xmm1, %xmm3
mulss %xmm0, %xmm3
mulss %xmm1, %xmm4
addss %xmm3, %xmm4
movss %xmm4, 0x88(%rsp)
movss 0x20(%rsp), %xmm0
mulss %xmm0, %xmm0
movss 0x10(%rsp), %xmm1
mulss %xmm1, %xmm1
addss %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtss %xmm1, %xmm0
movss %xmm0, 0x98(%rsp)
movq %rbp, 0x8(%rsp)
movq %r12, 0x80(%rsp)
cmpb $0x0, 0x74(%rbx)
jne 0x4a98
movq 0x18(%rbx), %rax
subq 0x10(%rbx), %rax
cmpq $0x5, %rax
jb 0x4a98
movl 0x60(%rbp), %eax
movl 0x60(%rbx), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x58(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0xe2ec
movl 0x60(%rbx), %eax
movl 0x60(%rbp), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x58(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0xe2ec
movl 0x60(%rbp), %eax
cmpl 0x60(%rbx), %eax
je 0x4a98
movq 0x10(%rbx), %rax
cmpq 0x18(%rbx), %rax
je 0x4a98
cmpq %rbx, %rbp
je 0x4b8c
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x4692
movq %rax, 0x38(%rsp)
movq %rbp, %rax
movq 0x10(%rbp), %rbp
movq 0x18(%rax), %rax
movq %rax, 0xd8(%rsp)
cmpq %rax, %rbp
je 0x499d
leaq 0x10(%rbx), %rax
movq %rax, 0x108(%rsp)
xorl %r13d, %r13d
xorps %xmm0, %xmm0
movss %xmm0, (%rsp)
movq 0x10(%rbx), %r12
movq 0x18(%rbx), %r15
cmpq %r15, %r12
je 0x4756
movl (%rbp), %eax
cmpl (%r12), %eax
jne 0x4708
incl %r13d
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x46fb
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x4708
leaq 0x30(%rsp), %rdi
movq %rbp, %rdx
callq 0xcab4
movl (%r12), %eax
movq (%r14), %rcx
movss 0x4(%rcx,%rax,8), %xmm0
mulss 0x20(%rsp), %xmm0
movss (%rcx,%rax,8), %xmm1
mulss 0x10(%rsp), %xmm1
addss %xmm0, %xmm1
addss 0x88(%rsp), %xmm1
andps 0xb926(%rip), %xmm1     # 0x10060
divss 0x98(%rsp), %xmm1
maxss (%rsp), %xmm1
addq $0x4, %r12
movss %xmm1, (%rsp)
jmp 0x46cd
addq $0x4, %rbp
cmpq 0xd8(%rsp), %rbp
jne 0x46c5
cmpl $0x1, %r13d
jbe 0x487e
movss 0xb91a(%rip), %xmm0     # 0x10094
movss (%rsp), %xmm1
ucomiss %xmm1, %xmm0
movq 0x8(%rsp), %rax
movq 0x80(%rsp), %r12
jae 0x4895
movq 0x30(%rsp), %r15
movq 0x38(%rsp), %rax
movq %rax, 0xd8(%rsp)
cmpq %rax, %r15
je 0x49ac
xorl %r12d, %r12d
xorl %ebp, %ebp
movl (%r15), %edx
leaq 0xbeaf(%rip), %rdi      # 0x1066e
movl 0x2c(%rsp), %esi
xorl %eax, %eax
callq 0x2030
movq 0x8(%rsp), %rax
movq 0x10(%rax), %r13
movq 0x18(%rax), %rdx
cmpq %rdx, %r13
je 0x481e
movl (%r13), %eax
cmpl (%r15), %eax
jne 0x4807
movq %r13, %rsi
addq $0x4, %rsi
cmpq %rdx, %rsi
je 0x480d
subq %rsi, %rdx
movq %r13, %rdi
callq 0x21e0
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdx
jmp 0x4812
addq $0x4, %r13
jmp 0x47d7
movq 0x8(%rsp), %rax
addq $-0x4, %rdx
movq %rdx, 0x18(%rax)
incl %ebp
jmp 0x47d7
movq 0x10(%rbx), %r13
movq 0x18(%rbx), %rdx
cmpq %rdx, %r13
je 0x4862
movl (%r13), %eax
cmpl (%r15), %eax
jne 0x485c
movq %r13, %rsi
addq $0x4, %rsi
cmpq %rdx, %rsi
je 0x484f
subq %rsi, %rdx
movq %r13, %rdi
callq 0x21e0
movq 0x18(%rbx), %rdx
addq $-0x4, %rdx
movq %rdx, 0x18(%rbx)
incl %r12d
jmp 0x4826
addq $0x4, %r13
jmp 0x4826
addq $0x4, %r15
cmpq 0xd8(%rsp), %r15
jne 0x47b5
movq 0x30(%rsp), %r15
jmp 0x49b1
leaq 0xa8(%rsp), %r15
leaq 0x58(%rsp), %r13
movq 0x8(%rsp), %rbp
jmp 0x4a90
movl 0x60(%rax), %edx
movl 0x60(%rbx), %ecx
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
leaq 0xbd3a(%rip), %rdi      # 0x105e3
movl 0x2c(%rsp), %esi
movl %r13d, %r8d
movsd %xmm0, (%rsp)
movb $0x1, %al
callq 0x2030
movq 0x10(%rbx), %r13
movq 0x18(%rbx), %r15
cmpq %r15, %r13
je 0x4966
xorl %ebp, %ebp
movq 0x8(%rsp), %r12
movq 0x10(%r12), %rdi
movq 0x18(%r12), %rsi
movq %r13, %rdx
callq 0xca0e
movq 0x18(%r12), %rsi
cmpq %rsi, %rax
je 0x48fa
movq 0x80(%rsp), %r12
jmp 0x4934
cmpq 0x20(%r12), %rax
je 0x491a
movl (%r13), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%r12)
movq 0x80(%rsp), %r12
jmp 0x4932
movq 0xe0(%rsp), %rdi
movq %r13, %rdx
callq 0xcab4
movq 0x80(%rsp), %r12
incl %ebp
addq $0x4, %r13
cmpq %r15, %r13
jne 0x48cf
testl %ebp, %ebp
je 0x4966
movl 0x60(%rbx), %ecx
movq 0x8(%rsp), %rax
movl 0x60(%rax), %r8d
leaq 0xbcdd(%rip), %rdi      # 0x10631
movl 0x2c(%rsp), %esi
movl %ebp, %edx
movsd (%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movq 0x10(%rbx), %rax
cmpq %rax, 0x18(%rbx)
je 0x4974
movq %rax, 0x18(%rbx)
movq $0x0, 0x58(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movb $0x1, 0x74(%rbx)
incl 0xa4(%rsp)
movl $0x0, 0x54(%rsp)
leaq 0xa8(%rsp), %r15
leaq 0x58(%rsp), %r13
movq 0x8(%rsp), %rbp
jmp 0x4a98
xorl %ebp, %ebp
xorl %r12d, %r12d
movl (%r15), %eax
movl %eax, 0x58(%rsp)
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rsi
cmpq 0x20(%rcx), %rsi
leaq 0x58(%rsp), %r13
je 0x49e0
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rcx)
leaq 0xa8(%rsp), %r15
jmp 0x49f8
movq 0xe0(%rsp), %rdi
movq %r13, %rdx
callq 0xcab4
leaq 0xa8(%rsp), %r15
movq 0x18(%rbx), %r10
cmpq 0x20(%rbx), %r10
je 0x4a14
movl 0x58(%rsp), %r9d
movl %r9d, (%r10)
addq $0x4, %r10
movq %r10, 0x18(%rbx)
jmp 0x4a30
movq 0x108(%rsp), %rdi
movq %r10, %rsi
movq %r13, %rdx
callq 0xcab4
movl 0x58(%rsp), %r9d
movq 0x18(%rbx), %r10
movq 0x8(%rsp), %rax
movl 0x60(%rax), %edx
movq 0x38(%rsp), %rcx
subq 0x30(%rsp), %rcx
shrq $0x2, %rcx
movl 0x60(%rbx), %r8d
movq 0x18(%rax), %r11
subq 0x10(%rax), %r11
shrq $0x2, %r11
subq 0x10(%rbx), %r10
shrq $0x2, %r10
xorps %xmm0, %xmm0
cvtss2sd (%rsp), %xmm0
leaq 0xbc0d(%rip), %rdi      # 0x1067a
movl 0x2c(%rsp), %esi
movb $0x1, %al
pushq %r10
pushq %r11
pushq %r12
pushq %rbp
movq 0x28(%rsp), %rbp
callq 0x2030
addq $0x20, %rsp
movl $0x0, 0x54(%rsp)
movq 0x80(%rsp), %r12
addq $0x90, %rbx
cmpq %r12, %rbx
jne 0x4608
addq $0x90, %rbp
cmpq 0x110(%rsp), %rbp
jne 0x4534
jmp 0x4ac5
movb $0x1, %al
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %ebx
testb $0x1, %bl
je 0x4aeb
movq 0x18(%rsp), %rax
cmpl $0x0, 0x60(%rax)
je 0x4aeb
leaq 0xbc0c(%rip), %rdi      # 0x106ec
movl 0x2c(%rsp), %esi
xorl %eax, %eax
callq 0x2030
incl 0x2c(%rsp)
testb $0x1, %bl
je 0x4508
leaq 0xbbf7(%rip), %rdi      # 0x106f6
movl 0xa4(%rsp), %esi
xorl %eax, %eax
callq 0x2030
movq 0x18(%rsp), %rax
movq 0x18(%rax), %r14
movq 0x20(%rax), %r15
cmpq %r15, %r14
movq 0x90(%rsp), %r12
je 0x4b5b
leaq 0xbbfb(%rip), %rbx      # 0x10729
movq 0x18(%r14), %rax
subq 0x10(%r14), %rax
cmpq $0x4, %rax
jne 0x4b4f
movl 0x60(%r14), %esi
movq %rbx, %rdi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2030
addq $0x90, %r14
cmpq %r15, %r14
jne 0x4b2e
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x4b6a
callq 0x2140
leaq 0xa8(%rsp), %rdi
callq 0xc05a
movl %r12d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xba45(%rip), %rdi      # 0x105d8
leaq 0xb5a6(%rip), %rsi      # 0x10140
leaq 0xba07(%rip), %rcx      # 0x105a8
movl $0x393, %edx            # imm = 0x393
callq 0x20e0
movl 0x60(%rbp), %esi
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm2, %xmm2
cvtss2sd %xmm3, %xmm3
leaq 0xb9bd(%rip), %rdi      # 0x10582
movb $0x4, %al
callq 0x2030
leaq 0xb9d3(%rip), %rdi      # 0x105a6
leaq 0xb566(%rip), %rsi      # 0x10140
leaq 0xb9c7(%rip), %rcx      # 0x105a8
movl $0x37e, %edx            # imm = 0x37E
callq 0x20e0
jmp 0x4cae
jmp 0x4cb3
jmp 0x4cae
jmp 0x4cae
jmp 0x4cb3
movq %rax, %r14
jmp 0x4c1b
movq %rax, %r14
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x4c1b
callq 0x2140
leaq 0x40(%rsp), %rbx
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0x4c44
callq 0x2140
jmp 0x4c44
movq %rax, %r14
leaq 0x40(%rsp), %rbx
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x4cc5
jmp 0x4cc0
movq %rax, %r14
jmp 0x4c67
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x4c67
callq 0x2140
leaq 0xb8(%rsp), %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x4c90
callq 0x2140
jmp 0x4c90
movq %rax, %r14
leaq 0xb8(%rsp), %rbx
movq 0xa8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x4cd2
callq 0x2140
jmp 0x4cd2
jmp 0x4cae
jmp 0x4cae
jmp 0x4cb3
jmp 0x4cb3
jmp 0x4cb3
movq %rax, %r14
jmp 0x4cc5
movq %rax, %r14
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x4cc5
callq 0x2140
leaq 0xa8(%rsp), %rdi
callq 0xc05a
movq %r14, %rdi
callq 0x2200