// File: /workspace/github_cpp_makefile_star2_O3/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_straight(int, block_struct*, setup_struct*)
int Interp::convert_straight(int move,   //!< either G_0 or G_1                       
                            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, v_end, w_end;
  int status;

  settings->arc_not_allowed = OFF;

  if (move == G_1) {
    if (settings->feed_mode == UNITS_PER_MINUTE) {
      CHKS((settings->feed_rate == 0.0), NCE_CANNOT_DO_G1_WITH_ZERO_FEED_RATE);
    } else if (settings->feed_mode == UNITS_PER_REVOLUTION) {
      CHKS((settings->feed_rate == 0.0), NCE_CANNOT_DO_G1_WITH_ZERO_FEED_RATE);
      CHKS((settings->speed == 0.0), "Cannot feed with zero spindle speed in feed per rev mode");
    } else if (settings->feed_mode == INVERSE_TIME) {
      CHKS((block->f_number == -1.0),
          NCE_F_WORD_MISSING_WITH_INVERSE_TIME_G1_MOVE);
    }
  }

  settings->motion_mode = move;
  CHP(find_ends(block, settings, &end_x, &end_y, &end_z,
                &AA_end, &BB_end, &CC_end, &u_end, &v_end, &w_end));

  if (move == G_1) {
      inverse_time_rate_straight(end_x, end_y, end_z,
                                 AA_end, BB_end, CC_end,
                                 u_end, v_end, w_end,
                                 block, settings);
  }

  if ((settings->cutter_comp_side != OFF) &&    /* ! "== ON" */
      (settings->cutter_comp_radius > 0.0)) {   /* radius always is >= 0 */

    CHKS((block->g_modes[0] == G_53),
        NCE_CANNOT_USE_G53_WITH_CUTTER_RADIUS_COMP);

    if(settings->plane == CANON_PLANE_XZ) {
        if (settings->cutter_comp_firstmove == ON)
            status = convert_straight_comp1(move, block, settings, end_z, end_x, end_y,
                                            AA_end, BB_end, CC_end, u_end, v_end, w_end);
        else
            status = convert_straight_comp2(move, block, settings, end_z, end_x, end_y,
                                            AA_end, BB_end, CC_end, u_end, v_end, w_end);
    } else if(settings->plane == CANON_PLANE_XY) {
        if (settings->cutter_comp_firstmove == ON)
            status = convert_straight_comp1(move, block, settings, end_x, end_y, end_z,
                                            AA_end, BB_end, CC_end, u_end, v_end, w_end);
        else
            status = convert_straight_comp2(move, block, settings, end_x, end_y, end_z,
                                            AA_end, BB_end, CC_end, u_end, v_end, w_end);
    } else ERS("BUG: Invalid plane for cutter compensation");
    CHP(status);
  } else if (move == G_0) {
    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;
  } else if (move == G_1) {
    STRAIGHT_FEED(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;
  } else if (move == G_33) {
    CHKS(((settings->spindle_turning != CANON_CLOCKWISE) &&
           (settings->spindle_turning != CANON_COUNTERCLOCKWISE)),
          "Spindle not turning in G33");
    START_SPEED_FEED_SYNCH(block->k_number, 0);
    STRAIGHT_FEED(block->line_number, end_x, end_y, end_z, AA_end, BB_end, CC_end, u_end, v_end, w_end);
    STOP_SPEED_FEED_SYNCH();
    settings->current_x = end_x;
    settings->current_y = end_y;
    settings->current_z = end_z;
  } else if (move == G_33_1) {
    CHKS(((settings->spindle_turning != CANON_CLOCKWISE) &&
           (settings->spindle_turning != CANON_COUNTERCLOCKWISE)),
          "Spindle not turning in G33.1");
    START_SPEED_FEED_SYNCH(block->k_number, 0);
    RIGID_TAP(block->line_number, end_x, end_y, end_z);
    STOP_SPEED_FEED_SYNCH();
    // after the RIGID_TAP cycle we'll be in the same spot
  } else if (move == G_76) {
    CHKS((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), NCE_CANNOT_MOVE_ROTARY_AXES_WITH_G76);
    int result = convert_threading_cycle(block, settings, end_x, end_y, end_z);
    if(result != INTERP_OK) return result;
  } else
    ERS(NCE_BUG_CODE_NOT_G0_OR_G1);

  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 $0x78, %rsp
movq %rcx, %rbx
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, %r14
movb $0x0, 0x110(%rcx)
cmpl $0xa, %esi
jne 0x16104
movl 0x670(%rbx), %eax
cmpl $0x2, %eax
je 0x16188
cmpl $0x1, %eax
je 0x16167
testl %eax, %eax
jne 0x161c4
movsd 0x678(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x161c4
jnp 0x1619c
jmp 0x161c4
movl %r12d, 0x1798(%rbx)
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 -0x40(%rbp), %rcx
leaq -0x38(%rbp), %r8
leaq -0x30(%rbp), %r9
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xaa70
testl %eax, %eax
jne 0x16221
jmp 0x162ce
movsd 0x148(%r15), %xmm0
ucomisd 0x1d6f8(%rip), %xmm0    # 0x33870
jne 0x161c4
jp 0x161c4
leaq 0x20124(%rip), %rdi     # 0x362a7
jmp 0x16576
movsd 0x678(%rbx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x161a8
jp 0x161a8
leaq 0x200e3(%rip), %rdi     # 0x36286
jmp 0x16576
movsd 0xc6b8(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x161c4
jp 0x161c4
leaq 0x1ed31(%rip), %rsi     # 0x34ef0
jmp 0x16662
movl $0xa, 0x1798(%rbx)
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 -0x40(%rbp), %rcx
leaq -0x38(%rbp), %r8
leaq -0x30(%rbp), %r9
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xaa70
testl %eax, %eax
je 0x1628c
movl %eax, %r13d
movq 0x2ad35(%rip), %rbx     # 0x40f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x165c0
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x1e775(%rip), %rsi     # 0x349cb
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 0x165c0
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%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)
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xa870
cmpl $0x0, 0x624(%rbx)
je 0x16306
movsd 0x618(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16306
cmpl $0x212, 0x150(%r15) # imm = 0x212
jne 0x16498
leaq 0x1ffcf(%rip), %rdi     # 0x362d0
jmp 0x16576
testl %r12d, %r12d
je 0x16357
cmpl $0xa, %r12d
jne 0x16405
movl 0x1d0(%r15), %edi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%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 0xa6d0
jmp 0x16397
movl 0x1d0(%r15), %edi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%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
movsd -0x40(%rbp), %xmm0
movsd %xmm0, 0x600(%rbx)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x608(%rbx)
movsd -0x30(%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
jmp 0x165c0
cmpl $0x2f8, %r12d           # imm = 0x2F8
je 0x1650b
cmpl $0x14b, %r12d           # imm = 0x14B
je 0x164c4
cmpl $0x14a, %r12d           # imm = 0x14A
jne 0x1656f
movl 0xc6cc(%rbx), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x1665b
movsd 0x1c0(%r15), %xmm0
xorl %edi, %edi
callq 0xaef0
movl 0x1d0(%r15), %edi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%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 0xa6d0
callq 0xa5f0
jmp 0x16397
movl 0xc67c(%rbx), %eax
cmpl $0x1, %eax
je 0x165d2
cmpl $0x3, %eax
jne 0x16649
movsd -0x30(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
jmp 0x165e1
movl 0xc6cc(%rbx), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x16652
movsd 0x1c0(%r15), %xmm0
xorl %edi, %edi
callq 0xaef0
movl 0x1d0(%r15), %edi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
callq 0xaaf0
callq 0xa5f0
jmp 0x163be
movsd 0x8(%rbx), %xmm0
ucomisd -0x70(%rbp), %xmm0
jne 0x16566
jp 0x16566
movsd 0x20(%rbx), %xmm0
ucomisd -0x68(%rbp), %xmm0
jne 0x16566
jp 0x16566
movsd 0x38(%rbx), %xmm0
ucomisd -0x60(%rbp), %xmm0
jne 0x16566
jp 0x16566
movsd 0x50(%rbx), %xmm0
ucomisd -0x58(%rbp), %xmm0
jne 0x16566
jp 0x16566
movsd 0x68(%rbx), %xmm0
ucomisd -0x50(%rbp), %xmm0
jne 0x16566
jp 0x16566
movsd 0x80(%rbx), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x16566
jnp 0x1666a
leaq 0x1fded(%rip), %rdi     # 0x3635a
jmp 0x16576
leaq 0x1fe05(%rip), %rdi     # 0x3637b
callq 0xa1f0
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x2a9d1(%rip), %rbx     # 0x40f60
leaq 0xc6d0(%rbx), %rdi
leaq 0x1e42e(%rip), %rsi     # 0x349cb
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r13d
movl %r13d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%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
cmpb $0x1, 0xc689(%rbx)
jne 0x16622
movsd %xmm8, (%rsp)
movq %r14, %rdi
movl %r12d, %esi
movq %r15, %rdx
movq %rbx, %rcx
callq 0xa7c0
jmp 0x16639
movsd %xmm8, (%rsp)
movq %r14, %rdi
movl %r12d, %esi
movq %r15, %rdx
movq %rbx, %rcx
callq 0xa5b0
movl %eax, %r13d
testl %eax, %eax
jne 0x16224
jmp 0x163be
leaq 0x1fca7(%rip), %rsi     # 0x362f7
jmp 0x16662
leaq 0x1fce4(%rip), %rsi     # 0x3633d
jmp 0x16662
leaq 0x1fcc0(%rip), %rsi     # 0x36322
movq %r14, %rdi
jmp 0x16581
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xb1f0
movl %eax, %r13d
testl %eax, %eax
jne 0x165c0
jmp 0x163be
nop