// File: realuptime[P]PolyDetector/PolyDetector.cpp
// Function: PolyLine::LineLineIntersectionPoint(PolyLine const&, vec&) const
bool PolyLine::LineLineIntersectionPoint(const PolyLine &line, PointType &pos) const
{
    auto &c = line.a;
    auto &d = line.b;
    
    // Line AB represented as a1x + b1y = c1
    double a1 = b.y - a.y;
    double b1 = a.x - b.x;
    double c1 = a1*(a.x) + b1*(a.y);
  
    // Line CD represented as a2x + b2y = c2
    double a2 = d.y - c.y;
    double b2 = c.x - d.x;
    double c2 = a2*(c.x)+ b2*(c.y);
  
    double determinant = a1*b2 - a2*b1;
  
    if (determinant == 0)
    {
        // The lines are parallel. This is simplified
        // by returning a pair of FLT_MAX
        return false;
    }

    double x = (b2*c1 - b1*c2)/determinant;
    double y = (a1*c2 - a2*c1)/determinant;
    pos = PointType(x, y, 0.0f);
    
    return true;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movq 0x78(%rsp), %rax
movq 0x70(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movq 0x70(%rsp), %rcx
addq $0x8, %rcx
movq %rcx, 0x58(%rsp)
movss 0xc(%rax), %xmm0
subss 0x4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
movss (%rax), %xmm0
subss 0x8(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x50(%rsp), %xmm0
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x48(%rsp), %xmm1
movss 0x4(%rax), %xmm3
cvtss2sd %xmm3, %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x58(%rsp), %rax
movss 0x4(%rax), %xmm0
movq 0x60(%rsp), %rax
subss 0x4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x60(%rsp), %rax
movss (%rax), %xmm0
movq 0x58(%rsp), %rax
subss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x38(%rsp), %xmm0
movq 0x60(%rsp), %rax
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x30(%rsp), %xmm1
movq 0x60(%rsp), %rax
movss 0x4(%rax), %xmm3
cvtss2sd %xmm3, %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x50(%rsp), %xmm0
movsd 0x30(%rsp), %xmm2
movsd 0x38(%rsp), %xmm1
mulsd 0x48(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2957
jp 0x2957
movb $0x0, 0x87(%rsp)
jmp 0x2a13
movsd 0x30(%rsp), %xmm0
movsd 0x40(%rsp), %xmm2
movsd 0x48(%rsp), %xmm1
mulsd 0x28(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x50(%rsp), %xmm0
movsd 0x28(%rsp), %xmm2
movsd 0x38(%rsp), %xmm1
mulsd 0x40(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm1
leaq 0x8(%rsp), %rdi
xorps %xmm2, %xmm2
callq 0x12870
movq 0x68(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movb $0x1, 0x87(%rsp)
movb 0x87(%rsp), %al
andb $0x1, %al
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)