// File: sundale[P]gcode/rs274ngc/interp_inverse.cc
// Function: Interp::inverse_time_rate_straight(double, double, double, double, double, double, double, double, double, block_struct*, setup_struct*)
int Interp::inverse_time_rate_straight(double end_x,     //!< x coordinate of end point of straight line
                                       double end_y,     //!< y coordinate of end point of straight line
                                       double end_z,     //!< z coordinate of end point of straight line
                                       double AA_end,    //!< A coordinate of end point of straight line/*AA*/
                                       double BB_end,    //!< B coordinate of end point of straight line/*BB*/
                                       double CC_end,    //!< C coordinate of end point of straight line/*CC*/
                                       double u_end, double v_end, double w_end,
                                       block_pointer block,      //!< pointer to a block of RS274 instructions  
                                       setup_pointer settings)   //!< pointer to machine settings               
{
  double length;
  double rate;
  double cx, cy, cz;

  if (settings->feed_mode != INVERSE_TIME) return -1;

  if (settings->cutter_comp_side != OFF && settings->cutter_comp_radius > 0.0 &&
      settings->cutter_comp_firstmove == OFF) {
      cx = settings->program_x;
      cy = settings->program_y;
      cz = settings->program_z;
  } else {
      cx = settings->current_x;
      cy = settings->current_y;
      cz = settings->current_z;
  }

  length = find_straight_length(end_x, end_y, end_z,
                                AA_end, BB_end, CC_end,
                                u_end, v_end, w_end,
                                cx, cy, cz,
                                settings->AA_current, settings->BB_current, settings->CC_current,
                                settings->u_current, settings->v_current, settings->w_current);

  rate = MAX(0.1, (length * block->f_number));
  enqueue_SET_FEED_RATE(rate);
  settings->feed_rate = rate;

  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movsd 0x10(%rbp), %xmm8
movq %rdi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
movsd %xmm2, -0x28(%rbp)
movsd %xmm3, -0x30(%rbp)
movsd %xmm4, -0x38(%rbp)
movsd %xmm5, -0x40(%rbp)
movsd %xmm6, -0x48(%rbp)
movsd %xmm7, -0x50(%rbp)
movq %rsi, -0x58(%rbp)
movq %rdx, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x60(%rbp), %rax
cmpl $0x1, 0x670(%rax)
je 0x5bf09
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5c12e
movq -0x60(%rbp), %rax
cmpl $0x0, 0x624(%rax)
je 0x5bf77
movq -0x60(%rbp), %rax
movsd 0x618(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5bf77
movq -0x60(%rbp), %rax
movb 0xc689(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5bf77
movq -0x60(%rbp), %rax
movsd 0xc690(%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x60(%rbp), %rax
movsd 0xc698(%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x60(%rbp), %rax
movsd 0xc6a0(%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
jmp 0x5bfad
movq -0x60(%rbp), %rax
movsd 0x600(%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x60(%rbp), %rax
movsd 0x608(%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x60(%rbp), %rax
movsd 0x610(%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x90(%rbp), %rdi
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x20(%rbp), %xmm1
movsd -0x28(%rbp), %xmm2
movsd -0x30(%rbp), %xmm3
movsd -0x38(%rbp), %xmm4
movsd -0x40(%rbp), %xmm5
movsd -0x48(%rbp), %xmm6
movsd -0x50(%rbp), %xmm7
movsd 0x10(%rbp), %xmm8
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x80(%rbp), %xmm15
movsd -0x88(%rbp), %xmm14
movq -0x60(%rbp), %rax
movsd 0x8(%rax), %xmm13
movq -0x60(%rbp), %rax
movsd 0x20(%rax), %xmm12
movq -0x60(%rbp), %rax
movsd 0x38(%rax), %xmm11
movq -0x60(%rbp), %rax
movsd 0x50(%rax), %xmm10
movq -0x60(%rbp), %rax
movsd 0x68(%rax), %xmm9
movq -0x60(%rbp), %rax
movsd 0x80(%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm8, (%rsp)
movsd -0xa0(%rbp), %xmm8
movsd %xmm8, 0x8(%rsp)
movsd -0x98(%rbp), %xmm8
movsd %xmm15, 0x10(%rsp)
movsd %xmm14, 0x18(%rsp)
movsd %xmm13, 0x20(%rsp)
movsd %xmm12, 0x28(%rsp)
movsd %xmm11, 0x30(%rsp)
movsd %xmm10, 0x38(%rsp)
movsd %xmm9, 0x40(%rsp)
movsd %xmm8, 0x48(%rsp)
callq 0x10760
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm1
movq -0x58(%rbp), %rax
mulsd 0x148(%rax), %xmm1
movsd 0x1af32(%rip), %xmm0    # 0x77000
ucomisd %xmm1, %xmm0
jbe 0x5c0e6
movsd 0x1af24(%rip), %xmm0    # 0x77000
movsd %xmm0, -0xb0(%rbp)
jmp 0x5c0ff
movsd -0x68(%rbp), %xmm0
movq -0x58(%rbp), %rax
mulsd 0x148(%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
callq 0x10ce0
movsd -0x70(%rbp), %xmm0
movq -0x60(%rbp), %rax
movsd %xmm0, 0x678(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw (%rax,%rax)