// File: /workspace/github_cpp_makefile_star2_O2/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 0x14b29
movq %rsi, %r14
cmpl $0x0, 0x624(%rsi)
je 0x14b79
leaq 0x1dbab(%rip), %rdi     # 0x326d2
jmp 0x14b30
leaq 0x1db7a(%rip), %rdi     # 0x326aa
callq 0xb220
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x28417(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x1bd81(%rip), %rsi     # 0x308d8
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %rax
jmp 0x15104
cmpl $0x0, 0x1e6c8(%r14)
jne 0x14b93
callq 0xbca0
movl $0x1, 0xc6cc(%r14)
cmpl $0x0, 0x1e6c4(%r14)
je 0x14c68
movq %r14, 0x28(%rsp)
leaq -0x108(%rbp), %rdx
movq %rdx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
andq $0x0, (%rsp)
movq %rdx, 0x8(%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 0xb440
leaq 0x1db0c(%rip), %rdi     # 0x32709
callq 0xb870
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)
pushq $-0x1
popq %rdi
callq 0xb970
leaq 0x1dabe(%rip), %rdi     # 0x32713
callq 0xb870
movsd (%r15), %xmm0
movsd %xmm0, 0x610(%r14)
cmpl $0x0, 0x1e6c0(%r14)
je 0x150d8
movsd 0xb9a8(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xba40
movsd %xmm0, -0x38(%rbp)
movq 0x282cb(%rip), %r15     # 0x3cf60
movl 0x1690(%r15), %eax
movsd 0x1b21c(%rip), %xmm0    # 0x2fec0
movsd %xmm0, -0x68(%rbp)
cmpl $0x3, %eax
je 0x14cb6
movsd 0x1b1ea(%rip), %xmm0    # 0x2fea0
movsd 0x1b20a(%rip), %xmm1    # 0x2fec8
movsd %xmm1, -0x70(%rbp)
cmpl $0x1, %eax
je 0x14ccb
movaps %xmm0, %xmm1
movsd %xmm1, -0x100(%rbp)
movsd 0xb9b0(%r14), %xmm0
movsd %xmm0, -0x58(%rbp)
callq 0xba40
movsd %xmm0, -0xd8(%rbp)
movl 0x1690(%r15), %eax
movsd 0x1b1c3(%rip), %xmm0    # 0x2fec0
cmpl $0x3, %eax
je 0x14d0a
movsd 0x1b196(%rip), %xmm0    # 0x2fea0
movsd 0x1b1b6(%rip), %xmm1    # 0x2fec8
cmpl $0x1, %eax
je 0x14d1a
movaps %xmm0, %xmm1
movsd %xmm1, -0xe0(%rbp)
movsd 0xb9b8(%r14), %xmm0
movsd %xmm0, -0x50(%rbp)
callq 0xba40
movsd %xmm0, -0xc0(%rbp)
movl 0x1690(%r15), %eax
movsd 0x1b174(%rip), %xmm0    # 0x2fec0
cmpl $0x3, %eax
je 0x14d59
movsd 0x1b147(%rip), %xmm0    # 0x2fea0
movsd 0x1b167(%rip), %xmm1    # 0x2fec8
cmpl $0x1, %eax
je 0x14d69
movaps %xmm0, %xmm1
movsd %xmm1, -0xd0(%rbp)
movsd 0xb9c0(%r14), %xmm0
movsd %xmm0, -0xf8(%rbp)
callq 0xc090
movsd %xmm0, -0xc8(%rbp)
movsd 0xb9c8(%r14), %xmm0
movsd %xmm0, -0xf0(%rbp)
callq 0xc090
movsd %xmm0, -0xb8(%rbp)
movsd 0xb9d0(%r14), %xmm0
movsd %xmm0, -0xe8(%rbp)
callq 0xc090
movsd %xmm0, -0xb0(%rbp)
movsd 0xb9d8(%r14), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0xba40
movsd %xmm0, -0xa0(%rbp)
movl 0x1690(%r15), %eax
movsd 0x1b0cb(%rip), %xmm0    # 0x2fec0
cmpl $0x3, %eax
je 0x14e02
movsd 0x1b09e(%rip), %xmm0    # 0x2fea0
movsd 0x1b0be(%rip), %xmm1    # 0x2fec8
cmpl $0x1, %eax
je 0x14e12
movaps %xmm0, %xmm1
movsd %xmm1, -0xa8(%rbp)
movsd 0xb9e0(%r14), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0xba40
movl 0x1690(%r15), %eax
movsd 0x1b084(%rip), %xmm1    # 0x2fec0
cmpl $0x3, %eax
je 0x14e49
movsd 0x1b057(%rip), %xmm1    # 0x2fea0
movsd 0x1b077(%rip), %xmm5    # 0x2fec8
cmpl $0x1, %eax
movsd -0x58(%rbp), %xmm2
movsd -0x50(%rbp), %xmm3
movsd -0x48(%rbp), %xmm4
je 0x14e68
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 0xba40
movl 0x1690(%r15), %eax
cmpl $0x3, %eax
je 0x14ee0
movsd 0x1afc5(%rip), %xmm1    # 0x2fea0
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 0x14f6d
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), %r15
leaq -0x118(%rbp), %r12
leaq -0x110(%rbp), %r13
movq %rbx, %rdi
movapd %xmm8, %xmm0
movq %rbx, -0x30(%rbp)
movq %rdx, %rbx
movq %r15, %rcx
movq %r12, %r8
movq %r13, %r9
callq 0xb440
leaq 0x1d71d(%rip), %rdi     # 0x32709
callq 0xb870
leaq -0x60(%rbp), %rax
movsd (%rax), %xmm0
movsd (%rbx), %xmm1
movsd (%r15), %xmm2
movsd (%r12), %xmm3
movsd (%r13), %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)
pushq $-0x1
popq %rdi
callq 0xb970
leaq 0x1d6c9(%rip), %rdi     # 0x32713
callq 0xb870
leaq -0x60(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x600(%r14)
movsd (%rbx), %xmm0
movq -0x30(%rbp), %rbx
movsd %xmm0, 0x608(%r14)
movsd (%r15), %xmm0
movsd %xmm0, 0x610(%r14)
movsd (%r12), %xmm0
movsd %xmm0, 0x8(%r14)
movsd (%r13), %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 0xb300
movl 0xc6b0(%r14), %eax
movl %eax, 0x5fc(%r14)
movb $0x1, 0xc682(%r14)
movq %rbx, %rdi
callq 0xc0c0
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq