// File: /workspace/github_cpp_makefile_star2_O3/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_arc(int, block_struct*, setup_struct*)
int Interp::convert_arc(int move,        //!< either G_2 (cw arc) or G_3 (ccw arc)    
                       block_pointer block,     //!< pointer to a block of RS274 instructions
                       setup_pointer settings)  //!< pointer to machine settings             
{
  int status;
  int first;                    /* flag set ON if this is first move after comp ON */
  int ijk_flag;                 /* flag set ON if any of i,j,k present in NC code  */
  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;

  CHKS((settings->arc_not_allowed), (_("The move just after exiting cutter compensation mode must be straight, not an arc")));

  ijk_flag = ((block->i_flag || block->j_flag) || block->k_flag) ? ON : OFF;
  first = settings->cutter_comp_firstmove == ON;

  CHKS(((block->r_flag != ON) && (ijk_flag != ON)),
      NCE_R_I_J_K_WORDS_ALL_MISSING_FOR_ARC);
  CHKS(((block->r_flag == ON) && (ijk_flag == ON)),
      NCE_MIXED_RADIUS_IJK_FORMAT_FOR_ARC);
  if (settings->feed_mode == UNITS_PER_MINUTE) {
    CHKS((settings->feed_rate == 0.0),
        NCE_CANNOT_MAKE_ARC_WITH_ZERO_FEED_RATE);
  } else if(settings->feed_mode == UNITS_PER_REVOLUTION) {
    CHKS((settings->feed_rate == 0.0),
        NCE_CANNOT_MAKE_ARC_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_ARC_MOVE);
  }

  if (ijk_flag) {
    if (settings->plane == CANON_PLANE_XY) {
      CHKS((block->k_flag), NCE_K_WORD_GIVEN_FOR_ARC_IN_XY_PLANE);
      if (block->i_flag == OFF) { /* i or j flag on to get here */
	if (settings->ijk_distance_mode == MODE_ABSOLUTE) {
	  ERS("%c word missing in absolute center arc", 'I');
	} else {
	  block->i_number = 0.0;
	}
      } else if (block->j_flag == OFF) {
	if (settings->ijk_distance_mode == MODE_ABSOLUTE) {
	  ERS("%c word missing in absolute center arc", 'J');
	} else {
	  block->j_number = 0.0;
	}
      }
    } else if (settings->plane == CANON_PLANE_YZ) {
      CHKS((block->i_flag), NCE_I_WORD_GIVEN_FOR_ARC_IN_YZ_PLANE);
      if (block->j_flag == OFF) { /* j or k flag on to get here */
	if (settings->ijk_distance_mode == MODE_ABSOLUTE) {
	  ERS("%c word missing in absolute center arc", 'J');
	} else {
	  block->j_number = 0.0;
	}
      } else if (block->k_flag == OFF) {
	if (settings->ijk_distance_mode == MODE_ABSOLUTE) {
	  ERS("%c word missing in absolute center arc", 'K');
	} else {
	  block->k_number = 0.0;
	}
      }
    } else if (settings->plane == CANON_PLANE_XZ) {
      CHKS((block->j_flag), NCE_J_WORD_GIVEN_FOR_ARC_IN_XZ_PLANE);
      if (block->i_flag == OFF) { /* i or k flag on to get here */
	if (settings->ijk_distance_mode == MODE_ABSOLUTE) {
	  ERS("%c word missing in absolute center arc", 'I');
	} else {
	  block->i_number = 0.0;
	}
      } else if (block->k_flag == OFF) {
	if (settings->ijk_distance_mode == MODE_ABSOLUTE) {
	  ERS("%c word missing in absolute center arc", 'K');
	} else {
	  block->k_number = 0.0;
	}
      }
    } else {
      ERS(NCE_BUG_PLANE_NOT_XY_YZ_OR_XZ);
    }
  } else {
    // in R format, we need some XYZ words specified because a full circle is not allowed.
    if (settings->plane == CANON_PLANE_XY) { 
        CHKS(((block->x_flag == OFF) && (block->y_flag == OFF) && (block->radius_flag == OFF) && (block->theta_flag == OFF)),
            NCE_X_AND_Y_WORDS_MISSING_FOR_ARC_IN_XY_PLANE);
    } else if (settings->plane == CANON_PLANE_YZ) {
        CHKS(((block->y_flag == OFF) && (block->z_flag == OFF)),
            NCE_Y_AND_Z_WORDS_MISSING_FOR_ARC_IN_YZ_PLANE);
    } else if (settings->plane == CANON_PLANE_XZ) {
        CHKS(((block->x_flag == OFF) && (block->z_flag == OFF)),
            NCE_X_AND_Z_WORDS_MISSING_FOR_ARC_IN_XZ_PLANE);
    }
  }


  CHP(find_ends(block, settings, &end_x, &end_y, &end_z,
                &AA_end, &BB_end, &CC_end, 
                &u_end, &v_end, &w_end));

  settings->motion_mode = move;


  if (settings->plane == CANON_PLANE_XY) {
    if ((settings->cutter_comp_side == OFF) ||
        (settings->cutter_comp_radius == 0.0)) {
      status =
        convert_arc2(move, block, settings,
                     &(settings->current_x), &(settings->current_y),
                     &(settings->current_z), end_x, end_y, end_z,
                     AA_end, BB_end, CC_end,
                     u_end, v_end, w_end,
                     block->i_number, block->j_number);
      CHP(status);
    } else if (first) {
      status = convert_arc_comp1(move, block, settings, end_x, end_y, end_z,
                                 block->i_number, block->j_number,
                                 AA_end, BB_end, CC_end,
                                 u_end, v_end, w_end);
      CHP(status);
    } else {
      status = convert_arc_comp2(move, block, settings, end_x, end_y, end_z,
                                 block->i_number, block->j_number,
                                 AA_end, BB_end, CC_end,
                                 u_end, v_end, w_end);
      CHP(status);
    }
  } else if (settings->plane == CANON_PLANE_XZ) {
    if ((settings->cutter_comp_side == OFF) ||
        (settings->cutter_comp_radius == 0.0)) {
      status =
        convert_arc2(move, block, settings,
                     &(settings->current_z), &(settings->current_x),
                     &(settings->current_y), end_z, end_x, end_y,
                     AA_end, BB_end, CC_end,
                     u_end, v_end, w_end,
                     block->k_number, block->i_number);
      CHP(status);
    } else if (first) {
      status = convert_arc_comp1(move, block, settings, end_z, end_x, end_y,
                                 block->k_number, block->i_number,
                                 AA_end, BB_end, CC_end,
                                 u_end, v_end, w_end);
      CHP(status);
    } else {
      status = convert_arc_comp2(move, block, settings, end_z, end_x, end_y,
                                 block->k_number, block->i_number,
                                 AA_end, BB_end, CC_end,
                                 u_end, v_end, w_end);

      CHP(status);
    }
  } else if (settings->plane == CANON_PLANE_YZ) {
    status =
      convert_arc2(move, block, settings,
                   &(settings->current_y), &(settings->current_z),
                   &(settings->current_x), end_y, end_z, end_x,
                   AA_end, BB_end, CC_end,
                   u_end, v_end, w_end,
                   block->j_number, block->k_number);
    CHP(status);
  } else
    ERS(NCE_BUG_PLANE_NOT_XY_YZ_OR_XZ);
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
cmpb $0x1, 0x110(%rcx)
jne 0xd6c2
leaq 0x2779f(%rip), %rdi     # 0x34e5c
jmp 0xda8a
movq %rcx, %r14
movq %rdx, %r12
movl %esi, %r13d
movb 0x198(%rdx), %al
testb %al, %al
jne 0xd6e0
cmpb $0x1, 0x1a8(%r12)
jne 0xd73b
movb 0x229(%r12), %dl
movb $0x1, %cl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xd6fd
leaq 0x277d8(%rip), %rdi     # 0x34ed0
jmp 0xda8a
movb 0xc689(%r14), %sil
movl 0x670(%r14), %edx
cmpl $0x2, %edx
je 0xd784
cmpl $0x1, %edx
je 0xd762
testl %edx, %edx
jne 0xd7c5
movsd 0x678(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xd7c5
jnp 0xd799
jmp 0xd7c5
movb 0x1b8(%r12), %cl
movb 0x229(%r12), %dl
movl %ecx, %esi
orb %dl, %sil
testb $0x1, %sil
jne 0xd6ea
leaq 0x27751(%rip), %rdi     # 0x34eae
jmp 0xda8a
movsd 0x148(%r12), %xmm0
ucomisd 0x260fc(%rip), %xmm0    # 0x33870
jne 0xd7c5
jp 0xd7c5
leaq 0x275fa(%rip), %rdi     # 0x34d79
jmp 0xda8a
movsd 0x678(%r14), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0xd7a5
jp 0xd7a5
leaq 0x275b5(%rip), %rdi     # 0x34d55
jmp 0xda8a
movsd 0xc6b8(%r14), %xmm1
ucomisd %xmm0, %xmm1
jne 0xd7c5
jp 0xd7c5
leaq 0x27733(%rip), %rsi     # 0x34ef0
movq %rbx, %rdi
jmp 0xda95
movl 0xc67c(%r14), %edx
testb $0x1, %cl
je 0xd807
cmpl $0x3, %edx
je 0xd8a4
cmpl $0x2, %edx
je 0xd86a
cmpl $0x1, %edx
jne 0xda83
cmpb $0x1, 0x1b8(%r12)
jne 0xd92c
leaq 0x27727(%rip), %rdi     # 0x34f29
jmp 0xda8a
cmpl $0x3, %edx
movb %sil, -0x29(%rbp)
je 0xd8bb
cmpl $0x2, %edx
je 0xd87a
cmpl $0x1, %edx
jne 0xd97d
cmpb $0x0, 0x270(%r12)
jne 0xd97d
cmpb $0x0, 0x280(%r12)
jne 0xd97d
cmpl $0x0, 0x2a0(%r12)
jne 0xd97d
cmpl $0x0, 0x2b0(%r12)
jne 0xd97d
leaq 0x27768(%rip), %rdi     # 0x34fcd
jmp 0xda8a
testb %al, %al
je 0xd8e5
leaq 0x276fc(%rip), %rdi     # 0x34f71
jmp 0xda8a
cmpb $0x0, 0x280(%r12)
jne 0xd97d
cmpb $0x0, 0x290(%r12)
jne 0xd97d
leaq 0x27758(%rip), %rdi     # 0x34ff7
jmp 0xda8a
cmpb $0x1, 0x1a8(%r12)
jne 0xd8f6
leaq 0x276dc(%rip), %rdi     # 0x34f92
jmp 0xda8a
cmpb $0x0, 0x270(%r12)
jne 0xd97d
cmpb $0x0, 0x290(%r12)
jne 0xd97d
leaq 0x27741(%rip), %rdi     # 0x35021
jmp 0xda8a
movb %sil, -0x29(%rbp)
cmpb $0x0, 0x1a8(%r12)
jne 0xd8fe
jmp 0xd93f
movb %sil, -0x29(%rbp)
testb %al, %al
je 0xd962
cmpb $0x0, 0x1b8(%r12)
jne 0xd97d
movl $0x1c0, %eax            # imm = 0x1C0
cmpl $0x0, 0x66c(%r14)
jne 0xd975
leaq 0x2762b(%rip), %rsi     # 0x34f4a
movq %rbx, %rdi
movl $0x4b, %edx
jmp 0xdc8c
movb %sil, -0x29(%rbp)
testb %al, %al
je 0xd962
cmpb $0x0, 0x1a8(%r12)
jne 0xd97d
movl $0x1b0, %eax            # imm = 0x1B0
cmpl $0x0, 0x66c(%r14)
jne 0xd975
leaq 0x275f5(%rip), %rsi     # 0x34f4a
movq %rbx, %rdi
movl $0x4a, %edx
jmp 0xdc8c
movl $0x1a0, %eax            # imm = 0x1A0
cmpl $0x0, 0x66c(%r14)
je 0xdc7d
movq $0x0, (%r12,%rax)
leaq -0x38(%rbp), %rax
movq %rax, 0x28(%rsp)
leaq -0x40(%rbp), %rax
movq %rax, 0x20(%rsp)
leaq -0x48(%rbp), %rax
movq %rax, 0x18(%rsp)
leaq -0x50(%rbp), %rax
movq %rax, 0x10(%rsp)
leaq -0x58(%rbp), %rax
movq %rax, 0x8(%rsp)
leaq -0x60(%rbp), %rax
movq %rax, (%rsp)
leaq -0x78(%rbp), %rcx
leaq -0x70(%rbp), %r8
leaq -0x68(%rbp), %r9
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0xaa70
testl %eax, %eax
jne 0xdc0a
movl %r13d, 0x1798(%r14)
movl 0xc67c(%r14), %eax
cmpl $0x3, %eax
je 0xdb5b
cmpl $0x2, %eax
movb -0x29(%rbp), %cl
je 0xdaf1
cmpl $0x1, %eax
jne 0xda83
cmpl $0x0, 0x624(%r14)
je 0xda27
movsd 0x618(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xdd0a
jp 0xdd0a
leaq 0x600(%r14), %r8
leaq 0x608(%r14), %r9
leaq 0x610(%r14), %rax
movsd -0x78(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
movsd -0x68(%rbp), %xmm2
movsd -0x60(%rbp), %xmm3
movsd -0x58(%rbp), %xmm4
movsd -0x50(%rbp), %xmm5
movsd -0x48(%rbp), %xmm6
movsd -0x40(%rbp), %xmm7
movsd -0x38(%rbp), %xmm8
movsd 0x1a0(%r12), %xmm9
movsd 0x1b0(%r12), %xmm10
jmp 0xdb48
leaq 0x27529(%rip), %rdi     # 0x34fb3
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x334bd(%rip), %rbx     # 0x40f60
leaq 0xc6d0(%rbx), %rdi
leaq 0x26731(%rip), %rsi     # 0x341e2
movl $0x50, %edx
callq 0xa8a0
movb $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
addq $0xc720, %rbx           # imm = 0xC720
movl $0x5, %r15d
movb $0x0, (%rbx)
movl %r15d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x608(%r14), %r8
leaq 0x610(%r14), %r9
leaq 0x600(%r14), %rax
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
movsd -0x78(%rbp), %xmm2
movsd -0x60(%rbp), %xmm3
movsd -0x58(%rbp), %xmm4
movsd -0x50(%rbp), %xmm5
movsd -0x48(%rbp), %xmm6
movsd -0x40(%rbp), %xmm7
movsd -0x38(%rbp), %xmm8
movsd 0x1b0(%r12), %xmm9
movsd 0x1c0(%r12), %xmm10
movsd %xmm10, 0x18(%rsp)
movsd %xmm9, 0x10(%rsp)
jmp 0xdbea
cmpl $0x0, 0x624(%r14)
movb -0x29(%rbp), %al
je 0xdb85
movsd 0x618(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xdc98
jp 0xdc98
leaq 0x610(%r14), %r8
leaq 0x600(%r14), %r9
leaq 0x608(%r14), %rax
movsd -0x68(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
movsd -0x70(%rbp), %xmm2
movsd -0x60(%rbp), %xmm3
movsd -0x58(%rbp), %xmm4
movsd -0x50(%rbp), %xmm5
movsd -0x48(%rbp), %xmm6
movsd -0x40(%rbp), %xmm7
movsd -0x38(%rbp), %xmm8
movsd 0x1a0(%r12), %xmm9
movsd 0x1c0(%r12), %xmm10
movsd %xmm9, 0x18(%rsp)
movsd %xmm10, 0x10(%rsp)
movsd %xmm8, 0x8(%rsp)
movq %rax, (%rsp)
movq %rbx, %rdi
movl %r13d, %esi
movq %r12, %rdx
movq %r14, %rcx
callq 0xac10
testl %eax, %eax
je 0xdc75
movl %eax, %r15d
movq 0x3334c(%rip), %r14     # 0x40f60
movslq 0xd670(%r14), %rax
cmpq $0x30, %rax
jg 0xdadc
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%r14,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x265a3(%rip), %rsi     # 0x341e2
movl $0x50, %edx
callq 0xa8a0
movslq 0xd670(%r14), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
leaq (%r14,%rcx), %rbx
addq $0xc720, %rbx           # imm = 0xC720
movb $0x0, -0x1(%rbx)
incl %eax
movl %eax, 0xd670(%r14)
jmp 0xdad9
xorl %r15d, %r15d
jmp 0xdadc
leaq 0x272c6(%rip), %rsi     # 0x34f4a
movq %rbx, %rdi
movl $0x49, %edx
xorl %eax, %eax
callq 0xa850
jmp 0xda9c
movsd -0x68(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
movsd -0x70(%rbp), %xmm2
movsd 0x1a0(%r12), %xmm4
movsd 0x1c0(%r12), %xmm3
movsd -0x60(%rbp), %xmm5
movsd -0x58(%rbp), %xmm6
movsd -0x50(%rbp), %xmm7
movsd -0x48(%rbp), %xmm8
movsd -0x40(%rbp), %xmm9
movsd -0x38(%rbp), %xmm10
testb %al, %al
je 0xdd52
movsd %xmm10, 0x10(%rsp)
movsd %xmm9, 0x8(%rsp)
movsd %xmm8, (%rsp)
movq %rbx, %rdi
movl %r13d, %esi
movq %r12, %rdx
movq %r14, %rcx
callq 0xb450
jmp 0xdc06
movsd -0x78(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
movsd -0x68(%rbp), %xmm2
movsd 0x1a0(%r12), %xmm3
movsd 0x1b0(%r12), %xmm4
movsd -0x60(%rbp), %xmm5
movsd -0x58(%rbp), %xmm6
movsd -0x50(%rbp), %xmm7
movsd -0x48(%rbp), %xmm8
movsd -0x40(%rbp), %xmm9
movsd -0x38(%rbp), %xmm10
testb %cl, %cl
jne 0xdce0
movsd %xmm10, 0x10(%rsp)
movsd %xmm9, 0x8(%rsp)
movsd %xmm8, (%rsp)
movq %rbx, %rdi
movl %r13d, %esi
movq %r12, %rdx
movq %r14, %rcx
callq 0xa5a0
jmp 0xdc06