// File: sundale[P]gcode/rs274ngc/interp_find.cc
// Function: Interp::find_turn(double, double, double, double, int, double, double)
double Interp::find_turn(double x1,      //!< X-coordinate of start point       
                        double y1,      //!< Y-coordinate of start point       
                        double center_x,        //!< X-coordinate of arc center        
                        double center_y,        //!< Y-coordinate of arc center        
                        int turn,       //!< no. of full or partial circles CCW
                        double x2,      //!< X-coordinate of end point         
                        double y2)      //!< Y-coordinate of end point         
{
  double alpha;                 /* angle of first radius */
  double beta;                  /* angle of second radius */
  double theta;                 /* amount of turn of arc CCW - negative if CW */

  if (turn == 0)
    return 0.0;
  alpha = atan2((y1 - center_y), (x1 - center_x));
  beta = atan2((y2 - center_y), (x2 - center_x));
  if (turn > 0) {
    if (beta <= alpha)
      beta = (beta + (2 * M_PIl));
    theta = ((beta - alpha) + ((turn - 1) * (2 * M_PIl)));
  } else {                      /* turn < 0 */

    if (alpha <= beta)
      alpha = (alpha + (2 * M_PIl));
    theta = ((beta - alpha) + ((turn + 1) * (2 * M_PIl)));
  }
  return (theta);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
movsd %xmm2, -0x28(%rbp)
movsd %xmm3, -0x30(%rbp)
movl %esi, -0x34(%rbp)
movsd %xmm4, -0x40(%rbp)
movsd %xmm5, -0x48(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x56c33
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x56d59
movsd -0x20(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
subsd -0x28(%rbp), %xmm1
callq 0x101d0
movsd %xmm0, -0x50(%rbp)
movsd -0x48(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
subsd -0x28(%rbp), %xmm1
callq 0x101d0
movsd %xmm0, -0x58(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x56cef
movsd -0x58(%rbp), %xmm1
movsd -0x50(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x56ca3
fldl -0x58(%rbp)
fldt 0x22212(%rip)           # 0x78ea0
faddp %st, %st(1)
fstpl -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
fldl -0x98(%rbp)
movl -0x34(%rbp), %eax
decl %eax
movl %eax, -0x8c(%rbp)
fildl -0x8c(%rbp)
fldt 0x221ca(%rip)           # 0x78ea0
fmulp %st, %st(1)
faddp %st, %st(1)
fstpl -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x56d4f
movsd -0x50(%rbp), %xmm1
movsd -0x58(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x56d17
fldl -0x50(%rbp)
fldt 0x22198(%rip)           # 0x78ea0
faddp %st, %st(1)
fstpl -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x58(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
fldl -0x78(%rbp)
movl -0x34(%rbp), %eax
incl %eax
movl %eax, -0x6c(%rbp)
fildl -0x6c(%rbp)
fldt 0x22162(%rip)           # 0x78ea0
fmulp %st, %st(1)
faddp %st, %st(1)
fstpl -0x80(%rbp)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)