// File: /workspace/github_cpp_makefile_star2_O1/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_home(int, block_struct*, setup_struct*)
int Interp::convert_home(int move,       //!< G code, must be G_28 or G_30            
                        block_pointer block,    //!< pointer to a block of RS274 instructions
                        setup_pointer settings) //!< pointer to machine settings             
{
  double end_x;
  double end_y;
  double end_z;
  double AA_end;
  double BB_end;
  double CC_end;
  double u_end;
  double v_end;
  double w_end;
  double end_x_home;
  double end_y_home;
  double end_z_home;
  double AA_end_home;
  double BB_end_home;
  double CC_end_home;
  double u_end_home;
  double v_end_home;
  double w_end_home;
  double *parameters;

  parameters = settings->parameters;
  CHP(find_ends(block, settings, &end_x, &end_y, &end_z,
                &AA_end, &BB_end, &CC_end, 
                &u_end, &v_end, &w_end));

  CHKS((settings->cutter_comp_side != OFF),
      NCE_CANNOT_USE_G28_OR_G30_WITH_CUTTER_RADIUS_COMP);

  // waypoint is in currently active coordinate system

  STRAIGHT_TRAVERSE(block->line_number, end_x, end_y, end_z,
                    AA_end, BB_end, CC_end,
                    u_end, v_end, w_end);

  if (move == G_28) {
      find_relative(USER_TO_PROGRAM_LEN(parameters[5161]),
                    USER_TO_PROGRAM_LEN(parameters[5162]),
                    USER_TO_PROGRAM_LEN(parameters[5163]),
                    USER_TO_PROGRAM_ANG(parameters[5164]),
                    USER_TO_PROGRAM_ANG(parameters[5165]),
                    USER_TO_PROGRAM_ANG(parameters[5166]),
                    USER_TO_PROGRAM_LEN(parameters[5167]),
                    USER_TO_PROGRAM_LEN(parameters[5168]),
                    USER_TO_PROGRAM_LEN(parameters[5169]),
                    &end_x_home, &end_y_home, &end_z_home,
                    &AA_end_home, &BB_end_home, &CC_end_home, 
                    &u_end_home, &v_end_home, &w_end_home, settings);
  } else if (move == G_30) {
      find_relative(USER_TO_PROGRAM_LEN(parameters[5181]),
                    USER_TO_PROGRAM_LEN(parameters[5182]),
                    USER_TO_PROGRAM_LEN(parameters[5183]),
                    USER_TO_PROGRAM_ANG(parameters[5184]),
                    USER_TO_PROGRAM_ANG(parameters[5185]),
                    USER_TO_PROGRAM_ANG(parameters[5186]),
                    USER_TO_PROGRAM_LEN(parameters[5187]),
                    USER_TO_PROGRAM_LEN(parameters[5188]),
                    USER_TO_PROGRAM_LEN(parameters[5189]),
                    &end_x_home, &end_y_home, &end_z_home,
                    &AA_end_home, &BB_end_home, &CC_end_home, 
                    &u_end_home, &v_end_home, &w_end_home, settings);
  } else
    ERS(NCE_BUG_CODE_NOT_G28_OR_G30);
  
  // if any axes are specified, home only those axes after the waypoint 
  // (both fanuc & haas, contrary to emc historical operation)

  if (block->x_flag == ON) end_x = end_x_home;  
  if (block->y_flag == ON) end_y = end_y_home;  
  if (block->z_flag == ON) end_z = end_z_home;  
  if (block->a_flag == ON) AA_end = AA_end_home;
  if (block->b_flag == ON) BB_end = BB_end_home;
  if (block->c_flag == ON) CC_end = CC_end_home;
  if (block->u_flag == ON) u_end = u_end_home;  
  if (block->v_flag == ON) v_end = v_end_home;  
  if (block->w_flag == ON) w_end = w_end_home;  

  // but, if no axes are specified, home all of them 
  // (haas does this, emc historical did, throws an error in fanuc)

  if (block->x_flag == OFF && block->y_flag == OFF && block->z_flag == OFF &&
      block->a_flag == OFF && block->b_flag == OFF && block->c_flag == OFF &&
      block->u_flag == OFF && block->v_flag == OFF && block->w_flag == OFF) {
      end_x = end_x_home;  
      end_y = end_y_home;  
      end_z = end_z_home;  
      AA_end = AA_end_home;
      BB_end = BB_end_home;
      CC_end = CC_end_home;
      u_end = u_end_home;  
      v_end = v_end_home;  
      w_end = w_end_home;  
  }

  STRAIGHT_TRAVERSE(block->line_number, end_x, end_y, end_z,
                    AA_end, BB_end, CC_end,
                    u_end, v_end, w_end);
  settings->current_x = end_x;
  settings->current_y = end_y;
  settings->current_z = end_z;
  settings->AA_current = AA_end;
  settings->BB_current = BB_end;
  settings->CC_current = CC_end;
  settings->u_current = u_end;
  settings->v_current = v_end;
  settings->w_current = w_end;
  
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rcx, %rbx
movq %rdx, %r14
movl %esi, %r12d
movq %rdi, %r15
leaq -0x48(%rbp), %rax
movq %rax, 0x28(%rsp)
leaq -0x50(%rbp), %rax
movq %rax, 0x20(%rsp)
leaq -0x58(%rbp), %rax
movq %rax, 0x18(%rsp)
leaq -0x60(%rbp), %rax
movq %rax, 0x10(%rsp)
leaq -0x68(%rbp), %rax
movq %rax, 0x8(%rsp)
leaq -0x70(%rbp), %rax
movq %rax, (%rsp)
leaq -0x88(%rbp), %rcx
leaq -0x80(%rbp), %r8
leaq -0x78(%rbp), %r9
movq %rdx, %rsi
movq %rbx, %rdx
callq 0xaa70
testl %eax, %eax
je 0x13934
movl %eax, %r13d
movq 0x3068d(%rip), %rbx     # 0x43f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x1406b
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x23f38(%rip), %rsi     # 0x37836
movl $0x50, %edx
callq 0xa8a0
movslq 0xd670(%rbx), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%rbx,%rcx)
incl %eax
movl %eax, 0xd670(%rbx)
movb %dl, 0xc720(%rbx,%rcx)
jmp 0x1406b
cmpl $0x0, 0x624(%rbx)
je 0x1399d
leaq 0x250f9(%rip), %rdi     # 0x38a3d
callq 0xa1f0
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x30603(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0x23ec1(%rip), %rsi     # 0x37836
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r13d
jmp 0x1406b
movl 0x1d0(%r14), %edi
movsd -0x88(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
movsd -0x78(%rbp), %xmm2
movsd -0x70(%rbp), %xmm3
movsd -0x68(%rbp), %xmm4
movsd -0x60(%rbp), %xmm5
movsd -0x58(%rbp), %xmm6
movsd -0x50(%rbp), %xmm7
movsd -0x48(%rbp), %xmm8
movsd %xmm8, (%rsp)
callq 0xa8d0
cmpl $0x118, %r12d           # imm = 0x118
je 0x13a4e
cmpl $0x12c, %r12d           # imm = 0x12C
jne 0x14080
movl $0xb9e8, %eax           # imm = 0xB9E8
movq %rax, -0xa8(%rbp)
movl $0xb9e0, %eax           # imm = 0xB9E0
movq %rax, -0x30(%rbp)
movl $0xb9d8, %eax           # imm = 0xB9D8
movq %rax, -0x38(%rbp)
movl $0xb9d0, %eax           # imm = 0xB9D0
movq %rax, -0x90(%rbp)
movl $0xb9c8, %eax           # imm = 0xB9C8
movq %rax, -0x98(%rbp)
movl $0xb9c0, %eax           # imm = 0xB9C0
movq %rax, -0xa0(%rbp)
movl $0xb9b8, %eax           # imm = 0xB9B8
movq %rax, -0x40(%rbp)
movl $0xb9b0, %r13d          # imm = 0xB9B0
movl $0xb9a8, %eax           # imm = 0xB9A8
jmp 0x13aa4
movl $0xb948, %eax           # imm = 0xB948
movq %rax, -0xa8(%rbp)
movl $0xb940, %eax           # imm = 0xB940
movq %rax, -0x30(%rbp)
movl $0xb938, %eax           # imm = 0xB938
movq %rax, -0x38(%rbp)
movl $0xb930, %eax           # imm = 0xB930
movq %rax, -0x90(%rbp)
movl $0xb928, %eax           # imm = 0xB928
movq %rax, -0x98(%rbp)
movl $0xb920, %eax           # imm = 0xB920
movq %rax, -0xa0(%rbp)
movl $0xb918, %eax           # imm = 0xB918
movq %rax, -0x40(%rbp)
movl $0xb910, %r13d          # imm = 0xB910
movl $0xb908, %eax           # imm = 0xB908
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0xb8(%rbp)
callq 0xa990
movsd %xmm0, -0x168(%rbp)
movq 0x3049b(%rip), %r12     # 0x43f60
movl 0x1690(%r12), %eax
movsd 0x233eb(%rip), %xmm0    # 0x36ec0
movsd %xmm0, -0xc0(%rbp)
cmpl $0x3, %eax
je 0x13aea
movsd 0x233b6(%rip), %xmm0    # 0x36ea0
movsd 0x233d6(%rip), %xmm1    # 0x36ec8
movsd %xmm1, -0xc8(%rbp)
cmpl $0x1, %eax
je 0x13b02
movaps %xmm0, %xmm1
movsd %xmm1, -0x170(%rbp)
movsd (%rbx,%r13), %xmm0
movsd %xmm0, -0xb0(%rbp)
callq 0xa990
movsd %xmm0, -0x158(%rbp)
movl 0x1690(%r12), %eax
movsd 0x2338b(%rip), %xmm0    # 0x36ec0
cmpl $0x3, %eax
je 0x13b42
movsd 0x2335e(%rip), %xmm0    # 0x36ea0
movsd 0x2337e(%rip), %xmm1    # 0x36ec8
cmpl $0x1, %eax
je 0x13b52
movaps %xmm0, %xmm1
movsd %xmm1, -0x160(%rbp)
movq -0x40(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0xa990
movsd %xmm0, -0x140(%rbp)
movl 0x1690(%r12), %eax
movsd 0x2333b(%rip), %xmm0    # 0x36ec0
cmpl $0x3, %eax
je 0x13b92
movsd 0x2330e(%rip), %xmm0    # 0x36ea0
movsd 0x2332e(%rip), %xmm1    # 0x36ec8
cmpl $0x1, %eax
je 0x13ba2
movaps %xmm0, %xmm1
movsd %xmm1, -0x150(%rbp)
movq -0xa0(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
callq 0xaf60
movsd %xmm0, -0x148(%rbp)
movq -0x98(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
callq 0xaf60
movsd %xmm0, -0x138(%rbp)
movq -0x90(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0x90(%rbp)
callq 0xaf60
movsd %xmm0, -0x130(%rbp)
movq -0x38(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0xa990
movsd %xmm0, -0x120(%rbp)
movl 0x1690(%r12), %eax
movsd 0x23288(%rip), %xmm0    # 0x36ec0
cmpl $0x3, %eax
je 0x13c45
movsd 0x2325b(%rip), %xmm0    # 0x36ea0
movsd 0x2327b(%rip), %xmm1    # 0x36ec8
cmpl $0x1, %eax
je 0x13c55
movaps %xmm0, %xmm1
movsd %xmm1, -0x128(%rbp)
movq -0x30(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movl 0x1690(%r12), %eax
movsd 0x23240(%rip), %xmm1    # 0x36ec0
cmpl $0x3, %eax
je 0x13c8d
movsd 0x23213(%rip), %xmm1    # 0x36ea0
movsd 0x23233(%rip), %xmm5    # 0x36ec8
cmpl $0x1, %eax
movsd -0xb0(%rbp), %xmm2
movsd -0x40(%rbp), %xmm3
movsd -0x38(%rbp), %xmm4
je 0x13caf
movaps %xmm1, %xmm5
movsd %xmm5, -0x118(%rbp)
movsd -0xb8(%rbp), %xmm1
divsd -0x168(%rbp), %xmm1
movsd %xmm1, -0xb8(%rbp)
divsd -0x158(%rbp), %xmm2
movsd %xmm2, -0xb0(%rbp)
divsd -0x140(%rbp), %xmm3
movsd %xmm3, -0x40(%rbp)
divsd -0x120(%rbp), %xmm4
movsd %xmm4, -0x38(%rbp)
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movq -0xa8(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
callq 0xa990
movl 0x1690(%r12), %eax
cmpl $0x3, %eax
je 0x13d3d
movsd 0x2316b(%rip), %xmm1    # 0x36ea0
movsd %xmm1, -0xc0(%rbp)
movsd -0xb8(%rbp), %xmm8
divsd -0x170(%rbp), %xmm8
movsd -0xb0(%rbp), %xmm1
divsd -0x160(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
divsd -0x150(%rbp), %xmm2
movsd -0xa0(%rbp), %xmm3
divsd -0x148(%rbp), %xmm3
movsd -0x98(%rbp), %xmm4
divsd -0x138(%rbp), %xmm4
movsd -0x90(%rbp), %xmm5
divsd -0x130(%rbp), %xmm5
movsd -0x38(%rbp), %xmm6
divsd -0x128(%rbp), %xmm6
movsd -0x30(%rbp), %xmm7
divsd -0x118(%rbp), %xmm7
movsd -0xa8(%rbp), %xmm9
divsd %xmm0, %xmm9
cmpl $0x1, %eax
je 0x13dd9
movsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
divsd -0xc8(%rbp), %xmm9
movq %rbx, 0x28(%rsp)
leaq -0xd0(%rbp), %rax
movq %rax, 0x20(%rsp)
leaq -0xd8(%rbp), %rax
movq %rax, 0x18(%rsp)
leaq -0xe0(%rbp), %rax
movq %rax, 0x10(%rsp)
leaq -0xe8(%rbp), %rax
movq %rax, 0x8(%rsp)
movsd %xmm9, (%rsp)
leaq -0x110(%rbp), %rsi
leaq -0x108(%rbp), %rdx
leaq -0x100(%rbp), %rcx
leaq -0xf8(%rbp), %r8
leaq -0xf0(%rbp), %r9
movq %r15, %rdi
movapd %xmm8, %xmm0
callq 0xa400
movb 0x270(%r14), %al
cmpb $0x1, %al
jne 0x13e68
movsd -0x110(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movb 0x280(%r14), %cl
cmpb $0x1, %cl
jne 0x13e81
movsd -0x108(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movb 0x290(%r14), %dl
cmpb $0x1, %dl
jne 0x13e9a
movsd -0x100(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movb (%r14), %dil
cmpb $0x1, %dil
jne 0x13eb0
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movb 0x10(%r14), %sil
cmpb $0x1, %sil
jne 0x13ec7
movsd -0xf0(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movb 0x20(%r14), %r8b
cmpb $0x1, %r8b
jne 0x13ede
movsd -0xe8(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movb 0x244(%r14), %r9b
cmpb $0x1, %r9b
jne 0x13ef8
movsd -0xe0(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movb 0x250(%r14), %r10b
cmpb $0x1, %r10b
jne 0x13f12
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movb 0x260(%r14), %r11b
cmpb $0x1, %r11b
jne 0x13f2c
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
orb %al, %cl
orb %dil, %dl
orb %cl, %dl
orb %r8b, %sil
orb %r9b, %sil
orb %dl, %sil
orb %r10b, %sil
orb %r11b, %sil
jne 0x13fbc
movsd -0x110(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x108(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x100(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0xf0(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0xe8(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0xe0(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movl 0x1d0(%r14), %edi
movsd -0x88(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
movsd -0x78(%rbp), %xmm2
movsd -0x70(%rbp), %xmm3
movsd -0x68(%rbp), %xmm4
movsd -0x60(%rbp), %xmm5
movsd -0x58(%rbp), %xmm6
movsd -0x50(%rbp), %xmm7
movsd -0x48(%rbp), %xmm8
movsd %xmm8, (%rsp)
callq 0xa8d0
movsd -0x88(%rbp), %xmm0
movsd %xmm0, 0x600(%rbx)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, 0x608(%rbx)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, 0x610(%rbx)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, 0x8(%rbx)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, 0x20(%rbx)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, 0x38(%rbx)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, 0x50(%rbx)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, 0x68(%rbx)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, 0x80(%rbx)
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x249e4(%rip), %rdi     # 0x38a6b
jmp 0x13944