// File: sundale[P]gcode/rs274ngc/interp_find.cc
// Function: Interp::find_relative(double, double, double, double, double, double, double, double, double, double*, double*, double*, double*, double*, double*, double*, double*, double*, setup_struct*)
int Interp::find_relative(double x1,     //!< absolute x position        
                          double y1,     //!< absolute y position        
                          double z1,     //!< absolute z position        
                          double AA_1,   //!< absolute a position         
                          double BB_1,   //!< absolute b position         
                          double CC_1,   //!< absolute c position         
                          double u_1,
                          double v_1,
                          double w_1,
                          double *x2,    //!< pointer to relative x      
                          double *y2,    //!< pointer to relative y      
                          double *z2,    //!< pointer to relative z      
                          double *AA_2,  //!< pointer to relative a       
                          double *BB_2,  //!< pointer to relative b       
                          double *CC_2,  //!< pointer to relative c       
                          double *u_2,
                          double *v_2,
                          double *w_2,
                          setup_pointer settings)        //!< pointer to machine settings
{
  *x2 = x1 - settings->origin_offset_x - settings->axis_offset_x - settings->tool_offset.tran.x;
  *y2 = y1 - settings->origin_offset_y - settings->axis_offset_y - settings->tool_offset.tran.y;
  rotate(x2, y2, -settings->rotation_xy);
  *z2 = z1 - settings->origin_offset_z - settings->axis_offset_z - settings->tool_offset.tran.z;

  if(settings->a_axis_wrapped) {
      CHP(unwrap_rotary(AA_2, AA_1,
                        AA_1 - settings->AA_origin_offset - settings->AA_axis_offset - settings->tool_offset.a,
                        settings->AA_current, 'A'));
  } else {
      *AA_2 = AA_1 - settings->AA_origin_offset - settings->AA_axis_offset;
  }

  if(settings->b_axis_wrapped) {
      CHP(unwrap_rotary(BB_2, BB_1,
                        BB_1 - settings->BB_origin_offset - settings->BB_axis_offset - settings->tool_offset.b,
                        settings->BB_current, 'B'));
  } else {
      *BB_2 = BB_1 - settings->BB_origin_offset - settings->BB_axis_offset;
  }

  if(settings->c_axis_wrapped) {
      CHP(unwrap_rotary(CC_2, CC_1,
                        CC_1 - settings->CC_origin_offset - settings->CC_axis_offset - settings->tool_offset.c,
                        settings->CC_current, 'C'));
  } else {
      *CC_2 = CC_1 - settings->CC_origin_offset - settings->CC_axis_offset;
  }

  *u_2 = u_1 - settings->u_origin_offset - settings->u_axis_offset - settings->tool_offset.u;
  *v_2 = v_1 - settings->v_origin_offset - settings->v_axis_offset - settings->tool_offset.v;
  *w_2 = w_1 - settings->w_origin_offset - settings->w_axis_offset - settings->tool_offset.w;
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
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 %rcx, -0x68(%rbp)
movq %r8, -0x70(%rbp)
movq %r9, -0x78(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x90(%rbp)
movsd -0x18(%rbp), %xmm0
movq 0x38(%rbp), %rax
subsd 0x17a0(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0x118(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0xd678(%rax), %xmm0
movq -0x58(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x20(%rbp), %xmm0
movq 0x38(%rbp), %rax
subsd 0x17a8(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0x120(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0xd680(%rax), %xmm0
movq -0x60(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x38(%rbp), %rax
movsd 0x17b8(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x11cc0
movsd -0x28(%rbp), %xmm0
movq 0x38(%rbp), %rax
subsd 0x17b0(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0x128(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0xd688(%rax), %xmm0
movq -0x68(%rbp), %rax
movsd %xmm0, (%rax)
movq 0x38(%rbp), %rax
cmpl $0x0, 0x1e6cc(%rax)
je 0x58fc9
jmp 0x58eb6
movq -0x90(%rbp), %rdi
movq -0x70(%rbp), %rsi
movsd -0x30(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movq 0x38(%rbp), %rax
subsd 0x10(%rax), %xmm1
movq 0x38(%rbp), %rax
subsd (%rax), %xmm1
movq 0x38(%rbp), %rax
subsd 0xd690(%rax), %xmm1
movq 0x38(%rbp), %rax
movsd 0x8(%rax), %xmm2
movl $0x41, %edx
callq 0x11430
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0x7c(%rbp)
je 0x58fc5
jmp 0x58f0a
movq 0x2e04f(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x58fba
movq 0x2e03b(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x2e02d(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x23cf6(%rip), %rsi     # 0x7cc3e
movl $0x50, %edx
callq 0x10840
movq 0x2e007(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2dff9(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x2dfe1(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x2dfd1(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x2dfc4(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2dfb6(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0x7c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x59307
jmp 0x58fc7
jmp 0x58fe7
movsd -0x30(%rbp), %xmm0
movq 0x38(%rbp), %rax
subsd 0x10(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd (%rax), %xmm0
movq -0x70(%rbp), %rax
movsd %xmm0, (%rax)
movq 0x38(%rbp), %rax
cmpl $0x0, 0x1e6d0(%rax)
je 0x5910e
jmp 0x58ffa
movq -0x90(%rbp), %rdi
movq -0x78(%rbp), %rsi
movsd -0x38(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movq 0x38(%rbp), %rax
subsd 0x28(%rax), %xmm1
movq 0x38(%rbp), %rax
subsd 0x18(%rax), %xmm1
movq 0x38(%rbp), %rax
subsd 0xd698(%rax), %xmm1
movq 0x38(%rbp), %rax
movsd 0x20(%rax), %xmm2
movl $0x42, %edx
callq 0x11430
movl %eax, -0x80(%rbp)
cmpl $0x0, -0x80(%rbp)
je 0x5910a
jmp 0x5904f
movq 0x2df0a(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x590ff
movq 0x2def6(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x2dee8(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x23bb1(%rip), %rsi     # 0x7cc3e
movl $0x50, %edx
callq 0x10840
movq 0x2dec2(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2deb4(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x2de9c(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x2de8c(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x2de7f(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2de71(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0x80(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x59307
jmp 0x5910c
jmp 0x5912d
movsd -0x38(%rbp), %xmm0
movq 0x38(%rbp), %rax
subsd 0x28(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0x18(%rax), %xmm0
movq -0x78(%rbp), %rax
movsd %xmm0, (%rax)
movq 0x38(%rbp), %rax
cmpl $0x0, 0x1e6d4(%rax)
je 0x5925d
jmp 0x59140
movq -0x90(%rbp), %rdi
movq 0x18(%rbp), %rsi
movsd -0x40(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movq 0x38(%rbp), %rax
subsd 0x40(%rax), %xmm1
movq 0x38(%rbp), %rax
subsd 0x30(%rax), %xmm1
movq 0x38(%rbp), %rax
subsd 0xd6a0(%rax), %xmm1
movq 0x38(%rbp), %rax
movsd 0x38(%rax), %xmm2
movl $0x43, %edx
callq 0x11430
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x84(%rbp)
je 0x59259
jmp 0x5919b
movq 0x2ddbe(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x5924b
movq 0x2ddaa(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x2dd9c(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x23a65(%rip), %rsi     # 0x7cc3e
movl $0x50, %edx
callq 0x10840
movq 0x2dd76(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2dd68(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x2dd50(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x2dd40(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x2dd33(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2dd25(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0x84(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x59307
jmp 0x5925b
jmp 0x5927c
movsd -0x40(%rbp), %xmm0
movq 0x38(%rbp), %rax
subsd 0x40(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0x30(%rax), %xmm0
movq 0x18(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x48(%rbp), %xmm0
movq 0x38(%rbp), %rax
subsd 0x58(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0x48(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0xd6a8(%rax), %xmm0
movq 0x20(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x50(%rbp), %xmm0
movq 0x38(%rbp), %rax
subsd 0x70(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0x60(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0xd6b0(%rax), %xmm0
movq 0x28(%rbp), %rax
movsd %xmm0, (%rax)
movsd 0x10(%rbp), %xmm0
movq 0x38(%rbp), %rax
subsd 0x88(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0x78(%rax), %xmm0
movq 0x38(%rbp), %rax
subsd 0xd6b8(%rax), %xmm0
movq 0x30(%rbp), %rax
movsd %xmm0, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)