// File: /workspace/github_cpp_makefile_star2_O1/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_stop(block_struct*, setup_struct*)
int Interp::convert_stop(block_pointer block,    //!< pointer to a block of RS274/NGC instructions
                        setup_pointer settings) //!< pointer to machine settings                 
{
  int index;
  char *line;
  int length;

  double cx, cy, cz;
  comp_get_current(settings, &cx, &cy, &cz);
  CHP(move_endpoint_and_flush(settings, cx, cy));
  dequeue_canons(settings);

  if (block->m_modes[4] == 0) {
    PROGRAM_STOP();
  } else if (block->m_modes[4] == 60) {
    PALLET_SHUTTLE();
    PROGRAM_STOP();
  } else if (block->m_modes[4] == 1) {
    OPTIONAL_PROGRAM_STOP();
  } else if ((block->m_modes[4] == 2) || (block->m_modes[4] == 30)) {   /* reset stuff here */
/*1*/
    settings->current_x += settings->origin_offset_x;
    settings->current_y += settings->origin_offset_y;
    settings->current_z += settings->origin_offset_z;
    settings->AA_current += settings->AA_origin_offset;
    settings->BB_current += settings->BB_origin_offset;
    settings->CC_current += settings->CC_origin_offset;
    settings->u_current += settings->u_origin_offset;
    settings->v_current += settings->v_origin_offset;
    settings->w_current += settings->w_origin_offset;
    rotate(&settings->current_x, &settings->current_y, settings->rotation_xy);

    settings->origin_index = 1;
    settings->parameters[5220] = 1.0;
    settings->origin_offset_x = USER_TO_PROGRAM_LEN(settings->parameters[5221]);
    settings->origin_offset_y = USER_TO_PROGRAM_LEN(settings->parameters[5222]);
    settings->origin_offset_z = USER_TO_PROGRAM_LEN(settings->parameters[5223]);
    settings->AA_origin_offset = USER_TO_PROGRAM_ANG(settings->parameters[5224]);
    settings->BB_origin_offset = USER_TO_PROGRAM_ANG(settings->parameters[5225]);
    settings->CC_origin_offset = USER_TO_PROGRAM_ANG(settings->parameters[5226]);
    settings->u_origin_offset = USER_TO_PROGRAM_LEN(settings->parameters[5227]);
    settings->v_origin_offset = USER_TO_PROGRAM_LEN(settings->parameters[5228]);
    settings->w_origin_offset = USER_TO_PROGRAM_LEN(settings->parameters[5229]);
    settings->rotation_xy = settings->parameters[5230];

    rotate(&settings->current_x, &settings->current_y, -settings->rotation_xy);
    settings->current_x -= settings->origin_offset_x;
    settings->current_y -= settings->origin_offset_y;
    settings->current_z -= settings->origin_offset_z;
    settings->AA_current -= settings->AA_origin_offset;
    settings->BB_current -= settings->BB_origin_offset;
    settings->CC_current -= settings->CC_origin_offset;
    settings->u_current -= settings->u_origin_offset;
    settings->v_current -= settings->v_origin_offset;
    settings->w_current -= settings->w_origin_offset;

    SET_ORIGIN_OFFSETS(settings->origin_offset_x + settings->axis_offset_x,
                       settings->origin_offset_y + settings->axis_offset_y,
                       settings->origin_offset_z + settings->axis_offset_z,
                       settings->AA_origin_offset + settings->AA_axis_offset,
                       settings->BB_origin_offset + settings->BB_axis_offset,
                       settings->CC_origin_offset + settings->CC_axis_offset,
                       settings->u_origin_offset + settings->u_axis_offset,
                       settings->v_origin_offset + settings->v_axis_offset,
                       settings->w_origin_offset + settings->w_axis_offset);
    SET_XY_ROTATION(settings->rotation_xy);

/*2*/ if (settings->plane != CANON_PLANE_XY) {
      SELECT_PLANE(CANON_PLANE_XY);
      settings->plane = CANON_PLANE_XY;
    }

/*3*/
    settings->distance_mode = MODE_ABSOLUTE;

/*4*/ settings->feed_mode = UNITS_PER_MINUTE;
    SET_FEED_MODE(0);
    settings->feed_rate = block->f_number;
    SET_FEED_RATE(0);

/*5*/ if (settings->feed_override != ON) {
      ENABLE_FEED_OVERRIDE();
      settings->feed_override = ON;
    }
    if (settings->speed_override != ON) {
      ENABLE_SPEED_OVERRIDE();
      settings->speed_override = ON;
    }

/*6*/
    settings->cutter_comp_side = OFF;
    settings->cutter_comp_firstmove = ON;

/*7*/ STOP_SPINDLE_TURNING();
    settings->spindle_turning = CANON_STOPPED;

    /* turn off FPR */
    SET_SPINDLE_MODE(0);

/*8*/ settings->motion_mode = G_1;

/*9*/ if (settings->mist == ON) {
      MIST_OFF();
      settings->mist = OFF;
    }
    if (settings->flood == ON) {
      FLOOD_OFF();
      settings->flood = OFF;
    }

    if (block->m_modes[4] == 30)
      PALLET_SHUTTLE();
    PROGRAM_END();
    if (_setup.percent_flag == ON && _setup.file_pointer) {
      line = _setup.linetext;
      for (;;) {                /* check for ending percent sign and comment if missing */
        if (fgets(line, LINELEN, _setup.file_pointer) == NULL) {
          enqueue_COMMENT("interpreter: percent sign missing from end of file");
          break;
        }
        length = strlen(line);
        if (length == (LINELEN - 1)) {       // line is too long. need to finish reading the line
          for (; fgetc(_setup.file_pointer) != '\n';);
          continue;
        }
        for (index = (length - 1);      // index set on last char
             (index >= 0) && (isspace(line[index])); index--);
        if (line[index] == '%') // found line with % at end
        {
          for (index--; (index >= 0) && (isspace(line[index])); index--);
          if (index == -1)      // found line with only percent sign
            break;
        }
      }
    }
    return INTERP_EXIT;
  } else
    ERS(NCE_BUG_CODE_NOT_M0_M1_M2_M30_M60);
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r12
leaq -0x68(%rbp), %r15
leaq -0x60(%rbp), %r13
leaq -0x58(%rbp), %r8
movq %rdx, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0xb6b0
movsd (%r15), %xmm0
movsd (%r13), %xmm1
movq %r12, %rdi
movq %r14, %rsi
callq 0xa760
testl %eax, %eax
je 0x17655
movl %eax, %r15d
movq 0x2c96c(%rip), %rbx     # 0x43f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x17f2d
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x2044e(%rip), %rsi     # 0x37a6d
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 0x17f2d
movq %r14, %rdi
callq 0xa300
movl 0x1f0(%rbx), %eax
cmpl $0x1, %eax
jle 0x17685
cmpl $0x2, %eax
je 0x176a0
cmpl $0x1e, %eax
je 0x176a0
cmpl $0x3c, %eax
jne 0x17ed2
callq 0xb590
jmp 0x17ec8
testl %eax, %eax
je 0x17ec8
cmpl $0x1, %eax
jne 0x17ed2
callq 0xa980
jmp 0x17ecd
movsd 0x17a0(%r14), %xmm0
addsd 0x600(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd %xmm0, 0x600(%r14)
movsd 0x17a8(%r14), %xmm0
addsd 0x608(%r14), %xmm0
movsd %xmm0, 0x608(%r14)
movsd 0x17b0(%r14), %xmm0
addsd 0x610(%r14), %xmm0
movsd %xmm0, 0x610(%r14)
movsd 0x10(%r14), %xmm0
movsd 0x28(%r14), %xmm1
addsd 0x8(%r14), %xmm0
movsd %xmm0, 0x8(%r14)
addsd 0x20(%r14), %xmm1
movsd %xmm1, 0x20(%r14)
movsd 0x40(%r14), %xmm0
addsd 0x38(%r14), %xmm0
movsd %xmm0, 0x38(%r14)
movsd 0x58(%r14), %xmm0
addsd 0x50(%r14), %xmm0
movsd %xmm0, 0x50(%r14)
movsd 0x70(%r14), %xmm0
addsd 0x68(%r14), %xmm0
movsd %xmm0, 0x68(%r14)
movsd 0x88(%r14), %xmm0
addsd 0x80(%r14), %xmm0
movsd %xmm0, 0x80(%r14)
movsd 0x17b8(%r14), %xmm0
mulsd 0x1f754(%rip), %xmm0    # 0x36ed0
divsd 0x1f754(%rip), %xmm0    # 0x36ed8
movsd %xmm0, -0x38(%rbp)
callq 0xb550
movsd %xmm0, -0x40(%rbp)
movsd 0x608(%r14), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0xa1d0
mulsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
mulsd -0x30(%rbp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, -0x40(%rbp)
movsd 0x600(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0xa1d0
movsd %xmm0, -0x48(%rbp)
movsd 0x608(%r14), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0xb550
mulsd -0x50(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
mulsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
movsd %xmm0, 0x600(%r14)
movsd %xmm1, 0x608(%r14)
movl $0x1, 0x179c(%r14)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0xbae0(%r14)
movsd 0xbae8(%r14), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0xa990
movq 0x2c708(%rip), %r13     # 0x43f60
movl 0x1690(%r13), %eax
movsd 0x1f659(%rip), %xmm1    # 0x36ec0
movsd %xmm1, -0x40(%rbp)
cmpl $0x3, %eax
je 0x17879
movsd 0x1f627(%rip), %xmm1    # 0x36ea0
movsd -0x38(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1f63e(%rip), %xmm0    # 0x36ec8
movsd %xmm0, -0x38(%rbp)
cmpl $0x1, %eax
je 0x17898
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x17a0(%r14)
movsd 0xbaf0(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movl 0x1690(%r13), %eax
movsd 0x1f5f9(%rip), %xmm1    # 0x36ec0
cmpl $0x3, %eax
je 0x178d4
movsd 0x1f5cc(%rip), %xmm1    # 0x36ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1f5e3(%rip), %xmm0    # 0x36ec8
cmpl $0x1, %eax
je 0x178ee
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x17a8(%r14)
movsd 0xbaf8(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movl 0x1690(%r13), %eax
movsd 0x1f5a3(%rip), %xmm1    # 0x36ec0
cmpl $0x3, %eax
je 0x1792a
movsd 0x1f576(%rip), %xmm1    # 0x36ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1f58d(%rip), %xmm0    # 0x36ec8
cmpl $0x1, %eax
je 0x17944
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x17b0(%r14)
movsd 0xbb00(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xaf60
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%r14)
movsd 0xbb08(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xaf60
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%r14)
movsd 0xbb10(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xaf60
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x40(%r14)
movsd 0xbb18(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movl 0x1690(%r13), %eax
movsd 0x1f4e7(%rip), %xmm1    # 0x36ec0
cmpl $0x3, %eax
je 0x179e6
movsd 0x1f4ba(%rip), %xmm1    # 0x36ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1f4d1(%rip), %xmm0    # 0x36ec8
cmpl $0x1, %eax
je 0x17a00
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x58(%r14)
movsd 0xbb20(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movl 0x1690(%r13), %eax
movsd 0x1f494(%rip), %xmm1    # 0x36ec0
cmpl $0x3, %eax
je 0x17a39
movsd 0x1f467(%rip), %xmm1    # 0x36ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1f47e(%rip), %xmm0    # 0x36ec8
cmpl $0x1, %eax
je 0x17a53
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x70(%r14)
movsd 0xbb28(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movl 0x1690(%r13), %eax
cmpl $0x3, %eax
je 0x17a89
movsd 0x1f41c(%rip), %xmm1    # 0x36ea0
movsd %xmm1, -0x40(%rbp)
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
cmpl $0x1, %eax
je 0x17aa1
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
divsd -0x38(%rbp), %xmm1
movsd %xmm1, 0x88(%r14)
movsd 0xbb30(%r14), %xmm0
movsd %xmm0, 0x17b8(%r14)
mulsd 0x1f41f(%rip), %xmm0    # 0x36ee8
divsd 0x1f407(%rip), %xmm0    # 0x36ed8
movsd %xmm0, -0x38(%rbp)
movsd 0x600(%r14), %xmm1
movsd %xmm1, -0x30(%rbp)
callq 0xb550
movsd %xmm0, -0x40(%rbp)
movsd 0x608(%r14), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0xa1d0
mulsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
mulsd -0x30(%rbp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, -0x40(%rbp)
movsd 0x600(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0xa1d0
movsd %xmm0, -0x48(%rbp)
movsd 0x608(%r14), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0xb550
mulsd -0x50(%rbp), %xmm0
movsd -0x48(%rbp), %xmm2
mulsd -0x30(%rbp), %xmm2
addsd %xmm0, %xmm2
movsd 0x17a0(%r14), %xmm0
movsd -0x40(%rbp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x600(%r14)
movsd 0x17a8(%r14), %xmm1
subsd %xmm1, %xmm2
movsd %xmm2, 0x608(%r14)
movsd 0x17b0(%r14), %xmm2
movsd 0x610(%r14), %xmm3
subsd %xmm2, %xmm3
movsd %xmm3, 0x610(%r14)
movsd 0x8(%r14), %xmm4
movsd 0x10(%r14), %xmm3
subsd %xmm3, %xmm4
movsd %xmm4, 0x8(%r14)
movsd 0x28(%r14), %xmm4
movsd 0x20(%r14), %xmm5
subsd %xmm4, %xmm5
movsd %xmm5, 0x20(%r14)
movsd 0x40(%r14), %xmm5
movsd 0x38(%r14), %xmm6
subsd %xmm5, %xmm6
movsd %xmm6, 0x38(%r14)
movsd 0x58(%r14), %xmm6
movsd 0x50(%r14), %xmm7
subsd %xmm6, %xmm7
movsd %xmm7, 0x50(%r14)
movsd 0x68(%r14), %xmm8
movsd 0x70(%r14), %xmm7
subsd %xmm7, %xmm8
movsd %xmm8, 0x68(%r14)
movsd 0x80(%r14), %xmm8
movsd 0x88(%r14), %xmm9
subsd %xmm9, %xmm8
movsd %xmm8, 0x80(%r14)
addsd 0x118(%r14), %xmm0
addsd 0x120(%r14), %xmm1
addsd 0x128(%r14), %xmm2
addsd (%r14), %xmm3
addsd 0x18(%r14), %xmm4
addsd 0x30(%r14), %xmm5
addsd 0x48(%r14), %xmm6
addsd 0x60(%r14), %xmm7
addsd 0x78(%r14), %xmm9
movsd %xmm9, (%rsp)
callq 0xa510
movsd 0x17b8(%r14), %xmm0
callq 0xae60
cmpl $0x1, 0xc67c(%r14)
je 0x17cbb
movl $0x1, %edi
callq 0xabc0
movl $0x1, 0xc67c(%r14)
xorl %eax, %eax
movl %eax, 0x668(%r14)
movl %eax, 0x670(%r14)
xorl %edi, %edi
callq 0xb1e0
movsd 0x148(%rbx), %xmm0
movsd %xmm0, 0x678(%r14)
xorps %xmm0, %xmm0
callq 0xab70
cmpb $0x0, 0x674(%r14)
jne 0x17d02
callq 0xa560
movb $0x1, 0x674(%r14)
cmpb $0x0, 0xc6c8(%r14)
jne 0x17d19
callq 0xb6c0
movb $0x1, 0xc6c8(%r14)
movl $0x0, 0x624(%r14)
movb $0x1, 0xc689(%r14)
callq 0xabb0
movl $0x1, 0xc6cc(%r14)
xorps %xmm0, %xmm0
callq 0xab80
movl $0xa, 0x1798(%r14)
cmpb $0x1, 0x1797(%r14)
jne 0x17d66
callq 0xa0f0
movb $0x0, 0x1797(%r14)
cmpb $0x1, 0x1688(%r14)
jne 0x17d7d
callq 0xa710
movb $0x0, 0x1688(%r14)
cmpl $0x1e, 0x1f0(%rbx)
jne 0x17d8b
callq 0xb590
callq 0xa7f0
movl $0x1, %r15d
cmpb $0x1, 0xc678(%r13)
jne 0x17f2d
cmpq $0x0, 0x1680(%r13)
je 0x17f2d
movq 0x1680(%r13), %rdx
leaq 0x1698(%r13), %rdi
movq %rdi, -0x38(%rbp)
movl $0xff, %esi
callq 0xb0f0
testq %rax, %rax
je 0x17eba
movl $0x1698, %eax           # imm = 0x1698
addq 0x2c17d(%rip), %rax     # 0x43f60
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0xa4a0
movq %rax, %r12
cmpl $0xfe, %r12d
jne 0x17e12
movq 0x1680(%r13), %rdi
callq 0xb0d0
cmpl $0xa, %eax
jne 0x17dfc
jmp 0x17e9c
movl %r12d, %r14d
movl %r12d, %ebx
sarl $0x1f, %ebx
andl %r12d, %ebx
leal -0x1(%rbx), %eax
movl %eax, -0x30(%rbp)
decq %r14
testl %r12d, %r12d
jle 0x17e4e
movl %r14d, %eax
movsbl 0x1698(%r13,%rax), %edi
callq 0xa0b0
decl %r12d
decq %r14
testl %eax, %eax
jne 0x17e27
leal 0x1(%r12), %ebx
jmp 0x17e54
movl -0x30(%rbp), %eax
movl %eax, %r12d
movslq %r12d, %rax
cmpb $0x25, 0x1698(%r13,%rax)
jne 0x17e9c
leal -0x2(%rbx), %r14d
cmpl $0x2, %ebx
jl 0x17e92
movl %r14d, %r14d
movsbl 0x1698(%r13,%r14), %edi
callq 0xa0b0
testl %eax, %eax
je 0x17e92
leaq -0x1(%r14), %rax
testq %r14, %r14
movq %rax, %r14
jg 0x17e6e
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $-0x1, %r14d
je 0x17f2d
movq 0x1680(%r13), %rdx
movq -0x38(%rbp), %rdi
movl $0xff, %esi
callq 0xb0f0
testq %rax, %rax
jne 0x17de7
leaq 0x21374(%rip), %rdi     # 0x39235
callq 0xb370
jmp 0x17f2d
callq 0xac80
xorl %r15d, %r15d
jmp 0x17f2d
leaq 0x2138f(%rip), %rdi     # 0x39268
callq 0xa1f0
movq %r12, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x2c06e(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0x1fb63(%rip), %rsi     # 0x37a6d
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r15d
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop