// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r15
movq %r8, %rbx
movq %rcx, %r12
movsd %xmm7, -0x38(%rbp)
movsd %xmm6, -0x30(%rbp)
movsd %xmm5, -0x40(%rbp)
movsd %xmm4, -0x48(%rbp)
movsd %xmm3, -0x50(%rbp)
movsd %xmm2, -0x58(%rbp)
movq 0x38(%rbp), %r13
subsd 0x17a0(%r13), %xmm0
subsd 0x118(%r13), %xmm0
subsd 0xd678(%r13), %xmm0
movq %rdi, %r14
movsd %xmm0, (%rsi)
subsd 0x17a8(%r13), %xmm1
subsd 0x120(%r13), %xmm1
subsd 0xd680(%r13), %xmm1
movsd %xmm1, (%rdx)
movsd 0x17b8(%r13), %xmm0
xorps 0xd61d(%rip), %xmm0     # 0x2ff10
callq 0xc300
movsd -0x50(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
subsd 0x17b0(%r13), %xmm1
subsd 0x128(%r13), %xmm1
subsd 0xd688(%r13), %xmm1
movsd %xmm1, (%r12)
cmpl $0x0, 0x1e6cc(%r13)
movapd %xmm0, %xmm1
subsd 0x10(%r13), %xmm1
subsd (%r13), %xmm1
je 0x22964
subsd 0xd690(%r13), %xmm1
movsd 0x8(%r13), %xmm2
pushq $0x41
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0xbd80
testl %eax, %eax
jne 0x229f0
jmp 0x22968
movsd %xmm1, (%rbx)
cmpl $0x0, 0x1e6d0(%r13)
movsd -0x48(%rbp), %xmm0
movapd %xmm0, %xmm1
subsd 0x28(%r13), %xmm1
subsd 0x18(%r13), %xmm1
je 0x229aa
subsd 0xd698(%r13), %xmm1
movsd 0x20(%r13), %xmm2
pushq $0x42
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0xbd80
testl %eax, %eax
jne 0x229f0
jmp 0x229af
movsd %xmm1, (%r15)
movq 0x18(%rbp), %rsi
cmpl $0x0, 0x1e6d4(%r13)
movsd -0x40(%rbp), %xmm0
movapd %xmm0, %xmm1
subsd 0x40(%r13), %xmm1
subsd 0x30(%r13), %xmm1
je 0x22a50
subsd 0xd6a0(%r13), %xmm1
movsd 0x38(%r13), %xmm2
pushq $0x43
popq %rdx
movq %r14, %rdi
callq 0xbd80
testl %eax, %eax
je 0x22a54
movl %eax, %ebx
movq 0x1a567(%rip), %r14     # 0x3cf60
movslq 0xd670(%r14), %rax
cmpq $0x30, %rax
jg 0x22abf
imulq $0x50, %rax, %rax
leaq (%r14,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x10f7c(%rip), %rsi     # 0x3399c
pushq $0x50
popq %rdx
callq 0xb940
movslq 0xd670(%r14), %rax
imulq $0x50, %rax, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%r14,%rcx)
incl %eax
movl %eax, 0xd670(%r14)
movb %dl, 0xc720(%r14,%rcx)
jmp 0x22abf
movsd %xmm1, (%rsi)
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rcx
movsd -0x30(%rbp), %xmm0
subsd 0x58(%r13), %xmm0
subsd 0x48(%r13), %xmm0
movq 0x20(%rbp), %rdx
subsd 0xd6a8(%r13), %xmm0
movsd %xmm0, (%rdx)
movsd -0x38(%rbp), %xmm1
subsd 0x70(%r13), %xmm1
subsd 0x60(%r13), %xmm1
movsd 0x10(%rbp), %xmm0
subsd 0xd6b0(%r13), %xmm1
movsd %xmm1, (%rcx)
subsd 0x88(%r13), %xmm0
subsd 0x78(%r13), %xmm0
subsd 0xd6b8(%r13), %xmm0
movsd %xmm0, (%rax)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq