// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %r8, %r15
movq %rcx, %r12
movsd %xmm7, -0x48(%rbp)
movsd %xmm6, -0x40(%rbp)
movsd %xmm5, -0x30(%rbp)
movsd %xmm4, -0x38(%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, %rbx
movsd %xmm0, (%rsi)
subsd 0x17a8(%r13), %xmm1
subsd 0x120(%r13), %xmm1
subsd 0xd680(%r13), %xmm1
movsd %xmm1, (%rdx)
movsd 0x17b8(%r13), %xmm0
xorps 0xf03b(%rip), %xmm0     # 0x36f10
callq 0xb1a0
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 0x27fc3
subsd 0xd690(%r13), %xmm1
movsd 0x8(%r13), %xmm2
movq %rbx, %rdi
movq %r15, %rsi
movl $0x41, %edx
callq 0xac90
movl %eax, %r15d
testl %eax, %eax
je 0x27fc8
movq 0x1c010(%rip), %r12     # 0x43f60
movslq 0xd670(%r12), %rax
cmpq $0x30, %rax
jg 0x27fae
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%r12,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x12a2c(%rip), %rsi     # 0x3a9a4
movl $0x50, %edx
callq 0xa8a0
movslq 0xd670(%r12), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%r12,%rcx)
incl %eax
movl %eax, 0xd670(%r12)
movb %dl, 0xc720(%r12,%rcx)
testl %r15d, %r15d
movsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm3
jne 0x281b8
jmp 0x27fd2
movsd %xmm1, (%r15)
movsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm3
cmpl $0x0, 0x1e6d0(%r13)
movapd %xmm3, %xmm1
subsd 0x28(%r13), %xmm1
subsd 0x18(%r13), %xmm1
je 0x28094
subsd 0xd698(%r13), %xmm1
movsd 0x20(%r13), %xmm2
movq %rbx, %rdi
movq %r14, %rsi
movapd %xmm3, %xmm0
movl $0x42, %edx
callq 0xac90
movsd -0x30(%rbp), %xmm0
movl %eax, %r14d
testl %eax, %eax
je 0x28089
movq 0x1bf3a(%rip), %r15     # 0x43f60
movslq 0xd670(%r15), %rax
cmpq $0x30, %rax
jg 0x28086
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%r15,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x12957(%rip), %rsi     # 0x3a9a4
movl $0x50, %edx
callq 0xa8a0
movsd -0x30(%rbp), %xmm0
movslq 0xd670(%r15), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%r15,%rcx)
incl %eax
movl %eax, 0xd670(%r15)
movb %dl, 0xc720(%r15,%rcx)
movl %r14d, %r15d
testl %r14d, %r14d
jne 0x281b8
jmp 0x28099
movsd %xmm1, (%r14)
movq 0x18(%rbp), %rsi
cmpl $0x0, 0x1e6d4(%r13)
movapd %xmm0, %xmm1
subsd 0x40(%r13), %xmm1
subsd 0x30(%r13), %xmm1
je 0x28148
subsd 0xd6a0(%r13), %xmm1
movsd 0x38(%r13), %xmm2
movq %rbx, %rdi
movl $0x43, %edx
callq 0xac90
movl %eax, %ebx
testl %eax, %eax
je 0x28142
movq 0x1be7c(%rip), %r14     # 0x43f60
movslq 0xd670(%r14), %rax
cmpq $0x30, %rax
jg 0x2813f
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%r14,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x12899(%rip), %rsi     # 0x3a9a4
movl $0x50, %edx
callq 0xa8a0
movslq 0xd670(%r14), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%r14,%rcx)
incl %eax
movl %eax, 0xd670(%r14)
movb %dl, 0xc720(%r14,%rcx)
movl %ebx, %r15d
testl %ebx, %ebx
jne 0x281b8
jmp 0x2814c
movsd %xmm1, (%rsi)
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rcx
movsd -0x40(%rbp), %xmm0
subsd 0x58(%r13), %xmm0
subsd 0x48(%r13), %xmm0
movq 0x20(%rbp), %rdx
subsd 0xd6a8(%r13), %xmm0
movsd %xmm0, (%rdx)
movsd -0x48(%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 %r15d, %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq