// File: /workspace/github_cpp_makefile_star2_O1/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_tool_change(setup_struct*)
int Interp::convert_tool_change(setup_pointer settings)  //!< pointer to machine settings
{

  if (settings->selected_pocket < 0) {
    ERS(NCE_TXX_MISSING_FOR_M6);
  }

  CHKS((settings->cutter_comp_side != OFF),
       (_("Cannot change tools with cutter radius compensation on")));

  if (!settings->tool_change_with_spindle_on) {
      STOP_SPINDLE_TURNING();
      settings->spindle_turning = CANON_STOPPED;
  }

  if (settings->tool_change_quill_up) {
      double up_z;
      double discard;
      find_relative(0., 0., 0., 0., 0., 0., 0., 0., 0., 
                    &discard, &discard, &up_z,
                    &discard, &discard, &discard, 
                    &discard, &discard, &discard,
                    settings);
      COMMENT("AXIS,hide");
      STRAIGHT_TRAVERSE(-1, settings->current_x, settings->current_y, up_z,
                        settings->AA_current, settings->BB_current, settings->CC_current,
                        settings->u_current, settings->v_current, settings->w_current);
      COMMENT("AXIS,show");
      settings->current_z = up_z;
  }

  if (settings->tool_change_at_g30) {
      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;

      find_relative(USER_TO_PROGRAM_LEN(settings->parameters[5181]),
                    USER_TO_PROGRAM_LEN(settings->parameters[5182]),
                    USER_TO_PROGRAM_LEN(settings->parameters[5183]),
                    USER_TO_PROGRAM_ANG(settings->parameters[5184]),
                    USER_TO_PROGRAM_ANG(settings->parameters[5185]),
                    USER_TO_PROGRAM_ANG(settings->parameters[5186]),
                    USER_TO_PROGRAM_LEN(settings->parameters[5187]),
                    USER_TO_PROGRAM_LEN(settings->parameters[5188]),
                    USER_TO_PROGRAM_LEN(settings->parameters[5189]),
                    &end_x, &end_y, &end_z,
                    &AA_end, &BB_end, &CC_end, 
                    &u_end, &v_end, &w_end, settings);
      COMMENT("AXIS,hide");
      STRAIGHT_TRAVERSE(-1, end_x, end_y, end_z,
                        AA_end, BB_end, CC_end,
                        u_end, v_end, w_end);
      COMMENT("AXIS,show");
      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;
  }

  CHANGE_TOOL(settings->selected_pocket);

  settings->current_pocket = settings->selected_pocket;
  // tool change can move the controlled point.  reread it:
  settings->toolchange_flag = ON; 
  set_tool_parameters();
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %rbx
cmpl $0x0, 0xc6b0(%rsi)
js 0x14b0b
movq %rsi, %r14
cmpl $0x0, 0x624(%rsi)
je 0x14b6a
leaq 0x24bbf(%rip), %rdi     # 0x396c8
jmp 0x14b12
leaq 0x24b8e(%rip), %rdi     # 0x396a0
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x2f435(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0x22d95(%rip), %rsi     # 0x378d8
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %eax
jmp 0x150fc
cmpl $0x0, 0x1e6c8(%r14)
jne 0x14b84
callq 0xabb0
movl $0x1, 0xc6cc(%r14)
cmpl $0x0, 0x1e6c4(%r14)
je 0x14c5e
movq %r14, 0x28(%rsp)
leaq -0x108(%rbp), %rdx
movq %rdx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq $0x0, (%rsp)
leaq -0x60(%rbp), %r15
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
xorps %xmm4, %xmm4
xorps %xmm5, %xmm5
xorps %xmm6, %xmm6
xorps %xmm7, %xmm7
movq %rbx, %rdi
movq %rdx, %rsi
movq %r15, %rcx
movq %rdx, %r8
movq %rdx, %r9
callq 0xa400
leaq 0x24b0e(%rip), %rdi     # 0x396ff
callq 0xa800
movsd 0x600(%r14), %xmm0
movsd 0x608(%r14), %xmm1
movsd (%r15), %xmm2
movsd 0x8(%r14), %xmm3
movsd 0x20(%r14), %xmm4
movsd 0x38(%r14), %xmm5
movsd 0x50(%r14), %xmm6
movsd 0x68(%r14), %xmm7
movsd 0x80(%r14), %xmm8
movsd %xmm8, (%rsp)
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xa8d0
leaq 0x24abe(%rip), %rdi     # 0x39709
callq 0xa800
movsd (%r15), %xmm0
movsd %xmm0, 0x610(%r14)
cmpl $0x0, 0x1e6c0(%r14)
je 0x150d0
movsd 0xb9a8(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movsd %xmm0, -0x38(%rbp)
movq 0x2f2d5(%rip), %r15     # 0x43f60
movl 0x1690(%r15), %eax
movsd 0x22226(%rip), %xmm0    # 0x36ec0
movsd %xmm0, -0x68(%rbp)
cmpl $0x3, %eax
je 0x14cac
movsd 0x221f4(%rip), %xmm0    # 0x36ea0
movsd 0x22214(%rip), %xmm1    # 0x36ec8
movsd %xmm1, -0x70(%rbp)
cmpl $0x1, %eax
je 0x14cc1
movaps %xmm0, %xmm1
movsd %xmm1, -0x100(%rbp)
movsd 0xb9b0(%r14), %xmm0
movsd %xmm0, -0x58(%rbp)
callq 0xa990
movsd %xmm0, -0xd8(%rbp)
movl 0x1690(%r15), %eax
movsd 0x221cd(%rip), %xmm0    # 0x36ec0
cmpl $0x3, %eax
je 0x14d00
movsd 0x221a0(%rip), %xmm0    # 0x36ea0
movsd 0x221c0(%rip), %xmm1    # 0x36ec8
cmpl $0x1, %eax
je 0x14d10
movaps %xmm0, %xmm1
movsd %xmm1, -0xe0(%rbp)
movsd 0xb9b8(%r14), %xmm0
movsd %xmm0, -0x50(%rbp)
callq 0xa990
movsd %xmm0, -0xc0(%rbp)
movl 0x1690(%r15), %eax
movsd 0x2217e(%rip), %xmm0    # 0x36ec0
cmpl $0x3, %eax
je 0x14d4f
movsd 0x22151(%rip), %xmm0    # 0x36ea0
movsd 0x22171(%rip), %xmm1    # 0x36ec8
cmpl $0x1, %eax
je 0x14d5f
movaps %xmm0, %xmm1
movsd %xmm1, -0xd0(%rbp)
movsd 0xb9c0(%r14), %xmm0
movsd %xmm0, -0xf8(%rbp)
callq 0xaf60
movsd %xmm0, -0xc8(%rbp)
movsd 0xb9c8(%r14), %xmm0
movsd %xmm0, -0xf0(%rbp)
callq 0xaf60
movsd %xmm0, -0xb8(%rbp)
movsd 0xb9d0(%r14), %xmm0
movsd %xmm0, -0xe8(%rbp)
callq 0xaf60
movsd %xmm0, -0xb0(%rbp)
movsd 0xb9d8(%r14), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0xa990
movsd %xmm0, -0xa0(%rbp)
movl 0x1690(%r15), %eax
movsd 0x220d5(%rip), %xmm0    # 0x36ec0
cmpl $0x3, %eax
je 0x14df8
movsd 0x220a8(%rip), %xmm0    # 0x36ea0
movsd 0x220c8(%rip), %xmm1    # 0x36ec8
cmpl $0x1, %eax
je 0x14e08
movaps %xmm0, %xmm1
movsd %xmm1, -0xa8(%rbp)
movsd 0xb9e0(%r14), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0xa990
movl 0x1690(%r15), %eax
movsd 0x2208e(%rip), %xmm1    # 0x36ec0
cmpl $0x3, %eax
je 0x14e3f
movsd 0x22061(%rip), %xmm1    # 0x36ea0
movsd 0x22081(%rip), %xmm5    # 0x36ec8
cmpl $0x1, %eax
movsd -0x58(%rbp), %xmm2
movsd -0x50(%rbp), %xmm3
movsd -0x48(%rbp), %xmm4
je 0x14e5e
movaps %xmm1, %xmm5
movsd %xmm5, -0x98(%rbp)
movsd -0x30(%rbp), %xmm1
divsd -0x38(%rbp), %xmm1
movsd %xmm1, -0x30(%rbp)
divsd -0xd8(%rbp), %xmm2
movsd %xmm2, -0x58(%rbp)
divsd -0xc0(%rbp), %xmm3
movsd %xmm3, -0x50(%rbp)
divsd -0xa0(%rbp), %xmm4
movsd %xmm4, -0x48(%rbp)
movsd -0x40(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x40(%rbp)
movsd 0xb9e8(%r14), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0xa990
movl 0x1690(%r15), %eax
cmpl $0x3, %eax
je 0x14ed6
movsd 0x21fcf(%rip), %xmm1    # 0x36ea0
movsd %xmm1, -0x68(%rbp)
movsd -0x30(%rbp), %xmm8
divsd -0x100(%rbp), %xmm8
movsd -0x58(%rbp), %xmm1
divsd -0xe0(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
divsd -0xd0(%rbp), %xmm2
movsd -0xf8(%rbp), %xmm3
divsd -0xc8(%rbp), %xmm3
movsd -0xf0(%rbp), %xmm4
divsd -0xb8(%rbp), %xmm4
movsd -0xe8(%rbp), %xmm5
divsd -0xb0(%rbp), %xmm5
movsd -0x48(%rbp), %xmm6
divsd -0xa8(%rbp), %xmm6
movsd -0x40(%rbp), %xmm7
divsd -0x98(%rbp), %xmm7
movsd -0x38(%rbp), %xmm9
divsd %xmm0, %xmm9
cmpl $0x1, %eax
je 0x14f63
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
divsd -0x70(%rbp), %xmm9
movq %r14, 0x28(%rsp)
leaq -0x78(%rbp), %rax
movq %rax, 0x20(%rsp)
leaq -0x80(%rbp), %rax
movq %rax, 0x18(%rsp)
leaq -0x88(%rbp), %rax
movq %rax, 0x10(%rsp)
leaq -0x90(%rbp), %rax
movq %rax, 0x8(%rsp)
movsd %xmm9, (%rsp)
leaq -0x60(%rbp), %rsi
leaq -0x108(%rbp), %rdx
leaq -0x120(%rbp), %r13
leaq -0x118(%rbp), %r12
leaq -0x110(%rbp), %r15
movq %rbx, %rdi
movapd %xmm8, %xmm0
movq %rbx, -0x30(%rbp)
movq %rdx, %rbx
movq %r13, %rcx
movq %r12, %r8
movq %r15, %r9
callq 0xa400
leaq 0x2471d(%rip), %rdi     # 0x396ff
callq 0xa800
leaq -0x60(%rbp), %rax
movsd (%rax), %xmm0
movsd (%rbx), %xmm1
movsd (%r13), %xmm2
movsd (%r12), %xmm3
movsd (%r15), %xmm4
leaq -0x90(%rbp), %rax
movsd (%rax), %xmm5
leaq -0x88(%rbp), %rax
movsd (%rax), %xmm6
leaq -0x80(%rbp), %rax
movsd (%rax), %xmm7
leaq -0x78(%rbp), %rax
movsd (%rax), %xmm8
movsd %xmm8, (%rsp)
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xa8d0
leaq 0x246c7(%rip), %rdi     # 0x39709
callq 0xa800
leaq -0x60(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x600(%r14)
movsd (%rbx), %xmm0
movq -0x30(%rbp), %rbx
movsd %xmm0, 0x608(%r14)
movsd (%r13), %xmm0
movsd %xmm0, 0x610(%r14)
movsd (%r12), %xmm0
movsd %xmm0, 0x8(%r14)
movsd (%r15), %xmm0
movsd %xmm0, 0x20(%r14)
leaq -0x90(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%r14)
leaq -0x88(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%r14)
leaq -0x80(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%r14)
leaq -0x78(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x80(%r14)
movl 0xc6b0(%r14), %edi
callq 0xa2d0
movl 0xc6b0(%r14), %eax
movl %eax, 0x5fc(%r14)
movb $0x1, 0xc682(%r14)
movq %rbx, %rdi
callq 0xaf90
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq