// File: /workspace/github_cpp_makefile_star2_O1/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 $0x138, %rsp            # imm = 0x138
movq %rdi, %r13
movq 0xc8(%rdi), %rax
cmpq %rax, 0xd0(%rdi)
je 0x39c5
movq %rax, 0xd0(%r13)
movq 0x18(%r13), %r15
movq 0x20(%r13), %rax
movq %rax, 0x50(%rsp)
leaq 0x98(%r13), %rdi
callq 0xca56
movq 0x18(%r13), %rbx
movq 0x20(%r13), %r14
cmpq %r14, %rbx
je 0x3a13
movq %rbx, %rdi
callq 0x53b6
movsd (%rbx), %xmm0
movsd 0x8(%rbx), %xmm1
addps %xmm0, %xmm1
mulps 0xc61a(%rip), %xmm1     # 0x10020
movlps %xmm1, 0x58(%rbx)
addq $0x90, %rbx
jmp 0x39e6
movq 0x50(%rsp), %r12
subq %r15, %r12
movabsq $-0x71c71c71c71c71c7, %rcx # imm = 0x8E38E38E38E38E39
movq 0x18(%r13), %rbx
movq 0x20(%r13), %r14
cmpq %r14, %rbx
je 0x3a76
movq %r14, %rax
subq %rbx, %rax
sarq $0x4, %rax
imulq %rcx, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rbp
leaq -0x12a9(%rip), %r15     # 0x27ae
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rcx
callq 0xcac8
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbp, %r15
callq 0xcc41
sarq $0x4, %r12
movq 0x18(%r13), %rbx
movq %r13, 0x10(%rsp)
movq 0x20(%r13), %r14
cmpq %r14, %rbx
je 0x3ab6
xorl %ebp, %ebp
movl %ebp, 0x60(%rbx)
movq 0x10(%rbx), %rax
cmpq %rax, 0x18(%rbx)
je 0x3a9f
movq %rax, 0x18(%rbx)
leaq 0x28(%rbx), %rdi
callq 0xbe78
addq $0x90, %rbx
incl %ebp
cmpq %r14, %rbx
jne 0x3a8e
movq %r12, %r13
movabsq $-0x71c71c71c71c71c7, %rax # imm = 0x8E38E38E38E38E39
imulq %rax, %r13
movq %r15, 0x88(%rsp)
cmpq %r15, 0x50(%rsp)
movq %r13, 0x48(%rsp)
je 0x3b89
xorl %eax, %eax
movl $0x2, 0x40(%rsp)
xorl %ecx, %ecx
incl %ecx
movq %rcx, 0x8(%rsp)
cmpq %rcx, %r13
jbe 0x3b74
leaq (%rax,%rax,8), %rbx
shlq $0x4, %rbx
movq 0x10(%rsp), %rax
addq 0x18(%rax), %rbx
leaq 0x8(%rbx), %r14
leaq 0x28(%rbx), %r15
leaq 0x60(%rbx), %r12
movl 0x40(%rsp), %ebp
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rcx
leaq (%rax,%rax,8), %rax
shlq $0x4, %rax
leaq (%rcx,%rax), %r13
addq %rax, %rcx
addq $0x8, %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2501
testb %al, %al
je 0x3b66
leaq 0x60(%r13), %rsi
movq %r15, %rdi
callq 0xdd88
addq $0x28, %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xdd88
movl %ebp, %eax
incl %ebp
movq 0x48(%rsp), %r13
cmpq %rax, %r13
ja 0x3b1d
incl 0x40(%rsp)
movq 0x8(%rsp), %rcx
movq %rcx, %rax
cmpq %rcx, %r13
ja 0x3aeb
movq 0x50(%rsp), %rax
cmpq 0x88(%rsp), %rax
movq 0x10(%rsp), %rbp
je 0x3cab
xorl %eax, %eax
xorl %r15d, %r15d
movq 0x18(%rbp), %r14
leaq (%rax,%rax,8), %r12
shlq $0x4, %r12
cmpq $0x1, 0x50(%r14,%r12)
jne 0x3c9c
leaq (%r14,%r12), %rbx
cmpl $0x0, 0x60(%rbp)
je 0x3bde
movl 0x60(%rbx), %esi
leaq 0xc826(%rip), %rdi      # 0x103f8
movl $0x1, %edx
xorl %eax, %eax
callq 0x2030
leaq (%r14,%r12), %rax
addq $0x28, %rax
movq %rax, 0x40(%rsp)
xorl %ebp, %ebp
cmpl %ebp, %r15d
je 0x3c7d
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
leaq (,%rbp,8), %rcx
addq %rbp, %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %r14
addq $0x30, %r14
movq 0x10(%r14), %r13
cmpq %r14, %r13
je 0x3c7d
leaq (%rax,%rcx), %rdx
movq %rdx, 0x8(%rsp)
leaq (%rax,%rcx), %r12
addq $0x28, %r12
movl 0x60(%rbx), %esi
cmpl %esi, 0x20(%r13)
jne 0x3c6d
movq 0x10(%rsp), %rax
cmpl $0x0, 0x60(%rax)
je 0x3c5a
movq 0x8(%rsp), %rax
movl 0x60(%rax), %edx
leaq 0xc7cc(%rip), %rdi      # 0x1041f
xorl %eax, %eax
callq 0x2030
movq %r12, %rdi
movq %r13, %rsi
callq 0xde98
movq %rax, %r13
xorl %r15d, %r15d
jmp 0x3c78
movq %r13, %rdi
callq 0x2180
movq %rax, %r13
cmpq %r14, %r13
jne 0x3c30
incl %ebp
movq 0x48(%rsp), %r13
cmpq %rbp, %r13
ja 0x3bed
movq 0x40(%rsp), %rdi
callq 0xbe78
movq 0x10(%rsp), %rbp
incl %r15d
movq %r15, %rax
cmpq %r15, %r13
ja 0x3ba6
cmpl $0x2, 0x60(%rbp)
jbe 0x3e92
movq 0x18(%rbp), %r14
movq 0x20(%rbp), %rax
movq %rax, 0x48(%rsp)
cmpq %rax, %r14
je 0x3e92
leaq 0xb0(%rsp), %rbx
leaq 0x30(%rsp), %r15
leaq 0x58(%rsp), %r12
movl $0xd1b71759, %r13d      # imm = 0xD1B71759
movq %rbx, 0xa0(%rsp)
movq $0x0, 0xa8(%rsp)
movb $0x0, 0xb0(%rsp)
movq 0x40(%r14), %rbp
movq %r14, 0x8(%rsp)
addq $0x30, %r14
cmpq %r14, %rbp
je 0x3e26
movl 0x20(%rbp), %ebx
movl $0x1, %eax
cmpl $0xa, %ebx
jb 0x3d61
movl $0x4, %eax
movl %ebx, %ecx
cmpl $0x63, %ecx
jbe 0x3d5a
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x3d5f
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x3d61
movl %ecx, %edx
imulq %r13, %rdx
shrq $0x2d, %rdx
addl $0x4, %eax
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x3d29
addl $-0x3, %eax
jmp 0x3d61
addl $-0x2, %eax
jmp 0x3d61
decl %eax
movl %eax, %esi
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
movq %r12, %rdi
xorl %edx, %edx
callq 0x2190
movq 0x58(%rsp), %rdi
movl 0x60(%rsp), %esi
movl %ebx, %edx
callq 0xbea5
movq %r12, %rdi
leaq 0xcce3(%rip), %rsi      # 0x10a74
callq 0x2230
movq %r15, 0x20(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x3db9
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x3dc0
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0x28(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0xa0(%rsp), %rdi
callq 0x2060
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x3dfe
callq 0x2140
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x3e12
callq 0x2140
movq %rbp, %rdi
callq 0x2180
movq %rax, %rbp
cmpq %r14, %rax
jne 0x3d15
cmpq $0x0, 0xa8(%rsp)
je 0x3e3e
leaq 0xa0(%rsp), %rdi
callq 0x21a0
movq 0x8(%rsp), %r14
movl 0x50(%r14), %edx
movl 0x60(%r14), %esi
movq 0xa0(%rsp), %rcx
leaq 0xc5f5(%rip), %rdi      # 0x1044f
xorl %eax, %eax
callq 0x2030
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rbx
cmpq %rbx, %rdi
movq 0x10(%rsp), %rbp
je 0x3e80
callq 0x2140
addq $0x90, %r14
cmpq 0x48(%rsp), %r14
jne 0x3ce3
leaq 0xc8(%rbp), %rax
movq %rax, 0xf8(%rsp)
leaq 0xa8(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq $0x0, 0x98(%rsp)
movq %rax, 0x20(%rcx)
movq 0x18(%rbp), %r13
movq 0x20(%rbp), %rax
movq %rax, 0xe0(%rsp)
cmpq %rax, %r13
je 0x4250
leaq 0xa0(%rsp), %r15
leaq 0x20(%rsp), %r12
movq $0x0, 0x98(%rsp)
movq 0x40(%r13), %rax
leaq 0x30(%r13), %rcx
movq %rcx, 0x88(%rsp)
cmpq %rcx, %rax
je 0x423b
movq %rax, 0x40(%rsp)
movl 0x20(%rax), %eax
movq 0x18(%rbp), %rcx
leaq (%rax,%rax,8), %rbx
shlq $0x4, %rbx
movl 0x60(%r13), %eax
movq %rcx, %r14
movl 0x60(%rcx,%rbx), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x20(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0xded0
leaq 0xa8(%rsp), %rcx
cmpq %rcx, %rax
jne 0x4223
addq %rbx, %r14
movq $0x0, 0x80(%rsp)
movq %r13, %rdi
movq %r14, %rsi
leaq 0x80(%rsp), %rdx
callq 0x26d6
testb %al, %al
je 0x4223
movq %r14, 0x8(%rsp)
movq 0xd0(%rbp), %rax
subq 0xc8(%rbp), %rax
shrq $0x3, %rax
movl %eax, 0x58(%rsp)
movq 0xc8(%rbp), %rcx
xorl %ebx, %ebx
cmpq %rcx, 0xd0(%rbp)
je 0x40e5
xorl %r14d, %r14d
movss (%rcx,%rbx,8), %xmm1
subss 0x80(%rsp), %xmm1
movss 0x4(%rcx,%rbx,8), %xmm0
subss 0x84(%rsp), %xmm0
mulss %xmm0, %xmm0
mulss %xmm1, %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x48(%rsp)
ucomiss 0xc08d(%rip), %xmm1     # 0x10080
jae 0x40b4
movq %rcx, 0x50(%rsp)
cmpl $0x4, 0x60(%rbp)
jb 0x408a
movl 0x60(%r13), %esi
movq 0x8(%rsp), %rax
movl 0x60(%rax), %edx
leaq 0xc45c(%rip), %rdi      # 0x10477
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2030
movq 0x10(%rsp), %rax
movq 0x18(%rax), %r12
movq 0x20(%rax), %r14
cmpq %r14, %r12
je 0x408a
movl 0x60(%r12), %eax
movq %r13, %r15
cmpl 0x60(%r13), %eax
je 0x407b
movq 0x8(%rsp), %rcx
cmpl 0x60(%rcx), %eax
je 0x407b
movq 0x10(%r12), %rbp
movq 0x18(%r12), %r13
cmpq %r13, %rbp
je 0x407b
cmpl %ebx, (%rbp)
jne 0x4075
movl 0x60(%r12), %esi
leaq 0xc457(%rip), %rdi      # 0x104c5
xorl %eax, %eax
callq 0x2030
addq $0x4, %rbp
jmp 0x4058
addq $0x90, %r12
cmpq %r14, %r12
movq %r15, %r13
jne 0x4036
movl %ebx, 0x58(%rsp)
movq 0x50(%rsp), %rax
movq (%rax,%rbx,8), %rax
movq %rax, 0x80(%rsp)
movb $0x1, %r14b
movq 0x10(%rsp), %rbp
leaq 0xa0(%rsp), %r15
leaq 0x20(%rsp), %r12
movss 0x48(%rsp), %xmm0
ucomiss 0xbfbf(%rip), %xmm0     # 0x10080
jb 0x40e8
incl %ebx
movq 0xc8(%rbp), %rcx
movq 0xd0(%rbp), %rax
subq %rcx, %rax
sarq $0x3, %rax
cmpq %rbx, %rax
ja 0x3fbd
jmp 0x40e8
xorl %r14d, %r14d
testb $0x1, %r14b
movq 0x8(%rsp), %rbx
jne 0x412d
movq 0xd0(%rbp), %rsi
cmpq 0xd8(%rbp), %rsi
je 0x4118
movq 0x80(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0xd0(%rbp)
jmp 0x412d
movq 0xf8(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0xdf38
cmpl $0x3, 0x60(%rbp)
jb 0x4154
movl 0x58(%rsp), %esi
movl 0x60(%r13), %edx
movl 0x60(%rbx), %ecx
andb $0x1, %r14b
movzbl %r14b, %r8d
leaq 0xc38d(%rip), %rdi      # 0x104da
xorl %eax, %eax
callq 0x2030
movq %r13, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
xorl %ebx, %ebx
movq 0x20(%rsp,%rbx), %rax
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x58(%rsp), %rdx
callq 0xc8a4
movq 0x20(%rsp,%rbx), %rdi
movq 0x18(%rdi), %rsi
cmpq %rsi, %rax
je 0x41a2
cmpl $0x2, 0x60(%rbp)
jb 0x41c6
movl 0x58(%rsp), %esi
movl 0x60(%rdi), %edx
leaq 0xc376(%rip), %rdi      # 0x1050f
xorl %eax, %eax
callq 0x2030
jmp 0x41c6
cmpq 0x20(%rdi), %rsi
je 0x41b8
movl 0x58(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rdi)
jmp 0x41c6
addq $0x10, %rdi
leaq 0x58(%rsp), %rdx
callq 0xc93e
addq $0x8, %rbx
cmpq $0x10, %rbx
jne 0x4160
movl 0x60(%r13), %eax
movq 0x8(%rsp), %rbx
movl 0x60(%rbx), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x20(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0xe076
movl 0x60(%rbx), %eax
movl 0x60(%r13), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x20(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0xe076
movq 0x98(%rsp), %rax
incl %eax
movq %rax, 0x98(%rsp)
movq 0x40(%rsp), %rdi
callq 0x2180
cmpq 0x88(%rsp), %rax
jne 0x3f18
addq $0x90, %r13
cmpq 0xe0(%rsp), %r13
jne 0x3eff
cmpl $0x0, 0x60(%rbp)
je 0x4276
movq 0xd0(%rbp), %rsi
subq 0xc8(%rbp), %rsi
shrq $0x3, %rsi
leaq 0xc2d1(%rip), %rdi      # 0x10540
xorl %eax, %eax
callq 0x2030
cmpl $0x3, 0x60(%rbp)
jb 0x4450
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rbx
movq 0x20(%rax), %rax
movq %rax, 0x48(%rsp)
cmpq %rax, %rbx
je 0x4450
leaq 0x30(%rsp), %r14
leaq 0x68(%rsp), %r12
movl $0xd1b71759, %ebp       # imm = 0xD1B71759
movq %r14, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
movq 0x10(%rbx), %r14
movq %rbx, 0x8(%rsp)
movq 0x18(%rbx), %r13
cmpq %r13, %r14
je 0x43f1
movl (%r14), %ebx
movl $0x1, %eax
cmpl $0xa, %ebx
jb 0x431f
movl $0x4, %eax
movl %ebx, %ecx
cmpl $0x63, %ecx
jbe 0x4318
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x431d
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x431f
movl %ecx, %edx
imulq %rbp, %rdx
shrq $0x2d, %rdx
addl $0x4, %eax
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x42e7
addl $-0x3, %eax
jmp 0x431f
addl $-0x2, %eax
jmp 0x431f
decl %eax
movl %eax, %esi
leaq 0x110(%rsp), %rax
movq %rax, 0x100(%rsp)
leaq 0x100(%rsp), %r15
movq %r15, %rdi
xorl %edx, %edx
callq 0x2190
movq 0x100(%rsp), %rdi
movl 0x108(%rsp), %esi
movl %ebx, %edx
callq 0xbea5
movq %r15, %rdi
leaq 0xc711(%rip), %rsi      # 0x10a74
callq 0x2230
movq %r12, 0x58(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x438b
movq %rdx, 0x58(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x68(%rsp)
jmp 0x4393
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 0x20(%rsp), %rdi
callq 0x2060
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x43ce
callq 0x2140
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x43e8
callq 0x2140
addq $0x4, %r14
jmp 0x42ca
cmpq $0x0, 0x28(%rsp)
je 0x4403
leaq 0x20(%rsp), %rdi
callq 0x21a0
movq 0x8(%rsp), %rbx
movl 0x60(%rbx), %esi
movq 0x18(%rbx), %rdx
subq 0x10(%rbx), %rdx
shrq $0x2, %rdx
movq 0x20(%rsp), %rcx
leaq 0xc134(%rip), %rdi      # 0x10557
xorl %eax, %eax
callq 0x2030
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %r14
cmpq %r14, %rdi
je 0x443e
callq 0x2140
addq $0x90, %rbx
cmpq 0x48(%rsp), %rbx
jne 0x42aa
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0xa0(%rsp), %r15
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x94(%rsp)
movq 0x10(%rsp), %rbx
movq %r15, %rdi
callq 0xe1ca
movq 0x18(%rbx), %rbp
movq 0x20(%rbx), %r12
cmpq %r12, %rbp
je 0x4a2b
movb $0x1, %al
movl %eax, 0x7c(%rsp)
leaq 0x58(%rsp), %rbx
movq %r12, 0xd0(%rsp)
cmpb $0x0, 0x74(%rbp)
jne 0x4a15
movq 0x18(%rbp), %rax
subq 0x10(%rbp), %rax
cmpq $0x5, %rax
jb 0x4a15
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, 0x50(%rsp)
movss %xmm5, 0x40(%rsp)
addss %xmm5, %xmm4
ucomiss 0xbb84(%rip), %xmm4     # 0x10088
jne 0x450c
jnp 0x4b0a
movq 0x10(%rsp), %rax
movq 0x18(%rax), %r14
movq 0x20(%rax), %r13
cmpq %r13, %r14
je 0x4a15
leaq 0x10(%rbp), %rax
movq %rax, 0xf0(%rsp)
movaps %xmm0, %xmm4
subss %xmm2, %xmm4
subss %xmm1, %xmm3
mulss %xmm0, %xmm3
mulss %xmm1, %xmm4
addss %xmm3, %xmm4
movss %xmm4, 0x88(%rsp)
movss 0x50(%rsp), %xmm0
mulss %xmm0, %xmm0
movss 0x40(%rsp), %xmm1
mulss %xmm1, %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x48(%rsp)
xorps %xmm0, %xmm0
sqrtss %xmm1, %xmm0
movss %xmm0, 0xe0(%rsp)
movq %r13, 0xd8(%rsp)
cmpb $0x0, 0x74(%r14)
jne 0x4a05
movq 0x18(%r14), %rax
subq 0x10(%r14), %rax
cmpq $0x5, %rax
jb 0x4a05
movl 0x60(%rbp), %eax
movl 0x60(%r14), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x58(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0xe076
movl 0x60(%r14), %eax
movl 0x60(%rbp), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x58(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0xe076
movl 0x60(%rbp), %eax
cmpl 0x60(%r14), %eax
je 0x4a05
movq 0x10(%r14), %rax
cmpq 0x18(%r14), %rax
je 0x4a05
cmpq %r14, %rbp
je 0x4aeb
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x4612
movq %rax, 0x28(%rsp)
movq 0x10(%rbp), %rbx
movq 0x18(%rbp), %rax
movq %rax, 0x130(%rsp)
cmpq %rax, %rbx
je 0x4725
xorl %r13d, %r13d
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x10(%r14), %r12
movq 0x18(%r14), %r15
cmpq %r15, %r12
je 0x4711
movl (%rbx), %eax
cmpl (%r12), %eax
jne 0x4679
incl %r13d
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x466c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x4679
leaq 0x20(%rsp), %rdi
movq %rbx, %rdx
callq 0xc93e
movl (%r12), %eax
movq 0xf8(%rsp), %rcx
movq (%rcx), %rcx
movss 0x4(%rcx,%rax,8), %xmm2
mulss 0x50(%rsp), %xmm2
movss (%rcx,%rax,8), %xmm1
mulss 0x40(%rsp), %xmm1
movss 0x48(%rsp), %xmm0
ucomiss 0xb9dc(%rip), %xmm0     # 0x10088
movss 0xe0(%rsp), %xmm0
jae 0x46e4
movss 0x48(%rsp), %xmm0
movaps %xmm1, 0x120(%rsp)
movss %xmm2, 0xec(%rsp)
callq 0x2220
movss 0xec(%rsp), %xmm2
movaps 0x120(%rsp), %xmm1
addss %xmm2, %xmm1
addss 0x88(%rsp), %xmm1
andps 0xb968(%rip), %xmm1     # 0x10060
divss %xmm0, %xmm1
maxss 0x8(%rsp), %xmm1
addq $0x4, %r12
movss %xmm1, 0x8(%rsp)
jmp 0x463f
addq $0x4, %rbx
cmpq 0x130(%rsp), %rbx
jne 0x4637
jmp 0x4731
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
xorl %r13d, %r13d
cmpl $0x1, %r13d
jbe 0x4815
movss 0xb941(%rip), %xmm0     # 0x10084
movss 0x8(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jae 0x4827
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rax
movq %rax, 0x120(%rsp)
cmpq %rax, %r15
je 0x4925
xorl %r12d, %r12d
xorl %r13d, %r13d
movl (%r15), %edx
leaq 0xbee1(%rip), %rdi      # 0x1065e
movl 0x1c(%rsp), %esi
xorl %eax, %eax
callq 0x2030
movq 0x10(%rbp), %rbx
movq 0x18(%rbp), %rdx
cmpq %rdx, %rbx
je 0x47c3
movl (%rbx), %eax
cmpl (%r15), %eax
jne 0x47bd
movq %rbx, %rsi
addq $0x4, %rsi
cmpq %rdx, %rsi
je 0x47b3
subq %rsi, %rdx
movq %rbx, %rdi
callq 0x21e0
addq $-0x4, 0x18(%rbp)
incl %r13d
jmp 0x478c
addq $0x4, %rbx
jmp 0x478c
movq 0x10(%r14), %rbx
movq 0x18(%r14), %rdx
cmpq %rdx, %rbx
je 0x47fe
movl (%rbx), %eax
cmpl (%r15), %eax
jne 0x47f8
movq %rbx, %rsi
addq $0x4, %rsi
cmpq %rdx, %rsi
je 0x47ee
subq %rsi, %rdx
movq %rbx, %rdi
callq 0x21e0
addq $-0x4, 0x18(%r14)
incl %r12d
jmp 0x47c7
addq $0x4, %rbx
jmp 0x47c7
addq $0x4, %r15
cmpq 0x120(%rsp), %r15
jne 0x4773
jmp 0x492b
leaq 0xa0(%rsp), %r15
leaq 0x58(%rsp), %rbx
jmp 0x49f5
movl 0x60(%rbp), %edx
movl 0x60(%r14), %ecx
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
leaq 0xbd97(%rip), %rdi      # 0x105d3
movl 0x1c(%rsp), %esi
movl %r13d, %r8d
movsd %xmm0, 0x8(%rsp)
movb $0x1, %al
callq 0x2030
movq 0x10(%r14), %r13
movq 0x18(%r14), %r15
xorl %ebx, %ebx
cmpq %r15, %r13
je 0x48ac
movq 0xf0(%rsp), %r12
movq 0x10(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq %r13, %rdx
callq 0xc8a4
movq 0x18(%rbp), %rsi
cmpq %rsi, %rax
jne 0x48a3
cmpq 0x20(%rbp), %rsi
je 0x4896
movl (%r13), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rbp)
jmp 0x48a1
movq %r12, %rdi
movq %r13, %rdx
callq 0xc93e
incl %ebx
addq $0x4, %r13
cmpq %r15, %r13
jne 0x4867
testl %ebx, %ebx
je 0x48d2
movl 0x60(%r14), %ecx
movl 0x60(%rbp), %r8d
leaq 0xbd62(%rip), %rdi      # 0x10621
movl 0x1c(%rsp), %esi
movl %ebx, %edx
movsd 0x8(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movq 0x10(%r14), %rax
cmpq %rax, 0x18(%r14)
leaq 0xa0(%rsp), %r15
movq 0xd0(%rsp), %r12
movq 0xd8(%rsp), %r13
je 0x48f8
movq %rax, 0x18(%r14)
movq $0x0, 0x58(%r14)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movb $0x1, 0x74(%r14)
incl 0x94(%rsp)
movl $0x0, 0x7c(%rsp)
leaq 0x58(%rsp), %rbx
jmp 0x4a05
xorl %r13d, %r13d
xorl %r12d, %r12d
movq 0x20(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x58(%rsp)
movq 0x18(%rbp), %rsi
cmpq 0x20(%rbp), %rsi
je 0x4951
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rbp)
leaq 0x58(%rsp), %rbx
jmp 0x4966
movq 0xf0(%rsp), %rdi
leaq 0x58(%rsp), %rbx
movq %rbx, %rdx
callq 0xc93e
movq 0x18(%r14), %rsi
cmpq 0x20(%r14), %rsi
je 0x4980
movl 0x58(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%r14)
jmp 0x498c
leaq 0x10(%r14), %rdi
movq %rbx, %rdx
callq 0xc93e
movl 0x60(%rbp), %edx
movq 0x28(%rsp), %rcx
subq 0x20(%rsp), %rcx
shrq $0x2, %rcx
movl 0x60(%r14), %r8d
movl 0x58(%rsp), %r9d
movq 0x18(%rbp), %r10
subq 0x10(%rbp), %r10
shrq $0x2, %r10
movq 0x18(%r14), %r11
subq 0x10(%r14), %r11
shrq $0x2, %r11
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
leaq 0xbc9c(%rip), %rdi      # 0x1066a
movl 0x1c(%rsp), %esi
movb $0x1, %al
pushq %r11
pushq %r10
pushq %r12
pushq %r13
callq 0x2030
addq $0x20, %rsp
movl $0x0, 0x7c(%rsp)
leaq 0xa0(%rsp), %r15
movq 0xd0(%rsp), %r12
movq 0xd8(%rsp), %r13
addq $0x90, %r14
cmpq %r13, %r14
jne 0x4584
addq $0x90, %rbp
cmpq %r12, %rbp
jne 0x44af
movl 0x7c(%rsp), %ebp
jmp 0x4a2e
movb $0x1, %bpl
testb $0x1, %bpl
movq 0x10(%rsp), %rbx
je 0x4a51
cmpl $0x0, 0x60(%rbx)
je 0x4a51
leaq 0xbc96(%rip), %rdi      # 0x106dc
movl 0x1c(%rsp), %esi
xorl %eax, %eax
callq 0x2030
incl 0x1c(%rsp)
testb $0x1, %bpl
je 0x4483
leaq 0xbc80(%rip), %rdi      # 0x106e6
movl 0x94(%rsp), %esi
xorl %eax, %eax
callq 0x2030
movq 0x18(%rbx), %r14
movq 0x20(%rbx), %r15
cmpq %r15, %r14
je 0x4ab5
leaq 0xbc91(%rip), %rbx      # 0x10719
movq 0x18(%r14), %rax
subq 0x10(%r14), %rax
cmpq $0x4, %rax
jne 0x4aa9
movl 0x60(%r14), %esi
movq %rbx, %rdi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2030
addq $0x90, %r14
cmpq %r15, %r14
jne 0x4a88
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4ac4
callq 0x2140
leaq 0xa0(%rsp), %rdi
callq 0xbf12
movq 0x98(%rsp), %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbad6(%rip), %rdi      # 0x105c8
leaq 0xb637(%rip), %rsi      # 0x10130
leaq 0xba98(%rip), %rcx      # 0x10598
movl $0x393, %edx            # imm = 0x393
callq 0x20e0
movl 0x60(%rbp), %esi
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm2, %xmm2
cvtss2sd %xmm3, %xmm3
leaq 0xba4e(%rip), %rdi      # 0x10572
movb $0x4, %al
callq 0x2030
leaq 0xba64(%rip), %rdi      # 0x10596
leaq 0xb5f7(%rip), %rsi      # 0x10130
leaq 0xba58(%rip), %rcx      # 0x10598
movl $0x37e, %edx            # imm = 0x37E
callq 0x20e0
jmp 0x4c0d
jmp 0x4c12
jmp 0x4c0d
jmp 0x4c0d
jmp 0x4c12
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x4b84
callq 0x2140
jmp 0x4b84
movq %rax, %rbx
leaq 0x30(%rsp), %r14
jmp 0x4ba3
movq %rax, %rbx
leaq 0x30(%rsp), %r14
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x4ba3
callq 0x2140
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x4c24
jmp 0x4c1f
movq %rax, %rbx
jmp 0x4bc6
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x4bc6
callq 0x2140
leaq 0xb0(%rsp), %r14
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x4bef
callq 0x2140
jmp 0x4bef
movq %rax, %rbx
leaq 0xb0(%rsp), %r14
movq 0xa0(%rsp), %rdi
cmpq %r14, %rdi
je 0x4c31
callq 0x2140
jmp 0x4c31
jmp 0x4c0d
jmp 0x4c0d
jmp 0x4c12
jmp 0x4c12
jmp 0x4c12
movq %rax, %rbx
jmp 0x4c24
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4c24
callq 0x2140
leaq 0xa0(%rsp), %rdi
callq 0xbf12
movq %rbx, %rdi
callq 0x2200