// File: /workspace/github_cpp_makefile_star2_O3/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 0x16ac7
movl %eax, %r15d
movq 0x2a4fa(%rip), %rbx     # 0x40f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x1738d
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x1dfdc(%rip), %rsi     # 0x34a6d
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 0x1738d
movq %r14, %rdi
callq 0xa300
movl 0x1f0(%rbx), %eax
cmpl $0x1, %eax
jle 0x16af7
cmpl $0x2, %eax
je 0x16b12
cmpl $0x1e, %eax
je 0x16b12
cmpl $0x3c, %eax
jne 0x1733c
callq 0xb590
jmp 0x17332
testl %eax, %eax
je 0x17332
cmpl $0x1, %eax
jne 0x1733c
callq 0xa980
jmp 0x17337
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 0x1d2ea(%rip), %xmm0    # 0x33ed8
divsd 0x1d2ea(%rip), %xmm0    # 0x33ee0
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 0x2a296(%rip), %r13     # 0x40f60
movl 0x1690(%r13), %eax
movsd 0x1d1e7(%rip), %xmm1    # 0x33ec0
movsd %xmm1, -0x40(%rbp)
cmpl $0x3, %eax
je 0x16ceb
movsd 0x1d1b5(%rip), %xmm1    # 0x33ea0
movsd -0x38(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1d1cc(%rip), %xmm0    # 0x33ec8
movsd %xmm0, -0x38(%rbp)
cmpl $0x1, %eax
je 0x16d0a
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 0x1d187(%rip), %xmm1    # 0x33ec0
cmpl $0x3, %eax
je 0x16d46
movsd 0x1d15a(%rip), %xmm1    # 0x33ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1d171(%rip), %xmm0    # 0x33ec8
cmpl $0x1, %eax
je 0x16d60
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 0x1d131(%rip), %xmm1    # 0x33ec0
cmpl $0x3, %eax
je 0x16d9c
movsd 0x1d104(%rip), %xmm1    # 0x33ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1d11b(%rip), %xmm0    # 0x33ec8
cmpl $0x1, %eax
je 0x16db6
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 0x1d075(%rip), %xmm1    # 0x33ec0
cmpl $0x3, %eax
je 0x16e58
movsd 0x1d048(%rip), %xmm1    # 0x33ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1d05f(%rip), %xmm0    # 0x33ec8
cmpl $0x1, %eax
je 0x16e72
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 0x1d022(%rip), %xmm1    # 0x33ec0
cmpl $0x3, %eax
je 0x16eab
movsd 0x1cff5(%rip), %xmm1    # 0x33ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1d00c(%rip), %xmm0    # 0x33ec8
cmpl $0x1, %eax
je 0x16ec5
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 0x16efb
movsd 0x1cfaa(%rip), %xmm1    # 0x33ea0
movsd %xmm1, -0x40(%rbp)
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
cmpl $0x1, %eax
je 0x16f13
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 0x1cfb5(%rip), %xmm0    # 0x33ef0
divsd 0x1cf9d(%rip), %xmm0    # 0x33ee0
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 0x1712d
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 0x17174
callq 0xa560
movb $0x1, 0x674(%r14)
cmpb $0x0, 0xc6c8(%r14)
jne 0x1718b
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 0x171d8
callq 0xa0f0
movb $0x0, 0x1797(%r14)
cmpb $0x1, 0x1688(%r14)
jne 0x171ef
callq 0xa710
movb $0x0, 0x1688(%r14)
cmpl $0x1e, 0x1f0(%rbx)
jne 0x171fd
callq 0xb590
callq 0xa7f0
movq 0x1680(%r13), %rdx
testq %rdx, %rdx
setne %al
andb 0xc678(%r13), %al
movl $0x1, %r15d
cmpb $0x1, %al
jne 0x1738d
movl $0x1698, %edi           # imm = 0x1698
addq 0x29d30(%rip), %rdi     # 0x40f60
movq %rdi, -0x38(%rbp)
movl $0xff, %esi
callq 0xb0f0
testq %rax, %rax
je 0x17324
leaq 0x1698(%r13), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0xa4a0
movq %rax, %r12
cmpl $0xfe, %r12d
jne 0x1727d
movq 0x1680(%r13), %rdi
callq 0xb0d0
cmpl $0xa, %eax
jne 0x17267
jmp 0x17306
movl %r12d, %ebx
movl %r12d, %r14d
sarl $0x1f, %r14d
andl %r12d, %r14d
leal -0x1(%r14), %eax
movl %eax, -0x30(%rbp)
decq %rbx
testl %r12d, %r12d
jle 0x172ba
movl %ebx, %eax
movsbl 0x1698(%r13,%rax), %edi
callq 0xa0b0
decl %r12d
decq %rbx
testl %eax, %eax
jne 0x17294
leal 0x1(%r12), %r14d
jmp 0x172c0
movl -0x30(%rbp), %eax
movl %eax, %r12d
movslq %r12d, %rax
cmpb $0x25, 0x1698(%r13,%rax)
jne 0x17306
leal -0x2(%r14), %eax
cmpl $0x2, %r14d
jl 0x172fd
movl %eax, %ebx
movsbl 0x1698(%r13,%rbx), %edi
callq 0xa0b0
testl %eax, %eax
je 0x17306
leaq -0x1(%rbx), %rax
testq %rbx, %rbx
movq %rax, %rbx
jg 0x172da
jmp 0x1738d
cmpl $-0x1, %eax
je 0x1738d
movq 0x1680(%r13), %rdx
movq -0x40(%rbp), %rdi
movl $0xff, %esi
callq 0xb0f0
testq %rax, %rax
jne 0x17252
leaq 0x1ef0a(%rip), %rdi     # 0x36235
callq 0xb370
jmp 0x1738d
callq 0xac80
xorl %r15d, %r15d
jmp 0x1738d
leaq 0x1ef25(%rip), %rdi     # 0x36268
callq 0xa1f0
movq %r12, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x29c04(%rip), %rbx     # 0x40f60
leaq 0xc6d0(%rbx), %rdi
leaq 0x1d703(%rip), %rsi     # 0x34a6d
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