// File: /workspace/github_cpp_makefile_star2_O2/micahcc[P]polygon_skeleton/voronoi.cpp
// Function: Voronoi::Implementation::compute(std::vector<Vector, std::allocator<Vector>> const&)
void Voronoi::Implementation::compute(const std::vector<Point>& points)
{
    m_points = &points;
    for(const auto& pt : points) {
        m_min_x = std::min<double>(pt.x, m_min_x);
        m_max_x = std::max<double>(pt.x, m_max_x);
        m_min_y = std::min<double>(pt.y, m_min_y);
        m_max_y = std::max<double>(pt.y, m_max_y);
    }

    std::cerr << "Sorting points" << std::endl;
    // Sort by decreasing y
    std::vector<size_t> ordered(points.size());
    for(size_t ii = 0; ii < points.size(); ii++) ordered[ii] = ii;
    std::sort(ordered.begin(), ordered.end(),
            [&](size_t ii, size_t jj) { return points[ii].y > points[jj].y; });

    // stop when circle event's centers are after this
    double last_y = points[ordered.back()].y;

    std::cerr << "Ordered points: " << std::endl;
    for(size_t ii : ordered) {
        std::cerr << points[ii] << std::endl;
    }
    std::cerr << std::endl;

    // Travel downward so at each step take
    size_t ii = 0;
    double prev_sweep = NAN;
    double sweep = NAN;
    while(!m_events.empty() || ii < ordered.size()) {
        std::cerr << "Remaining Points: " << (ordered.size() - ii) << std::endl;
        std::cerr << "Remaining Events: " << m_events.size() << std::endl;

        if(m_events.empty()) {
            std::cerr << "Events Empty, processing next point" << std::endl;
            sweep = points[ordered[ii]].y;
            draw_state(m_beach, m_events, prev_sweep, sweep);
            prev_sweep = sweep;
            processPoint(points[ordered[ii]]);
            ii++;
        } else if(ii == ordered.size()) {
            std::cerr << "Points Done, processing next event" << std::endl;
            auto evt = m_events.back(); // greater y's first (decreasing y)
            std::cerr << evt.circle.center.y << std::endl;
            sweep = evt.circle.center.y - evt.circle.radius;
            draw_state(m_beach, m_events, prev_sweep, sweep);
            prev_sweep = sweep;
            m_events.pop_back();
            processEvent(evt);
        } else {
            auto evt = m_events.back(); // greater y's first (decreasing y)
            std::cerr << "Next point: " << points[ordered[ii]].y
                << ", Next Event: " << evt.circle.center.y - evt.circle.radius
                << std::endl;
            if(points[ordered[ii]].y > evt.circle.center.y - evt.circle.radius) {
                sweep = points[ordered[ii]].y;
                draw_state(m_beach, m_events, prev_sweep, sweep);
                prev_sweep = sweep;
                processPoint(points[ordered[ii]]);
                ii++;
            } else {
                sweep = evt.circle.center.y - evt.circle.radius;
                draw_state(m_beach, m_events, prev_sweep, sweep);
                    prev_sweep = sweep;
                m_events.pop_back();
                processEvent(evt);
            }
        }

        std::cerr << "Final Beach: " << std::endl;
        for(const auto& inter: m_beach) {
            std::cerr << "(" << inter.pt_left << ", " << inter.pt_right << ")";
            if(inter.pt_left) std::cerr << "Point 0: " << *inter.pt_left << " ";
            if(inter.pt_right) std::cerr << "Point 1: " << *inter.pt_right << " ";
            std::cerr << std::endl;
        }

        std::cerr << "Final Events: " << std::endl;
        for(const auto& evt: m_events) {
            std::cerr << "at " << (evt.circle.center.y - evt.circle.radius)
                << "( "
                << evt.left_int.pt_left << ", "
                << evt.left_int.pt_right << ")"
                << " -- "
                << evt.right_int.pt_left << ", ("
                << evt.right_int.pt_right << ")"
                << std::endl;
        }

        for(const auto& tup_node: m_nodes) {
            assert(tup_node.second != nullptr);
            std::cerr << tup_node.second->x << ", "
                << tup_node.second->y << std::endl;
        }
    }

    //return voronoi;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r12
movq %rsi, 0xe0(%rdi)
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
movsd 0x70(%rdi), %xmm0
movsd 0x78(%rdi), %xmm1
movsd 0x80(%rdi), %xmm2
movq %rdi, -0x30(%rbp)
movsd 0x88(%rdi), %xmm3
movq -0x30(%rbp), %rdx
cmpq %rcx, %rax
je 0x7bf9
cvtss2sd (%rax), %xmm4
minsd %xmm4, %xmm0
movsd %xmm0, 0x70(%rdx)
maxsd %xmm4, %xmm1
movsd %xmm1, 0x78(%rdx)
cvtss2sd 0x4(%rax), %xmm4
minsd %xmm4, %xmm2
movsd %xmm2, 0x80(%rdx)
maxsd %xmm4, %xmm3
movsd %xmm3, 0x88(%rdx)
addq $0x8, %rax
jmp 0x7bbb
movq 0xc3f0(%rip), %rdi      # 0x13ff0
leaq 0x5ce1(%rip), %rsi      # 0xd8e8
callq 0x31f0
movq %rax, %rdi
callq 0x30d0
movq 0x8(%r12), %rsi
subq (%r12), %rsi
sarq $0x3, %rsi
leaq -0x68(%rbp), %rbx
leaq -0xb0(%rbp), %rdx
movq %rbx, %rdi
callq 0x9368
movq 0x8(%r12), %rax
subq (%r12), %rax
sarq $0x3, %rax
xorl %ecx, %ecx
movq (%rbx), %r14
cmpq %rcx, %rax
je 0x7c54
movq %rcx, (%r14,%rcx,8)
incq %rcx
jmp 0x7c46
movq -0x60(%rbp), %rbx
cmpq %rbx, %r14
je 0x7cc7
movq %rbx, %r15
subq %r14, %r15
movq %r15, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rcx
callq 0x877e
cmpq $0x81, %r15
jl 0x7cb9
leaq 0x80(%r14), %r15
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x89db
cmpq %rbx, %r15
je 0x7cc7
movq %r15, %rdi
movq %r12, %rsi
callq 0x8a5c
addq $0x8, %r15
jmp 0x7ca3
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x89db
movq 0xc322(%rip), %rdi      # 0x13ff0
leaq 0x5c22(%rip), %rsi      # 0xd8f7
callq 0x31f0
movq %rax, %rdi
callq 0x30d0
movq -0x68(%rbp), %r14
movq -0x60(%rbp), %r15
movq 0xc2ff(%rip), %rbx      # 0x13ff0
cmpq %r15, %r14
je 0x7d17
movq (%r14), %rsi
shlq $0x3, %rsi
addq (%r12), %rsi
movq %rbx, %rdi
callq 0x62cf
movq %rbx, %rdi
callq 0x30d0
addq $0x8, %r14
jmp 0x7cf1
movq 0xc2d2(%rip), %rdi      # 0x13ff0
callq 0x30d0
movq %r12, -0x50(%rbp)
movq -0x30(%rbp), %rax
leaq 0x40(%rax), %rcx
movq %rcx, -0x48(%rbp)
leaq 0x48(%rax), %rcx
movq %rcx, -0x78(%rbp)
leaq 0x10(%rax), %rcx
movq %rcx, -0x70(%rbp)
leaq 0x18(%rax), %rcx
movq %rcx, -0xc0(%rbp)
addq $0xa0, %rax
movq %rax, -0xb8(%rbp)
movsd 0x5505(%rip), %xmm0     # 0xd268
movsd %xmm0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq 0xc279(%rip), %r13      # 0x13ff0
leaq 0x5309(%rip), %r15      # 0xd087
leaq 0x5c70(%rip), %rbx      # 0xd9f5
movq -0x30(%rbp), %rax
cmpq $0x0, 0x68(%rax)
jne 0x7da6
movq -0x60(%rbp), %rax
subq -0x68(%rbp), %rax
sarq $0x3, %rax
cmpq %rax, -0x38(%rbp)
jae 0x8278
movq %r13, %rdi
leaq 0x5b58(%rip), %rsi      # 0xd908
callq 0x31f0
movq -0x60(%rbp), %rsi
subq -0x68(%rbp), %rsi
sarq $0x3, %rsi
subq -0x38(%rbp), %rsi
movq %rax, %rdi
callq 0x3140
movq %rax, %rdi
callq 0x30d0
movq %r13, %rdi
leaq 0x5b3c(%rip), %rsi      # 0xd91b
callq 0x31f0
movq -0x30(%rbp), %rcx
movq 0x68(%rcx), %rsi
movq %rax, %rdi
callq 0x3140
movq %rax, %rdi
callq 0x30d0
movq -0x30(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x7ec5
movq -0x60(%rbp), %rax
subq -0x68(%rbp), %rax
sarq $0x3, %rax
cmpq %rax, -0x38(%rbp)
jne 0x7f31
movq %r13, %rdi
leaq 0x5b27(%rip), %rsi      # 0xd952
callq 0x31f0
movq %rax, %rdi
callq 0x30d0
movq -0x78(%rbp), %rdi
callq 0x3120
movups 0x20(%rax), %xmm0
movups 0x30(%rax), %xmm1
movupd 0x40(%rax), %xmm2
movapd %xmm2, -0x90(%rbp)
movaps %xmm0, -0xb0(%rbp)
movaps %xmm1, -0xa0(%rbp)
movss -0x8c(%rbp), %xmm0
movq %r13, %rdi
callq 0x3170
movq %rax, %rdi
callq 0x30d0
movss -0x8c(%rbp), %xmm0
subss -0x88(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movq -0x70(%rbp), %rdi
movq -0x48(%rbp), %rsi
movsd -0x40(%rbp), %xmm0
movsd %xmm1, -0x40(%rbp)
callq 0x93b9
movq -0x48(%rbp), %rdi
callq 0x940a
movq -0x30(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x64a0
jmp 0x805f
movq %r13, %rdi
leaq 0x5a5f(%rip), %rsi      # 0xd92e
callq 0x31f0
movq %rax, %rdi
callq 0x30d0
movq -0x68(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x50(%rbp), %rcx
movq (%rcx), %rcx
cvtss2sd 0x4(%rcx,%rax,8), %xmm1
movq -0x70(%rbp), %rdi
movq -0x48(%rbp), %rsi
movsd -0x40(%rbp), %xmm0
movsd %xmm1, -0x40(%rbp)
callq 0x93b9
movq -0x68(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
shlq $0x3, %rsi
movq -0x50(%rbp), %rax
addq (%rax), %rsi
movq -0x30(%rbp), %rdi
callq 0x7782
jmp 0x8025
movq -0x78(%rbp), %rdi
callq 0x3120
movups 0x20(%rax), %xmm0
movups 0x30(%rax), %xmm1
movupd 0x40(%rax), %xmm2
movaps %xmm0, -0xb0(%rbp)
movaps %xmm1, -0xa0(%rbp)
movapd %xmm2, -0x90(%rbp)
movq %r13, %rdi
leaq 0x5a0e(%rip), %rsi      # 0xd975
callq 0x31f0
movq -0x68(%rbp), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x50(%rbp), %rdx
movq (%rdx), %rdx
movss 0x4(%rdx,%rcx,8), %xmm0
movq %rax, %rdi
callq 0x3170
movq %rax, %rdi
leaq 0x59eb(%rip), %rsi      # 0xd982
callq 0x31f0
movss -0x8c(%rbp), %xmm0
subss -0x88(%rbp), %xmm0
movq %rax, %rdi
callq 0x3170
movq %rax, %rdi
callq 0x30d0
movq -0x68(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x50(%rbp), %rcx
movq (%rcx), %rcx
movss 0x4(%rcx,%rax,8), %xmm0
movss -0x8c(%rbp), %xmm1
subss -0x88(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x802b
cvtss2sd %xmm0, %xmm1
movq -0x70(%rbp), %rdi
movq -0x48(%rbp), %rsi
movsd -0x40(%rbp), %xmm0
movsd %xmm1, -0x40(%rbp)
callq 0x93b9
movq -0x68(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
shlq $0x3, %rsi
movq -0x50(%rbp), %rax
addq (%rax), %rsi
movq -0x30(%rbp), %rdi
callq 0x7782
incq -0x38(%rbp)
jmp 0x805f
cvtss2sd %xmm1, %xmm1
movq -0x70(%rbp), %rdi
movq -0x48(%rbp), %rsi
movsd -0x40(%rbp), %xmm0
movsd %xmm1, -0x40(%rbp)
callq 0x93b9
movq -0x48(%rbp), %rdi
callq 0x940a
movq -0x30(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x64a0
movq %r13, %rdi
leaq 0x5928(%rip), %rsi      # 0xd991
callq 0x31f0
movq %rax, %rdi
callq 0x30d0
movq -0x30(%rbp), %rax
movq 0x28(%rax), %r14
cmpq -0xc0(%rbp), %r14
je 0x8148
movq %r13, %rdi
leaq 0x591e(%rip), %rsi      # 0xd9b3
callq 0x31f0
movq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x3190
movq %rax, %rdi
movq %r15, %rsi
callq 0x31f0
movq 0x28(%r14), %rsi
movq %rax, %rdi
callq 0x3190
movq %rax, %rdi
movq %rbx, %rsi
callq 0x31f0
cmpq $0x0, 0x20(%r14)
je 0x80fc
movq %r13, %rdi
leaq 0x5a69(%rip), %rsi      # 0xdb42
callq 0x31f0
movq %rax, %r12
movq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x62cf
movq %r12, %rdi
leaq 0x5051(%rip), %rsi      # 0xd148
callq 0x31f0
cmpq $0x0, 0x28(%r14)
je 0x8130
movq %r13, %rdi
leaq 0x5a47(%rip), %rsi      # 0xdb54
callq 0x31f0
movq %rax, %r12
movq 0x28(%r14), %rsi
movq %rax, %rdi
callq 0x62cf
movq %r12, %rdi
leaq 0x501d(%rip), %rsi      # 0xd148
callq 0x31f0
movq %r13, %rdi
callq 0x30d0
movq %r14, %rdi
callq 0x3230
movq %rax, %r14
jmp 0x807e
movq %r13, %rdi
leaq 0x584d(%rip), %rsi      # 0xd99f
callq 0x31f0
movq %rax, %rdi
callq 0x30d0
movq -0x30(%rbp), %rax
movq 0x58(%rax), %r14
cmpq -0x78(%rbp), %r14
je 0x822a
movq %r13, %rdi
leaq 0x53f7(%rip), %rsi      # 0xd572
callq 0x31f0
movss 0x44(%r14), %xmm0
subss 0x48(%r14), %xmm0
movq %rax, %rdi
callq 0x3170
movq %rax, %rdi
leaq 0x5810(%rip), %rsi      # 0xd9ae
callq 0x31f0
movq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x3190
movq %rax, %rdi
movq %r15, %rsi
callq 0x31f0
movq 0x28(%r14), %rsi
movq %rax, %rdi
callq 0x3190
movq %rax, %rdi
movq %rbx, %rsi
callq 0x31f0
movq %rax, %rdi
leaq 0x53a3(%rip), %rsi      # 0xd57e
callq 0x31f0
movq 0x30(%r14), %rsi
movq %rax, %rdi
callq 0x3190
movq %rax, %rdi
leaq 0x57bb(%rip), %rsi      # 0xd9b1
callq 0x31f0
movq 0x38(%r14), %rsi
movq %rax, %rdi
callq 0x3190
movq %rax, %rdi
movq %rbx, %rsi
callq 0x31f0
movq %rax, %rdi
callq 0x30d0
movq %r14, %rdi
callq 0x3230
movq %rax, %r14
jmp 0x8167
movq -0xb8(%rbp), %r14
movq (%r14), %r14
testq %r14, %r14
je 0x7d85
movq 0x20(%r14), %rax
testq %rax, %rax
je 0x8293
movss (%rax), %xmm0
movq %r13, %rdi
callq 0x3170
movq %rax, %rdi
movq %r15, %rsi
callq 0x31f0
movq 0x20(%r14), %rcx
movss 0x4(%rcx), %xmm0
movq %rax, %rdi
callq 0x3170
movq %rax, %rdi
callq 0x30d0
jmp 0x8231
leaq -0x68(%rbp), %rdi
callq 0xa390
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x54bd(%rip), %rdi      # 0xd757
leaq 0x5069(%rip), %rsi      # 0xd30a
leaq 0x570d(%rip), %rcx      # 0xd9b5
movl $0x3c4, %edx            # imm = 0x3C4
callq 0x3130
jmp 0x82c0
jmp 0x82c0
jmp 0x82c0
jmp 0x82c0
jmp 0x82c0
jmp 0x82c0
jmp 0x82c0
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0xa390
movq %rbx, %rdi
callq 0x3360