// File: /workspace/github_cpp_makefile_star2_O2/hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::IntersectPoint(ClipperLib::TEdge&, ClipperLib::TEdge&, ClipperLib::IntPoint&, bool)
bool IntersectPoint(TEdge &Edge1, TEdge &Edge2,
  IntPoint &ip, bool UseFullInt64Range)
{
#ifdef use_xyz  
  ip.Z = 0;
#endif
  double b1, b2;
  //nb: with very large coordinate values, it's possible for SlopesEqual() to 
  //return false but for the edge.Dx value be equal due to double precision rounding.
  if (SlopesEqual(Edge1, Edge2, UseFullInt64Range) || Edge1.Dx == Edge2.Dx)
  {
    if (Edge2.Bot.Y > Edge1.Bot.Y) ip = Edge2.Bot;
    else ip = Edge1.Bot;
    return false;
  }
  else if (Edge1.Delta.X == 0)
  {
    ip.X = Edge1.Bot.X;
    if (IsHorizontal(Edge2))
      ip.Y = Edge2.Bot.Y;
    else
    {
      b2 = Edge2.Bot.Y - (Edge2.Bot.X / Edge2.Dx);
      ip.Y = Round(ip.X / Edge2.Dx + b2);
    }
  }
  else if (Edge2.Delta.X == 0)
  {
    ip.X = Edge2.Bot.X;
    if (IsHorizontal(Edge1))
      ip.Y = Edge1.Bot.Y;
    else
    {
      b1 = Edge1.Bot.Y - (Edge1.Bot.X / Edge1.Dx);
      ip.Y = Round(ip.X / Edge1.Dx + b1);
    }
  } 
  else 
  {
    b1 = Edge1.Bot.X - Edge1.Bot.Y * Edge1.Dx;
    b2 = Edge2.Bot.X - Edge2.Bot.Y * Edge2.Dx;
    double q = (b2-b1) / (Edge1.Dx - Edge2.Dx);
    ip.Y = Round(q);
    if (std::fabs(Edge1.Dx) < std::fabs(Edge2.Dx))
      ip.X = Round(Edge1.Dx * q + b1);
    else 
      ip.X = Round(Edge2.Dx * q + b2);
  }

  if (ip.Y < Edge1.Top.Y || ip.Y < Edge2.Top.Y) 
  {
    if (Edge1.Top.Y > Edge2.Top.Y)
      ip.Y = Edge1.Top.Y;
    else
      ip.Y = Edge2.Top.Y;
    if (std::fabs(Edge1.Dx) < std::fabs(Edge2.Dx))
      ip.X = TopX(Edge1, ip.Y);
    else
      ip.X = TopX(Edge2, ip.Y);
  } 
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movl %ecx, %edx
callq 0x7ee7
testb %al, %al
jne 0x809c
movsd 0x40(%r15), %xmm0
movsd 0x40(%r14), %xmm1
ucomisd %xmm1, %xmm0
jne 0x80c5
jp 0x80c5
movq 0x8(%r14), %rax
cmpq 0x8(%r15), %rax
jle 0x80ad
movupd (%r14), %xmm0
jmp 0x80b2
movupd (%r15), %xmm0
movupd %xmm0, (%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x30(%r15)
je 0x81c2
cmpq $0x0, 0x30(%r14)
je 0x81f0
cvtsi2sdq (%r15), %xmm2
cvtsi2sdq 0x8(%r15), %xmm3
mulsd %xmm0, %xmm3
cvtsi2sdq (%r14), %xmm5
cvtsi2sdq 0x8(%r14), %xmm4
subsd %xmm3, %xmm2
mulsd %xmm1, %xmm4
subsd %xmm4, %xmm5
movapd %xmm5, %xmm3
subsd %xmm2, %xmm3
movapd %xmm0, %xmm4
subsd %xmm1, %xmm4
divsd %xmm4, %xmm3
xorpd %xmm6, %xmm6
movapd %xmm3, %xmm8
cmpltsd %xmm6, %xmm8
movsd 0xb594(%rip), %xmm4     # 0x136c0
movapd %xmm8, %xmm9
andpd %xmm4, %xmm9
movsd 0xae82(%rip), %xmm7     # 0x12fc0
andnpd %xmm7, %xmm8
orpd %xmm9, %xmm8
addsd %xmm3, %xmm8
cvttsd2si %xmm8, %rax
movq %rax, 0x8(%rbx)
movapd 0xad81(%rip), %xmm8     # 0x12ee0
movapd %xmm0, %xmm9
andpd %xmm8, %xmm9
andpd %xmm1, %xmm8
cmpltsd %xmm8, %xmm9
movapd %xmm1, %xmm8
mulsd %xmm3, %xmm8
addsd %xmm5, %xmm8
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
andpd %xmm9, %xmm3
andnpd %xmm8, %xmm9
orpd %xmm3, %xmm9
movapd %xmm9, %xmm2
cmpltsd %xmm6, %xmm2
andpd %xmm2, %xmm4
andnpd %xmm7, %xmm2
orpd %xmm4, %xmm2
addsd %xmm9, %xmm2
cvttsd2si %xmm2, %rcx
movq %rcx, (%rbx)
jmp 0x8242
movq (%r15), %rcx
movq %rcx, (%rbx)
cmpq $0x0, 0x38(%r14)
movq 0x8(%r14), %rax
je 0x823e
cvtsi2sd %rax, %xmm2
cvtsi2sdq (%r14), %xmm3
divsd %xmm1, %xmm3
subsd %xmm3, %xmm2
cvtsi2sd %rcx, %xmm3
divsd %xmm1, %xmm3
jmp 0x821c
movq (%r14), %rcx
movq %rcx, (%rbx)
cmpq $0x0, 0x38(%r15)
movq 0x8(%r15), %rax
je 0x823e
cvtsi2sd %rax, %xmm2
cvtsi2sdq (%r15), %xmm3
divsd %xmm0, %xmm3
subsd %xmm3, %xmm2
cvtsi2sd %rcx, %xmm3
divsd %xmm0, %xmm3
addsd %xmm2, %xmm3
xorpd %xmm2, %xmm2
xorl %eax, %eax
ucomisd %xmm3, %xmm2
seta %al
leaq 0xb4bc(%rip), %rcx      # 0x136f0
addsd (%rcx,%rax,8), %xmm3
cvttsd2si %xmm3, %rax
movq %rax, 0x8(%rbx)
movq 0x28(%r15), %rcx
cmpq %rcx, %rax
setl %dl
movq 0x28(%r14), %rsi
cmpq %rsi, %rax
setl %al
orb %dl, %al
movb $0x1, %bpl
cmpb $0x1, %al
jne 0x80b8
cmpq %rsi, %rcx
cmovgq %rcx, %rsi
movq %rsi, 0x8(%rbx)
movapd 0xac6a(%rip), %xmm2     # 0x12ee0
andpd %xmm2, %xmm0
andpd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8289
movq %r15, %rdi
jmp 0x828c
movq %r14, %rdi
callq 0xf607
movq %rax, (%rbx)
jmp 0x80b8