// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movss %xmm1, -0x44(%rbp)
movq %rsi, %rbx
movq %rdi, %r15
movss %xmm0, -0x38(%rbp)
movq 0xd9a7(%rip), %r14      # 0x13ff0
leaq 0x8d40(%rip), %rsi      # 0xf390
movl $0x19, %edx
movq %r14, %rdi
callq 0x3270
movq %r14, %rdi
movq %r15, %rsi
callq 0x6f7e
leaq 0x8d35(%rip), %r12      # 0xf3a4
movl $0x5, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x3270
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6f7e
movl $0x5, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x3270
xorps %xmm0, %xmm0
cvtss2sd -0x38(%rbp), %xmm0
movq %r14, %rdi
movsd %xmm0, -0x60(%rbp)
callq 0x3320
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movss -0x38(%rbp), %xmm3
movss 0x4(%r15), %xmm4
movaps %xmm4, %xmm0
subss %xmm3, %xmm0
movaps 0x8b9e(%rip), %xmm1     # 0xf290
andps %xmm0, %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x8b37(%rip), %xmm1     # 0xf238
ucomisd %xmm2, %xmm1
jbe 0x67ac
leaq 0x8c98(%rip), %rsi      # 0xf3aa
movl $0x12, %edx
movq %r14, %rdi
callq 0x3270
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movss (%r15), %xmm5
movss %xmm5, -0x68(%rbp)
xorps %xmm1, %xmm1
cvtss2sd %xmm5, %xmm1
mulsd %xmm1, %xmm1
movaps %xmm5, %xmm2
addss %xmm5, %xmm2
movss (%rbx), %xmm3
movss 0x4(%rbx), %xmm0
mulss %xmm3, %xmm2
cvtss2sd %xmm2, %xmm2
subsd %xmm2, %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm3, %xmm2
mulsd %xmm2, %xmm2
addsd %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
movsd -0x60(%rbp), %xmm2
mulsd %xmm2, %xmm2
subsd %xmm2, %xmm1
subss -0x38(%rbp), %xmm0
jmp 0x6cde
movsd -0x60(%rbp), %xmm6
movss 0x4(%rbx), %xmm7
movaps %xmm7, %xmm2
subss %xmm3, %xmm2
andps 0x8acc(%rip), %xmm2     # 0xf290
cvtss2sd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x686e
leaq 0x8be4(%rip), %rsi      # 0xf3bd
movl $0x12, %edx
movq %r14, %rdi
callq 0x3270
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movss -0x38(%rbp), %xmm4
movss (%rbx), %xmm5
movss %xmm5, -0x68(%rbp)
movss (%r15), %xmm1
movss 0x4(%r15), %xmm0
movaps %xmm0, %xmm2
mulss %xmm0, %xmm2
movaps %xmm1, %xmm3
mulss %xmm1, %xmm3
addss %xmm2, %xmm3
mulss 0x8a84(%rip), %xmm1     # 0xf2c4
mulss %xmm5, %xmm1
addss %xmm3, %xmm1
movaps %xmm5, %xmm2
mulss %xmm5, %xmm2
addss %xmm1, %xmm2
movaps %xmm4, %xmm1
mulss %xmm4, %xmm1
subss %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
subss %xmm4, %xmm0
jmp 0x6cde
movaps %xmm4, %xmm2
subss %xmm7, %xmm2
movaps 0x8a14(%rip), %xmm1     # 0xf290
andps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd 0x89ad(%rip), %xmm1     # 0xf238
jbe 0x6911
movaps %xmm2, -0x80(%rbp)
movss (%rbx), %xmm6
movss (%r15), %xmm2
movaps %xmm4, %xmm0
mulss %xmm4, %xmm0
movaps %xmm2, %xmm1
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0x8a0c(%rip), %xmm5     # 0xf2c4
movss %xmm2, -0x2c(%rbp)
movaps %xmm2, %xmm0
mulss %xmm5, %xmm0
mulss %xmm6, %xmm0
addss %xmm1, %xmm0
movss %xmm6, -0x48(%rbp)
movaps %xmm6, %xmm1
mulss %xmm6, %xmm1
addss %xmm0, %xmm1
movaps %xmm4, %xmm2
mulss %xmm5, %xmm2
mulss %xmm7, %xmm2
addss %xmm1, %xmm2
movaps %xmm7, %xmm0
mulss %xmm7, %xmm0
addss %xmm2, %xmm0
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm0
movss %xmm4, -0x40(%rbp)
movss %xmm7, -0x3c(%rbp)
jb 0x6971
xorps %xmm1, %xmm1
sqrtss %xmm0, %xmm1
jmp 0x6981
movss (%r15), %xmm1
movss (%rbx), %xmm5
addss %xmm1, %xmm5
mulss 0x899a(%rip), %xmm5     # 0xf2c0
movss %xmm5, -0x68(%rbp)
xorps %xmm2, %xmm2
cvtss2sd %xmm1, %xmm2
mulsd %xmm2, %xmm2
xorps %xmm3, %xmm3
cvtss2sd %xmm4, %xmm3
mulsd %xmm3, %xmm3
addsd %xmm2, %xmm3
addss %xmm1, %xmm1
mulss %xmm5, %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm3
xorps %xmm1, %xmm1
cvtss2sd %xmm5, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm3, %xmm1
mulsd %xmm6, %xmm6
subsd %xmm6, %xmm1
jmp 0x6cde
callq 0x33a0
xorps %xmm2, %xmm2
movss -0x38(%rbp), %xmm3
movaps %xmm0, %xmm1
movss 0x4(%r15), %xmm0
subss %xmm3, %xmm0
ucomiss %xmm2, %xmm0
movaps %xmm1, -0x60(%rbp)
jb 0x699d
xorps %xmm6, %xmm6
sqrtss %xmm0, %xmm6
jmp 0x69aa
callq 0x33a0
movss -0x38(%rbp), %xmm3
movaps %xmm0, %xmm6
movss -0x40(%rbp), %xmm2
movss -0x3c(%rbp), %xmm4
movss -0x2c(%rbp), %xmm1
mulss %xmm1, %xmm4
movss -0x48(%rbp), %xmm0
mulss %xmm0, %xmm2
subss %xmm0, %xmm1
movss 0x4(%rbx), %xmm0
subss %xmm3, %xmm0
xorps %xmm5, %xmm5
ucomiss %xmm5, %xmm0
jb 0x69e1
sqrtss %xmm0, %xmm0
jmp 0x6a13
movss %xmm1, -0x2c(%rbp)
movss %xmm2, -0x40(%rbp)
movss %xmm4, -0x3c(%rbp)
movss %xmm6, -0x6c(%rbp)
callq 0x33a0
movss -0x6c(%rbp), %xmm6
movss -0x3c(%rbp), %xmm4
movss -0x40(%rbp), %xmm2
movss -0x2c(%rbp), %xmm1
movss -0x38(%rbp), %xmm3
movss %xmm0, -0x48(%rbp)
movaps -0x60(%rbp), %xmm0
subss %xmm4, %xmm2
movss %xmm2, -0x40(%rbp)
mulss %xmm3, %xmm1
movss %xmm1, -0x2c(%rbp)
mulss %xmm6, %xmm0
movaps %xmm0, -0x60(%rbp)
movss 0x4(%r15), %xmm0
subss 0x4(%rbx), %xmm0
movss %xmm0, -0x3c(%rbp)
movq 0xd5a3(%rip), %rdi      # 0x13ff0
leaq 0x8951(%rip), %rsi      # 0xf3a5
movl $0x4, %edx
callq 0x3270
movss (%r15), %xmm1
movss 0x4(%r15), %xmm2
movaps %xmm2, %xmm0
mulss %xmm2, %xmm0
movaps %xmm1, %xmm3
mulss %xmm1, %xmm3
addss %xmm0, %xmm3
movss 0x8841(%rip), %xmm5     # 0xf2c4
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 0x880d(%rip), %xmm0     # 0xf2c8
jb 0x6ac3
sqrtss %xmm0, %xmm0
jmp 0x6ac8
callq 0x33a0
movss -0x2c(%rbp), %xmm1
addss -0x40(%rbp), %xmm1
movss %xmm1, -0x2c(%rbp)
movaps -0x60(%rbp), %xmm1
mulss -0x48(%rbp), %xmm1
movaps %xmm1, -0x60(%rbp)
cvtss2sd %xmm0, %xmm0
movq 0xd501(%rip), %rdi      # 0x13ff0
callq 0x3320
movq %rax, %r12
leaq 0x853d(%rip), %rsi      # 0xf03b
movl $0x2, %edx
movq %rax, %rdi
callq 0x3270
movss 0x4(%r15), %xmm0
subss -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x6b24
sqrtss %xmm0, %xmm0
jmp 0x6b29
callq 0x33a0
movaps -0x80(%rbp), %xmm2
movss -0x2c(%rbp), %xmm1
divss %xmm2, %xmm1
movss %xmm1, -0x2c(%rbp)
movaps -0x60(%rbp), %xmm1
divss -0x3c(%rbp), %xmm1
movaps %xmm1, -0x60(%rbp)
cvtss2sd %xmm0, %xmm0
movq %r12, %rdi
callq 0x3320
movq %rax, %r12
leaq 0x84dd(%rip), %rsi      # 0xf03b
movl $0x2, %edx
movq %rax, %rdi
callq 0x3270
movss 0x4(%rbx), %xmm0
subss -0x38(%rbp), %xmm0
ucomiss 0x874c(%rip), %xmm0     # 0xf2c8
jb 0x6b84
sqrtss %xmm0, %xmm0
jmp 0x6b89
callq 0x33a0
movss 0x4(%r15), %xmm1
subss 0x4(%rbx), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movq %r12, %rdi
callq 0x3320
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movq 0xd41b(%rip), %r12      # 0x13ff0
leaq 0x87c9(%rip), %rsi      # 0xf3a5
movl $0x4, %edx
movq %r12, %rdi
callq 0x3270
xorps %xmm0, %xmm0
cvtss2sd -0x2c(%rbp), %xmm0
movq %r12, %rdi
callq 0x3320
movq %rax, %r12
leaq 0x87cd(%rip), %rsi      # 0xf3d0
movl $0x3, %edx
movq %rax, %rdi
callq 0x3270
xorps %xmm0, %xmm0
cvtss2sd -0x44(%rbp), %xmm0
movq %r12, %rdi
callq 0x3320
movq %rax, %r12
leaq 0x87aa(%rip), %rsi      # 0xf3d4
movl $0x3, %edx
movq %rax, %rdi
callq 0x3270
xorps %xmm0, %xmm0
cvtss2sd -0x60(%rbp), %xmm0
movq %r12, %rdi
callq 0x3320
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movaps -0x60(%rbp), %xmm5
andps 0x8614(%rip), %xmm5     # 0xf290
mulss -0x44(%rbp), %xmm5
addss -0x2c(%rbp), %xmm5
movss %xmm5, -0x68(%rbp)
movss (%r15), %xmm1
movss 0x4(%r15), %xmm0
movaps %xmm0, %xmm2
mulss %xmm0, %xmm2
movaps %xmm1, %xmm3
mulss %xmm1, %xmm3
addss %xmm2, %xmm3
mulss 0x8614(%rip), %xmm1     # 0xf2c4
mulss %xmm5, %xmm1
addss %xmm3, %xmm1
movaps %xmm5, %xmm2
mulss %xmm5, %xmm2
addss %xmm1, %xmm2
movss -0x38(%rbp), %xmm3
movaps %xmm3, %xmm1
mulss %xmm3, %xmm1
subss %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
subss %xmm3, %xmm0
mulsd 0x855a(%rip), %xmm1     # 0xf240
cvtss2sd %xmm0, %xmm0
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, -0x64(%rbp)
movd %xmm5, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7f800000, %eax       # imm = 0x7F800000
je 0x6f02
movd %xmm0, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7f800000, %eax       # imm = 0x7F800000
je 0x6f21
ucomiss %xmm5, %xmm5
jp 0x6f40
movaps %xmm5, -0x60(%rbp)
ucomiss %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
jp 0x6f5f
leaq 0x871a(%rip), %rsi      # 0xf45e
movl $0xe, %edx
movq %r14, %rdi
callq 0x3270
leaq -0x68(%rbp), %rsi
movq %r14, %rdi
callq 0x6f7e
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
leaq 0x86e2(%rip), %rsi      # 0xf46d
movl $0x1a, %edx
movq %r14, %rdi
callq 0x3270
movss -0x44(%rbp), %xmm0
subss -0x38(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq %r14, %rdi
callq 0x3320
movq %rax, %r12
leaq 0x8309(%rip), %r13      # 0xf0c6
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x3270
leaq 0x86b4(%rip), %rsi      # 0xf488
movl $0x18, %edx
movq %r12, %rdi
callq 0x3270
movss (%r15), %xmm0
movss 0x4(%r15), %xmm1
subss -0x60(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm0, %xmm0
subss -0x44(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
movq %r12, %rdi
callq 0x3320
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
leaq 0x8657(%rip), %rsi      # 0xf4a1
movl $0x1a, %edx
movq %r14, %rdi
callq 0x3270
movq %r14, %rdi
movsd -0x38(%rbp), %xmm0
callq 0x3320
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x3270
leaq 0x863e(%rip), %rsi      # 0xf4bc
movl $0x18, %edx
movq %r14, %rdi
callq 0x3270
movss (%rbx), %xmm0
movss 0x4(%rbx), %xmm1
subss -0x60(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm0, %xmm0
subss -0x44(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
movq %r14, %rdi
callq 0x3320
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
leaq -0x68(%rbp), %rax
movsd (%rax), %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x84cf(%rip), %rdi      # 0xf3d8
leaq 0x83ea(%rip), %rsi      # 0xf2fa
leaq 0x84d2(%rip), %rcx      # 0xf3e9
movl $0x22a, %edx            # imm = 0x22A
callq 0x3140
leaq 0x8503(%rip), %rdi      # 0xf42b
leaq 0x83cb(%rip), %rsi      # 0xf2fa
leaq 0x84b3(%rip), %rcx      # 0xf3e9
movl $0x22b, %edx            # imm = 0x22B
callq 0x3140
leaq 0x84f5(%rip), %rdi      # 0xf43c
leaq 0x83ac(%rip), %rsi      # 0xf2fa
leaq 0x8494(%rip), %rcx      # 0xf3e9
movl $0x22c, %edx            # imm = 0x22C
callq 0x3140
leaq 0x84e7(%rip), %rdi      # 0xf44d
leaq 0x838d(%rip), %rsi      # 0xf2fa
leaq 0x8475(%rip), %rcx      # 0xf3e9
movl $0x22d, %edx            # imm = 0x22D
callq 0x3140