// File: /workspace/github_cpp_makefile_star2_O1/micahcc[P]polygon_skeleton/voronoi.cpp
// Function: getIntersection(float, Vector const&, Vector const&, float)
Point getIntersection(float sweep_y, const Point& p, const Point& r, float sign)
{
    // Given any point q, its distance from sweep is:
    //
    // (q.y - y_s)
    //
    // Its distance from an event p is:
    //
    // sqrt((q.x - p.x)^2 + (q.y - p.y)^2)
    //
    // the parabola equation is then:
    //
    // (q.y - y_s)^2 = (q.x - p.x)^2 + (q.y - p.y)^2
    //
    // For two event points, r and p, we can solve q.x -- the intersection
    // location must satisfy:
    //
    // sqrt( sqr(q_x - p_x) + sqr(q_y - p_y) ) ==
    // sqrt( sqr(q_x - r_x) + sqr(q_y - r_y) )
    //
    // and
    //
    // sqrt( sqr(q_x - r_x) + sqr(q_y - r_y) ) == q_y - sweep_y
    std::cerr << "<<<<Intersection of:\n<<<<" << p << "\n<<<<" << r << "\n<<<<" <<
        sweep_y << std::endl;

    // Solve for x first
    float y_s = sweep_y;
    Point q;
    if(std::abs(p.y - sweep_y) < 0.0000001) {
        // parabola around p has no width, just select point on parabola r at
        // p.x
        std::cerr << "<<<<p_y == sweep_y" << std::endl;
        q.x = p.x;
        q.y = 0.5*( sqr(q.x) - 2*q.x*r.x + sqr(r.x) + sqr(r.y) - sqr(y_s))/(r.y - y_s);
    } else if(std::abs(r.y - sweep_y) < 0.0000001) {
        // parabola around r has no width, just select point on parabola q at
        // r.x
        std::cerr << "<<<<r_y == sweep_y" << std::endl;
        q.x = r.x;
        q.y = 0.5*(p.x*p.x + p.y*p.y - 2*p.x*q.x + q.x*q.x - y_s*y_s)/(p.y - y_s);
    } else {
        if(std::abs(p.y - r.y) > 0.0000001) {
            float term1 = (p.y*r.x - p.x*r.y + (p.x - r.x)*y_s) / (p.y - r.y);
            float rad =
                sqrt(p.x*p.x + p.y*p.y - 2*p.x*r.x + r.x*r.x - 2*p.y*r.y + r.y*r.y)*
                sqrt(p.y - y_s)*sqrt(r.y - y_s)/(p.y - r.y);

            std::cerr << "<<<<"
                << sqrt(p.x*p.x + p.y*p.y - 2*p.x*r.x + r.x*r.x - 2*p.y*r.y + r.y*r.y)
                << ", " << sqrt( p.y - y_s) << ", " << sqrt(r.y - y_s)/(p.y - r.y) << std::endl;;
            std::cerr << "<<<<" << term1 << " + " << sign << " * " << rad << std::endl;
            // choose +- radical to be between
            q.x = term1 + sign*std::abs(rad);

            // use one of the parabolas to find y
            q.y = 0.5*(p.x*p.x + p.y*p.y - 2*p.x*q.x + q.x*q.x - y_s*y_s)/(p.y - y_s);
        } else {
            // special case: x-coord is exactly in-between
            q.x = (p.x + r.x)*0.5;
            q.y = 0.5*(sqr(p.x) + sqr(p.y) - 2*p.x*q.x + sqr(q.x) - sqr(y_s))/
                (p.y - y_s);
        }
    }

    assert(!std::isinf(q.x));
    assert(!std::isinf(q.y));
    assert(!std::isnan(q.x));
    assert(!std::isnan(q.y));
    std::cerr << "<<<<Solution: " << q << std::endl;
    std::cerr << "<<<<Sweep line distance0: " << (q.y - sweep_y) << "\n"
        << "<<<<Solution distance0: "
        << std::sqrt( sqr(p.x - q.x ) + sqr( p.y - q.y )) << std::endl;
    std::cerr << "<<<<Sweep line distance1: " << (q.y - sweep_y) << "\n"
        << "<<<<Solution distance1: "
        << std::sqrt( sqr(r.x - q.x ) + sqr( r.y - q.y )) << std::endl;
    return q;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x60, %rsp
movss %xmm1, -0x3c(%rbp)
movq %rsi, %rbx
movq %rdi, %r14
movss %xmm0, -0x30(%rbp)
movq 0xd983(%rip), %r15      # 0x13ff0
leaq 0x8d2c(%rip), %rsi      # 0xf3a0
movl $0x19, %edx
movq %r15, %rdi
callq 0x3280
movq %r15, %rdi
movq %r14, %rsi
callq 0x6fc0
leaq 0x8d21(%rip), %r12      # 0xf3b4
movl $0x5, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x3280
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6fc0
movl $0x5, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x3280
xorps %xmm0, %xmm0
cvtss2sd -0x30(%rbp), %xmm0
movq %r15, %rdi
movsd %xmm0, -0x28(%rbp)
callq 0x3330
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movss -0x30(%rbp), %xmm3
movq $0x0, -0x48(%rbp)
movss 0x4(%r14), %xmm4
movaps %xmm4, %xmm0
subss %xmm3, %xmm0
movaps 0x8b82(%rip), %xmm1     # 0xf2a0
andps %xmm0, %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x8b0b(%rip), %xmm1     # 0xf238
ucomisd %xmm2, %xmm1
jbe 0x67d2
leaq 0x8c7c(%rip), %rsi      # 0xf3ba
movl $0x12, %edx
movq %r15, %rdi
callq 0x3280
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movss (%r14), %xmm1
movss %xmm1, -0x48(%rbp)
xorps %xmm2, %xmm2
cvtss2sd %xmm1, %xmm2
mulsd %xmm2, %xmm2
addss %xmm1, %xmm1
movss (%rbx), %xmm3
movss 0x4(%rbx), %xmm0
mulss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm2
cvtss2sd %xmm3, %xmm3
mulsd %xmm3, %xmm3
addsd %xmm2, %xmm3
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm3, %xmm1
movsd -0x28(%rbp), %xmm2
mulsd %xmm2, %xmm2
subsd %xmm2, %xmm1
subss -0x30(%rbp), %xmm0
jmp 0x6cee
movsd -0x28(%rbp), %xmm5
movss 0x4(%rbx), %xmm6
movaps %xmm6, %xmm2
subss %xmm3, %xmm2
andps 0x8ab6(%rip), %xmm2     # 0xf2a0
cvtss2sd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x688e
leaq 0x8bce(%rip), %rsi      # 0xf3cd
movl $0x12, %edx
movq %r15, %rdi
callq 0x3280
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movss -0x30(%rbp), %xmm5
movss (%rbx), %xmm1
movss %xmm1, -0x48(%rbp)
movss (%r14), %xmm2
movss 0x4(%r14), %xmm0
movaps %xmm0, %xmm3
mulss %xmm0, %xmm3
movaps %xmm2, %xmm4
mulss %xmm2, %xmm4
addss %xmm3, %xmm4
mulss 0x8a6e(%rip), %xmm2     # 0xf2d4
mulss %xmm1, %xmm2
addss %xmm4, %xmm2
mulss %xmm1, %xmm1
addss %xmm2, %xmm1
movaps %xmm5, %xmm2
mulss %xmm5, %xmm2
subss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
subss %xmm5, %xmm0
jmp 0x6cee
movaps %xmm4, %xmm2
subss %xmm6, %xmm2
movaps 0x8a04(%rip), %xmm1     # 0xf2a0
andps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd 0x898d(%rip), %xmm1     # 0xf238
jbe 0x692a
movaps %xmm2, -0x80(%rbp)
movss (%rbx), %xmm7
movss (%r14), %xmm2
movaps %xmm4, %xmm0
mulss %xmm4, %xmm0
movaps %xmm2, %xmm1
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0x8a00(%rip), %xmm5     # 0xf2d4
movss %xmm2, -0x28(%rbp)
movaps %xmm2, %xmm0
mulss %xmm5, %xmm0
mulss %xmm7, %xmm0
addss %xmm1, %xmm0
movss %xmm7, -0x4c(%rbp)
movaps %xmm7, %xmm1
mulss %xmm7, %xmm1
addss %xmm0, %xmm1
movaps %xmm4, %xmm2
mulss %xmm5, %xmm2
mulss %xmm6, %xmm2
addss %xmm1, %xmm2
movaps %xmm6, %xmm0
mulss %xmm6, %xmm0
addss %xmm2, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movss %xmm4, -0x38(%rbp)
movss %xmm6, -0x34(%rbp)
jb 0x6987
sqrtss %xmm0, %xmm0
jmp 0x6994
movss (%r14), %xmm1
movss (%rbx), %xmm2
addss %xmm1, %xmm2
mulss 0x8991(%rip), %xmm2     # 0xf2d0
movss %xmm2, -0x48(%rbp)
xorps %xmm3, %xmm3
cvtss2sd %xmm1, %xmm3
mulsd %xmm3, %xmm3
cvtss2sd %xmm4, %xmm4
mulsd %xmm4, %xmm4
addsd %xmm3, %xmm4
addss %xmm1, %xmm1
mulss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm4
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm4, %xmm1
mulsd %xmm5, %xmm5
subsd %xmm5, %xmm1
jmp 0x6cee
callq 0x33b0
xorps %xmm1, %xmm1
movss -0x30(%rbp), %xmm3
movaps %xmm0, -0x60(%rbp)
movss 0x4(%r14), %xmm0
subss %xmm3, %xmm0
ucomiss %xmm1, %xmm0
jb 0x69b0
xorps %xmm6, %xmm6
sqrtss %xmm0, %xmm6
jmp 0x69bd
callq 0x33b0
movss -0x30(%rbp), %xmm3
movaps %xmm0, %xmm6
movss -0x28(%rbp), %xmm1
movss -0x38(%rbp), %xmm2
movss -0x34(%rbp), %xmm4
mulss %xmm1, %xmm4
movss -0x4c(%rbp), %xmm0
mulss %xmm0, %xmm2
subss %xmm0, %xmm1
movss 0x4(%rbx), %xmm0
subss %xmm3, %xmm0
xorps %xmm5, %xmm5
ucomiss %xmm5, %xmm0
jb 0x69f4
sqrtss %xmm0, %xmm0
jmp 0x6a26
movss %xmm1, -0x28(%rbp)
movss %xmm2, -0x38(%rbp)
movss %xmm4, -0x34(%rbp)
movss %xmm6, -0x64(%rbp)
callq 0x33b0
movss -0x64(%rbp), %xmm6
movss -0x34(%rbp), %xmm4
movss -0x38(%rbp), %xmm2
movss -0x28(%rbp), %xmm1
movss -0x30(%rbp), %xmm3
movss %xmm0, -0x4c(%rbp)
subss %xmm4, %xmm2
movss %xmm2, -0x38(%rbp)
mulss %xmm3, %xmm1
movss %xmm1, -0x28(%rbp)
movaps -0x60(%rbp), %xmm0
mulss %xmm6, %xmm0
movaps %xmm0, -0x60(%rbp)
movss 0x4(%r14), %xmm0
subss 0x4(%rbx), %xmm0
movss %xmm0, -0x34(%rbp)
movq 0xd590(%rip), %rdi      # 0x13ff0
leaq 0x894e(%rip), %rsi      # 0xf3b5
movl $0x4, %edx
callq 0x3280
movss (%r14), %xmm1
movss 0x4(%r14), %xmm2
movaps %xmm2, %xmm0
mulss %xmm2, %xmm0
movaps %xmm1, %xmm3
mulss %xmm1, %xmm3
addss %xmm0, %xmm3
movss 0x883e(%rip), %xmm5     # 0xf2d4
mulss %xmm5, %xmm1
movss (%rbx), %xmm4
movss 0x4(%rbx), %xmm0
mulss %xmm4, %xmm1
addss %xmm3, %xmm1
mulss %xmm4, %xmm4
addss %xmm1, %xmm4
mulss %xmm5, %xmm2
mulss %xmm0, %xmm2
addss %xmm4, %xmm2
mulss %xmm0, %xmm0
addss %xmm2, %xmm0
ucomiss 0x880a(%rip), %xmm0     # 0xf2d8
jb 0x6ad6
sqrtss %xmm0, %xmm0
jmp 0x6adb
callq 0x33b0
movss -0x28(%rbp), %xmm1
addss -0x38(%rbp), %xmm1
movss %xmm1, -0x28(%rbp)
movaps -0x60(%rbp), %xmm1
mulss -0x4c(%rbp), %xmm1
movaps %xmm1, -0x60(%rbp)
cvtss2sd %xmm0, %xmm0
movq 0xd4ee(%rip), %rdi      # 0x13ff0
callq 0x3330
movq %rax, %r12
leaq 0x852a(%rip), %rsi      # 0xf03b
movl $0x2, %edx
movq %rax, %rdi
callq 0x3280
movss 0x4(%r14), %xmm0
subss -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x6b37
sqrtss %xmm0, %xmm0
jmp 0x6b3c
callq 0x33b0
movaps -0x80(%rbp), %xmm2
movss -0x28(%rbp), %xmm1
divss %xmm2, %xmm1
movss %xmm1, -0x28(%rbp)
movaps -0x60(%rbp), %xmm1
divss -0x34(%rbp), %xmm1
movaps %xmm1, -0x60(%rbp)
cvtss2sd %xmm0, %xmm0
movq %r12, %rdi
callq 0x3330
movq %rax, %r12
leaq 0x84ca(%rip), %rsi      # 0xf03b
movl $0x2, %edx
movq %rax, %rdi
callq 0x3280
movss 0x4(%rbx), %xmm0
subss -0x30(%rbp), %xmm0
ucomiss 0x8749(%rip), %xmm0     # 0xf2d8
jb 0x6b97
sqrtss %xmm0, %xmm0
jmp 0x6b9c
callq 0x33b0
movss 0x4(%r14), %xmm1
subss 0x4(%rbx), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movq %r12, %rdi
callq 0x3330
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movq 0xd408(%rip), %r12      # 0x13ff0
leaq 0x87c6(%rip), %rsi      # 0xf3b5
movl $0x4, %edx
movq %r12, %rdi
callq 0x3280
xorps %xmm0, %xmm0
cvtss2sd -0x28(%rbp), %xmm0
movq %r12, %rdi
callq 0x3330
movq %rax, %r12
leaq 0x87ca(%rip), %rsi      # 0xf3e0
movl $0x3, %edx
movq %rax, %rdi
callq 0x3280
xorps %xmm0, %xmm0
cvtss2sd -0x3c(%rbp), %xmm0
movq %r12, %rdi
callq 0x3330
movq %rax, %r12
leaq 0x87a7(%rip), %rsi      # 0xf3e4
movl $0x3, %edx
movq %rax, %rdi
callq 0x3280
xorps %xmm0, %xmm0
cvtss2sd -0x60(%rbp), %xmm0
movq %r12, %rdi
callq 0x3330
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movaps -0x60(%rbp), %xmm4
andps 0x8611(%rip), %xmm4     # 0xf2a0
mulss -0x3c(%rbp), %xmm4
addss -0x28(%rbp), %xmm4
movss %xmm4, -0x48(%rbp)
movss (%r14), %xmm1
movss 0x4(%r14), %xmm0
movaps %xmm0, %xmm2
mulss %xmm0, %xmm2
movaps %xmm1, %xmm3
mulss %xmm1, %xmm3
addss %xmm2, %xmm3
mulss 0x8611(%rip), %xmm1     # 0xf2d4
mulss %xmm4, %xmm1
addss %xmm3, %xmm1
mulss %xmm4, %xmm4
addss %xmm1, %xmm4
movss -0x30(%rbp), %xmm2
movaps %xmm2, %xmm1
mulss %xmm2, %xmm1
subss %xmm1, %xmm4
xorps %xmm1, %xmm1
cvtss2sd %xmm4, %xmm1
subss %xmm2, %xmm0
mulsd 0x854a(%rip), %xmm1     # 0xf240
cvtss2sd %xmm0, %xmm0
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, -0x44(%rbp)
movd -0x48(%rbp), %xmm0
movd %xmm0, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7f800000, %eax       # imm = 0x7F800000
je 0x6f44
movd -0x44(%rbp), %xmm1
movd %xmm1, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7f800000, %eax       # imm = 0x7F800000
je 0x6f63
ucomiss %xmm0, %xmm0
jp 0x6f82
movss %xmm0, -0x3c(%rbp)
ucomiss %xmm1, %xmm1
movss %xmm1, -0x28(%rbp)
jp 0x6fa1
leaq 0x870f(%rip), %rsi      # 0xf46e
movl $0xe, %edx
movq %r15, %rdi
callq 0x3280
leaq -0x48(%rbp), %rsi
movq %r15, %rdi
callq 0x6fc0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
leaq 0x86d7(%rip), %rsi      # 0xf47d
movl $0x1a, %edx
movq %r15, %rdi
callq 0x3280
movss -0x28(%rbp), %xmm0
subss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
movsd %xmm0, -0x30(%rbp)
callq 0x3330
movq %rax, %r15
leaq 0x82ee(%rip), %rsi      # 0xf0c6
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
leaq 0x86ac(%rip), %rsi      # 0xf498
movl $0x18, %edx
movq %r15, %rdi
callq 0x3280
movss (%r14), %xmm0
movss 0x4(%r14), %xmm1
subss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm2
mulsd %xmm2, %xmm2
subss -0x28(%rbp), %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x6e34
sqrtsd %xmm0, %xmm0
jmp 0x6e39
callq 0x31e0
movq %r15, %rdi
callq 0x3330
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movq 0xd17e(%rip), %r14      # 0x13ff0
leaq 0x8638(%rip), %rsi      # 0xf4b1
movl $0x1a, %edx
movq %r14, %rdi
callq 0x3280
movq %r14, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x3330
movq %rax, %r14
leaq 0x8229(%rip), %rsi      # 0xf0c6
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
leaq 0x861b(%rip), %rsi      # 0xf4cc
movl $0x18, %edx
movq %r14, %rdi
callq 0x3280
movss (%rbx), %xmm0
movss 0x4(%rbx), %xmm1
subss -0x3c(%rbp), %xmm0
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
mulsd %xmm2, %xmm2
subss -0x28(%rbp), %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
ucomisd 0x8355(%rip), %xmm0     # 0xf248
jb 0x6efb
sqrtsd %xmm0, %xmm0
jmp 0x6f00
callq 0x31e0
movq %r14, %rdi
callq 0x3330
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movsd -0x48(%rbp), %xmm0
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x849d(%rip), %rdi      # 0xf3e8
leaq 0x83b8(%rip), %rsi      # 0xf30a
leaq 0x84a0(%rip), %rcx      # 0xf3f9
movl $0x22a, %edx            # imm = 0x22A
callq 0x3140
leaq 0x84d1(%rip), %rdi      # 0xf43b
leaq 0x8399(%rip), %rsi      # 0xf30a
leaq 0x8481(%rip), %rcx      # 0xf3f9
movl $0x22b, %edx            # imm = 0x22B
callq 0x3140
leaq 0x84c3(%rip), %rdi      # 0xf44c
leaq 0x837a(%rip), %rsi      # 0xf30a
leaq 0x8462(%rip), %rcx      # 0xf3f9
movl $0x22c, %edx            # imm = 0x22C
callq 0x3140
leaq 0x84b5(%rip), %rdi      # 0xf45d
leaq 0x835b(%rip), %rsi      # 0xf30a
leaq 0x8443(%rip), %rcx      # 0xf3f9
movl $0x22d, %edx            # imm = 0x22D
callq 0x3140