// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movss %xmm1, -0x3c(%rbp)
movq %rsi, %rbx
movq %rdi, %r14
movss %xmm0, -0x2c(%rbp)
movq 0xe4a7(%rip), %rdi      # 0x13ff0
leaq 0x7850(%rip), %rsi      # 0xd3a0
callq 0x31f0
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x62cf
leaq 0x784a(%rip), %r12      # 0xd3b4
movq %r15, %rdi
movq %r12, %rsi
callq 0x31f0
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x62cf
movq %r15, %rdi
movq %r12, %rsi
callq 0x31f0
movq %rax, %rdi
movss -0x2c(%rbp), %xmm0
callq 0x3170
movq %rax, %rdi
callq 0x30d0
movss -0x2c(%rbp), %xmm4
movss 0x4(%r14), %xmm3
movaps %xmm3, %xmm0
subss %xmm4, %xmm0
movaps 0x76f4(%rip), %xmm1     # 0xd2b0
andps %xmm0, %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x768d(%rip), %xmm1     # 0xd258
ucomisd %xmm2, %xmm1
jbe 0x5c48
movq 0xe418(%rip), %rdi      # 0x13ff0
leaq 0x77db(%rip), %rsi      # 0xd3ba
callq 0x31f0
movq %rax, %rdi
callq 0x30d0
movss -0x2c(%rbp), %xmm4
movss (%r14), %xmm5
movss %xmm5, -0x58(%rbp)
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
cvtss2sd %xmm3, %xmm2
mulsd %xmm2, %xmm2
addsd %xmm1, %xmm2
cvtss2sd %xmm0, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
cvtss2sd %xmm4, %xmm2
mulsd %xmm2, %xmm2
subsd %xmm2, %xmm1
jmp 0x5cd9
movss 0x4(%rbx), %xmm6
movaps %xmm6, %xmm2
subss %xmm4, %xmm2
andps 0x7655(%rip), %xmm2     # 0xd2b0
cvtss2sd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x5e72
movq 0xe380(%rip), %rdi      # 0x13ff0
leaq 0x7756(%rip), %rsi      # 0xd3cd
callq 0x31f0
movq %rax, %rdi
callq 0x30d0
movss -0x2c(%rbp), %xmm4
movss (%rbx), %xmm5
movss %xmm5, -0x58(%rbp)
movss (%r14), %xmm1
movss 0x4(%r14), %xmm0
movaps %xmm0, %xmm2
mulss %xmm0, %xmm2
movaps %xmm1, %xmm3
mulss %xmm1, %xmm3
addss %xmm2, %xmm3
mulss 0x761d(%rip), %xmm1     # 0xd2d4
mulss %xmm5, %xmm1
addss %xmm3, %xmm1
movaps %xmm5, %xmm2
mulss %xmm5, %xmm2
addss %xmm1, %xmm2
movaps %xmm4, %xmm1
mulss %xmm4, %xmm1
subss %xmm1, %xmm2
cvtss2sd %xmm2, %xmm1
subss %xmm4, %xmm0
mulsd 0x7353(%rip), %xmm1     # 0xd038
cvtss2sd %xmm0, %xmm0
divsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, -0x54(%rbp)
movd %xmm5, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7f800000, %eax       # imm = 0x7F800000
je 0x6253
movd %xmm0, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7f800000, %eax       # imm = 0x7F800000
je 0x6272
ucomiss %xmm5, %xmm5
jp 0x6291
movaps %xmm5, -0x50(%rbp)
ucomiss %xmm0, %xmm0
movss %xmm0, -0x3c(%rbp)
jp 0x62b0
movq 0xe2b0(%rip), %r12      # 0x13ff0
leaq 0x7727(%rip), %rsi      # 0xd46e
movq %r12, %rdi
callq 0x31f0
movq %rax, %r13
leaq -0x58(%rbp), %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x62cf
movq %r13, %rdi
callq 0x30d0
leaq 0x770d(%rip), %rsi      # 0xd47d
movq %r12, %rdi
callq 0x31f0
movss -0x3c(%rbp), %xmm0
subss -0x2c(%rbp), %xmm0
movss %xmm0, -0x2c(%rbp)
movq %rax, %rdi
callq 0x3170
leaq 0x7352(%rip), %r13      # 0xd0e8
movq %rax, %rdi
movq %r13, %rsi
callq 0x31f0
leaq 0x76f0(%rip), %rsi      # 0xd498
movq %rax, %rdi
callq 0x31f0
movss (%r14), %xmm0
movss 0x4(%r14), %xmm1
subss -0x50(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm0, %xmm0
subss -0x3c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x3300
movq %rax, %rdi
callq 0x30d0
leaq 0x76bd(%rip), %rsi      # 0xd4b1
movq %r12, %rdi
callq 0x31f0
movq %rax, %rdi
movss -0x2c(%rbp), %xmm0
callq 0x3170
movq %rax, %rdi
movq %r13, %rsi
callq 0x31f0
leaq 0x76b1(%rip), %rsi      # 0xd4cc
movq %rax, %rdi
callq 0x31f0
movss (%rbx), %xmm0
movss 0x4(%rbx), %xmm1
subss -0x50(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm0, %xmm0
subss -0x3c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x3300
movq %rax, %rdi
callq 0x30d0
movsd (%r15), %xmm0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movaps %xmm3, %xmm2
subss %xmm6, %xmm2
movaps 0x7430(%rip), %xmm1     # 0xd2b0
andps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd 0x73c9(%rip), %xmm1     # 0xd258
jbe 0x5f0e
movaps %xmm2, -0x70(%rbp)
movss (%rbx), %xmm7
movss (%r14), %xmm2
movaps %xmm3, %xmm0
mulss %xmm3, %xmm0
movaps %xmm2, %xmm1
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0x741c(%rip), %xmm5     # 0xd2d4
movss %xmm2, -0x30(%rbp)
movaps %xmm2, %xmm0
mulss %xmm5, %xmm0
mulss %xmm7, %xmm0
addss %xmm1, %xmm0
movss %xmm7, -0x40(%rbp)
movaps %xmm7, %xmm1
mulss %xmm7, %xmm1
addss %xmm0, %xmm1
movaps %xmm3, %xmm2
mulss %xmm5, %xmm2
mulss %xmm6, %xmm2
addss %xmm1, %xmm2
movaps %xmm6, %xmm0
mulss %xmm6, %xmm0
addss %xmm2, %xmm0
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm0
movss %xmm3, -0x38(%rbp)
movss %xmm6, -0x34(%rbp)
jb 0x5f69
sqrtss %xmm0, %xmm1
jmp 0x5f79
movss (%r14), %xmm1
movss (%rbx), %xmm5
addss %xmm1, %xmm5
mulss 0x73ad(%rip), %xmm5     # 0xd2d0
movss %xmm5, -0x58(%rbp)
cvtss2sd %xmm1, %xmm2
mulsd %xmm2, %xmm2
cvtss2sd %xmm3, %xmm3
mulsd %xmm3, %xmm3
addsd %xmm2, %xmm3
addss %xmm1, %xmm1
mulss %xmm5, %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm3
cvtss2sd %xmm5, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm3, %xmm1
cvtss2sd %xmm4, %xmm2
mulsd %xmm2, %xmm2
subsd %xmm2, %xmm1
jmp 0x5cdd
callq 0x3370
xorps %xmm2, %xmm2
movss -0x2c(%rbp), %xmm4
movaps %xmm0, %xmm1
movss 0x4(%r14), %xmm0
subss %xmm4, %xmm0
ucomiss %xmm2, %xmm0
movaps %xmm1, -0x50(%rbp)
jb 0x5f92
sqrtss %xmm0, %xmm6
jmp 0x5f9f
callq 0x3370
movss -0x2c(%rbp), %xmm4
movaps %xmm0, %xmm6
movss -0x38(%rbp), %xmm2
movss -0x34(%rbp), %xmm3
movss -0x30(%rbp), %xmm1
mulss %xmm1, %xmm3
movss -0x40(%rbp), %xmm0
mulss %xmm0, %xmm2
subss %xmm0, %xmm1
movss 0x4(%rbx), %xmm0
subss %xmm4, %xmm0
xorps %xmm5, %xmm5
ucomiss %xmm5, %xmm0
jb 0x5fd6
sqrtss %xmm0, %xmm0
jmp 0x6008
movss %xmm1, -0x30(%rbp)
movss %xmm2, -0x38(%rbp)
movss %xmm3, -0x34(%rbp)
movss %xmm6, -0x5c(%rbp)
callq 0x3370
movss -0x5c(%rbp), %xmm6
movss -0x34(%rbp), %xmm3
movss -0x38(%rbp), %xmm2
movss -0x30(%rbp), %xmm1
movss -0x2c(%rbp), %xmm4
movss %xmm0, -0x40(%rbp)
movaps -0x50(%rbp), %xmm0
subss %xmm3, %xmm2
movss %xmm2, -0x38(%rbp)
mulss %xmm4, %xmm1
movss %xmm1, -0x30(%rbp)
mulss %xmm6, %xmm0
movaps %xmm0, -0x50(%rbp)
movss 0x4(%r14), %xmm0
subss 0x4(%rbx), %xmm0
movss %xmm0, -0x34(%rbp)
movq 0xdfae(%rip), %rdi      # 0x13ff0
leaq 0x736c(%rip), %rsi      # 0xd3b5
callq 0x31f0
movq %rax, %r15
movss (%r14), %xmm1
movss 0x4(%r14), %xmm2
movaps %xmm2, %xmm0
mulss %xmm2, %xmm0
movaps %xmm1, %xmm3
mulss %xmm1, %xmm3
addss %xmm0, %xmm3
movss 0x725e(%rip), %xmm5     # 0xd2d4
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 0x722a(%rip), %xmm0     # 0xd2d8
jb 0x60b6
sqrtss %xmm0, %xmm0
jmp 0x60bb
callq 0x3370
movss -0x30(%rbp), %xmm1
addss -0x38(%rbp), %xmm1
movss %xmm1, -0x30(%rbp)
movaps -0x50(%rbp), %xmm1
mulss -0x40(%rbp), %xmm1
movaps %xmm1, -0x50(%rbp)
movq %r15, %rdi
callq 0x3170
leaq 0x6fa1(%rip), %rsi      # 0xd087
movq %rax, %rdi
callq 0x31f0
movq %rax, %r15
movss 0x4(%r14), %xmm0
subss -0x2c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x610a
sqrtss %xmm0, %xmm0
jmp 0x610f
callq 0x3370
movaps -0x70(%rbp), %xmm2
movss -0x30(%rbp), %xmm1
divss %xmm2, %xmm1
movss %xmm1, -0x30(%rbp)
movaps -0x50(%rbp), %xmm1
divss -0x34(%rbp), %xmm1
movaps %xmm1, -0x50(%rbp)
movq %r15, %rdi
callq 0x3170
leaq 0x6f4a(%rip), %rsi      # 0xd087
movq %rax, %rdi
callq 0x31f0
movq %rax, %r15
movss 0x4(%rbx), %xmm0
subss -0x2c(%rbp), %xmm0
ucomiss 0x717f(%rip), %xmm0     # 0xd2d8
jb 0x6161
sqrtss %xmm0, %xmm0
jmp 0x6166
callq 0x3370
movss 0x4(%r14), %xmm1
subss 0x4(%rbx), %xmm1
divss %xmm1, %xmm0
movq %r15, %rdi
callq 0x3170
movq %rax, %rdi
callq 0x30d0
movq 0xde64(%rip), %rdi      # 0x13ff0
leaq 0x7222(%rip), %rsi      # 0xd3b5
callq 0x31f0
movq %rax, %rdi
movss -0x30(%rbp), %xmm0
callq 0x3170
leaq 0x7234(%rip), %rsi      # 0xd3e0
movq %rax, %rdi
callq 0x31f0
movq %rax, %rdi
movss -0x3c(%rbp), %xmm0
callq 0x3170
leaq 0x721c(%rip), %rsi      # 0xd3e4
movq %rax, %rdi
callq 0x31f0
movq %rax, %rdi
movaps -0x50(%rbp), %xmm0
callq 0x3170
movq %rax, %rdi
callq 0x30d0
movaps -0x50(%rbp), %xmm5
andps 0x70c1(%rip), %xmm5     # 0xd2b0
mulss -0x3c(%rbp), %xmm5
addss -0x30(%rbp), %xmm5
movss %xmm5, -0x58(%rbp)
movss (%r14), %xmm1
movss 0x4(%r14), %xmm0
movaps %xmm0, %xmm2
mulss %xmm0, %xmm2
movaps %xmm1, %xmm3
mulss %xmm1, %xmm3
addss %xmm2, %xmm3
mulss 0x70b1(%rip), %xmm1     # 0xd2d4
mulss %xmm5, %xmm1
addss %xmm3, %xmm1
movaps %xmm5, %xmm2
mulss %xmm5, %xmm2
addss %xmm1, %xmm2
movss -0x2c(%rbp), %xmm3
movaps %xmm3, %xmm1
mulss %xmm3, %xmm1
subss %xmm1, %xmm2
cvtss2sd %xmm2, %xmm1
subss %xmm3, %xmm0
jmp 0x5cdd
leaq 0x718e(%rip), %rdi      # 0xd3e8
leaq 0x70a9(%rip), %rsi      # 0xd30a
leaq 0x7191(%rip), %rcx      # 0xd3f9
movl $0x22a, %edx            # imm = 0x22A
callq 0x3130
leaq 0x71c2(%rip), %rdi      # 0xd43b
leaq 0x708a(%rip), %rsi      # 0xd30a
leaq 0x7172(%rip), %rcx      # 0xd3f9
movl $0x22b, %edx            # imm = 0x22B
callq 0x3130
leaq 0x71b4(%rip), %rdi      # 0xd44c
leaq 0x706b(%rip), %rsi      # 0xd30a
leaq 0x7153(%rip), %rcx      # 0xd3f9
movl $0x22c, %edx            # imm = 0x22C
callq 0x3130
leaq 0x71a6(%rip), %rdi      # 0xd45d
leaq 0x704c(%rip), %rsi      # 0xd30a
leaq 0x7134(%rip), %rcx      # 0xd3f9
movl $0x22d, %edx            # imm = 0x22D
callq 0x3130