// File: /workspace/github_cpp_makefile_star2_O3/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 0x12f66
movl %eax, %r13d
movq 0x2e05b(%rip), %rbx     # 0x40f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x136a6
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x21906(%rip), %rsi     # 0x34836
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 0x136a6
cmpl $0x0, 0x624(%rbx)
je 0x12fc5
leaq 0x22ac7(%rip), %rdi     # 0x35a3d
callq 0xa1f0
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x2dfd1(%rip), %rbx     # 0x40f60
leaq 0xc6d0(%rbx), %rdi
leaq 0x21899(%rip), %rsi     # 0x34836
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r13d
jmp 0x136a6
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 0x13076
cmpl $0x12c, %r12d           # imm = 0x12C
jne 0x135a2
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 0x130cc
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 0x2de73(%rip), %r12     # 0x40f60
movl 0x1690(%r12), %eax
movsd 0x20dc3(%rip), %xmm0    # 0x33ec0
movsd %xmm0, -0xc0(%rbp)
cmpl $0x3, %eax
je 0x13112
movsd 0x20d8e(%rip), %xmm0    # 0x33ea0
movsd 0x20dae(%rip), %xmm1    # 0x33ec8
movsd %xmm1, -0xc8(%rbp)
cmpl $0x1, %eax
je 0x1312a
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 0x20d63(%rip), %xmm0    # 0x33ec0
cmpl $0x3, %eax
je 0x1316a
movsd 0x20d36(%rip), %xmm0    # 0x33ea0
movsd 0x20d56(%rip), %xmm1    # 0x33ec8
cmpl $0x1, %eax
je 0x1317a
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 0x20d13(%rip), %xmm0    # 0x33ec0
cmpl $0x3, %eax
je 0x131ba
movsd 0x20ce6(%rip), %xmm0    # 0x33ea0
movsd 0x20d06(%rip), %xmm1    # 0x33ec8
cmpl $0x1, %eax
je 0x131ca
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 0x20c60(%rip), %xmm0    # 0x33ec0
cmpl $0x3, %eax
je 0x1326d
movsd 0x20c33(%rip), %xmm0    # 0x33ea0
movsd 0x20c53(%rip), %xmm1    # 0x33ec8
cmpl $0x1, %eax
je 0x1327d
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 0x20c18(%rip), %xmm1    # 0x33ec0
cmpl $0x3, %eax
je 0x132b5
movsd 0x20beb(%rip), %xmm1    # 0x33ea0
movsd 0x20c0b(%rip), %xmm5    # 0x33ec8
cmpl $0x1, %eax
movsd -0xb0(%rbp), %xmm2
movsd -0x40(%rbp), %xmm3
movsd -0x38(%rbp), %xmm4
je 0x132d7
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 0x13365
movsd 0x20b43(%rip), %xmm1    # 0x33ea0
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 0x13401
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 0x13490
movsd -0x110(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movb 0x280(%r14), %cl
cmpb $0x1, %cl
jne 0x134a9
movsd -0x108(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movb 0x290(%r14), %dl
cmpb $0x1, %dl
jne 0x134c2
movsd -0x100(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movb (%r14), %dil
cmpb $0x1, %dil
jne 0x134d8
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movb 0x10(%r14), %sil
cmpb $0x1, %sil
jne 0x134ef
movsd -0xf0(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movb 0x20(%r14), %r8b
cmpb $0x1, %r8b
jne 0x13506
movsd -0xe8(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movb 0x244(%r14), %r9b
cmpb $0x1, %r9b
jne 0x13520
movsd -0xe0(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movb 0x250(%r14), %r10b
cmpb $0x1, %r10b
jne 0x1353a
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movb 0x260(%r14), %r11b
cmpb $0x1, %r11b
jne 0x13554
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
je 0x135ae
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
jmp 0x13628
leaq 0x224c2(%rip), %rdi     # 0x35a6b
jmp 0x12f76
movsd -0x110(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x108(%rbp), %xmm1
movsd %xmm1, -0x80(%rbp)
movsd -0x100(%rbp), %xmm2
movsd %xmm2, -0x78(%rbp)
movsd -0xf8(%rbp), %xmm3
movsd %xmm3, -0x70(%rbp)
movsd -0xf0(%rbp), %xmm4
movsd %xmm4, -0x68(%rbp)
movsd -0xe8(%rbp), %xmm5
movsd %xmm5, -0x60(%rbp)
movsd -0xe0(%rbp), %xmm6
movsd %xmm6, -0x58(%rbp)
movsd -0xd8(%rbp), %xmm7
movsd %xmm7, -0x50(%rbp)
movsd -0xd0(%rbp), %xmm8
movsd %xmm8, -0x48(%rbp)
movl 0x1d0(%r14), %edi
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
nop