// File: /workspace/github_cpp_makefile_star2_O2/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 0xe485
leaq 0x229d9(%rip), %rdi     # 0x30e5c
jmp 0xe4d4
movq %rcx, %r14
movq %rdx, %r15
movl %esi, %r12d
movb 0x198(%rdx), %al
movb $0x1, %cl
testb %al, %al
jne 0xe4ab
cmpb $0x0, 0x1a8(%r15)
jne 0xe4ab
movb 0x1b8(%r15), %cl
movb 0x229(%r15), %dl
movl %edx, %esi
orb %cl, %sil
testb $0x1, %sil
je 0xe4cd
andb %cl, %dl
cmpb $0x1, %dl
jne 0xe537
leaq 0x22a05(%rip), %rdi     # 0x30ed0
jmp 0xe4d4
leaq 0x229da(%rip), %rdi     # 0x30eae
callq 0xb220
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x2ea73(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x21ce7(%rip), %rsi     # 0x301e2
pushq $0x50
popq %rdx
callq 0xb940
movb $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
addq $0xc720, %rbx           # imm = 0xC720
pushq $0x5
popq %r13
movb $0x0, (%rbx)
movl %r13d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb 0xc689(%r14), %sil
movl 0x670(%r14), %edx
cmpl $0x2, %edx
je 0xe58b
cmpl $0x1, %edx
je 0xe56a
testl %edx, %edx
jne 0xe5cc
movsd 0x678(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xe5cc
jnp 0xe5a0
jmp 0xe5cc
movsd 0x148(%r15), %xmm0
ucomisd 0x212f5(%rip), %xmm0    # 0x2f870
jne 0xe5cc
jp 0xe5cc
leaq 0x227f3(%rip), %rdi     # 0x30d79
jmp 0xe4d4
movsd 0x678(%r14), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0xe5ac
jp 0xe5ac
leaq 0x227ae(%rip), %rdi     # 0x30d55
jmp 0xe4d4
movsd 0xc6b8(%r14), %xmm1
ucomisd %xmm0, %xmm1
jne 0xe5cc
jp 0xe5cc
leaq 0x2292c(%rip), %rsi     # 0x30ef0
movq %rbx, %rdi
jmp 0xe4df
movl 0xc67c(%r14), %edx
testb %cl, %cl
je 0xe60c
cmpl $0x3, %edx
je 0xe6a3
cmpl $0x2, %edx
je 0xe66b
cmpl $0x1, %edx
jne 0xe864
cmpb $0x1, 0x1b8(%r15)
jne 0xe720
leaq 0x22922(%rip), %rdi     # 0x30f29
jmp 0xe4d4
cmpl $0x3, %edx
movb %sil, -0x29(%rbp)
je 0xe6b9
cmpl $0x2, %edx
je 0xe67b
cmpl $0x1, %edx
jne 0xe767
cmpb $0x0, 0x270(%r15)
jne 0xe767
cmpb $0x0, 0x280(%r15)
jne 0xe767
cmpl $0x0, 0x2a0(%r15)
jne 0xe767
cmpl $0x0, 0x2b0(%r15)
jne 0xe767
leaq 0x22967(%rip), %rdi     # 0x30fcd
jmp 0xe4d4
testb %al, %al
je 0xe6e1
leaq 0x228fb(%rip), %rdi     # 0x30f71
jmp 0xe4d4
cmpb $0x0, 0x280(%r15)
jne 0xe767
cmpb $0x0, 0x290(%r15)
jne 0xe767
leaq 0x22959(%rip), %rdi     # 0x30ff7
jmp 0xe4d4
cmpb $0x1, 0x1a8(%r15)
jne 0xe6f1
leaq 0x228de(%rip), %rdi     # 0x30f92
jmp 0xe4d4
cmpb $0x0, 0x270(%r15)
jne 0xe767
cmpb $0x0, 0x290(%r15)
jne 0xe767
leaq 0x22945(%rip), %rdi     # 0x31021
jmp 0xe4d4
movb %sil, -0x29(%rbp)
cmpb $0x0, 0x1a8(%r15)
jne 0xe6f9
jmp 0xe732
movb %sil, -0x29(%rbp)
testb %al, %al
je 0xe74f
cmpb $0x0, 0x1b8(%r15)
jne 0xe767
movl $0x1c0, %eax            # imm = 0x1C0
cmpl $0x0, 0x66c(%r14)
jne 0xe762
leaq 0x22831(%rip), %rsi     # 0x30f4a
pushq $0x4b
jmp 0xe9f7
movb %sil, -0x29(%rbp)
testb %al, %al
je 0xe74f
cmpb $0x0, 0x1a8(%r15)
jne 0xe767
movl $0x1b0, %eax            # imm = 0x1B0
cmpl $0x0, 0x66c(%r14)
jne 0xe762
leaq 0x22802(%rip), %rsi     # 0x30f4a
pushq $0x4a
jmp 0xe9f7
movl $0x1a0, %eax            # imm = 0x1A0
cmpl $0x0, 0x66c(%r14)
je 0xe9ee
andq $0x0, (%r15,%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 %r15, %rsi
movq %r14, %rdx
callq 0xbb30
testl %eax, %eax
jne 0xe985
movl %r12d, 0x1798(%r14)
movl 0xc67c(%r14), %eax
cmpl $0x3, %eax
je 0xe8d8
cmpl $0x2, %eax
movb -0x29(%rbp), %cl
je 0xe870
cmpl $0x1, %eax
jne 0xe864
cmpl $0x0, 0x624(%r14)
je 0xe80d
movsd 0x618(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xea77
jp 0xea77
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(%r15), %xmm9
movsd 0x1b0(%r15), %xmm10
jmp 0xe8c5
leaq 0x22748(%rip), %rdi     # 0x30fb3
jmp 0xe4d4
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(%r15), %xmm9
movsd 0x1c0(%r15), %xmm10
movsd %xmm10, 0x18(%rsp)
movsd %xmm9, 0x10(%rsp)
jmp 0xe965
cmpl $0x0, 0x624(%r14)
movb -0x29(%rbp), %al
je 0xe902
movsd 0x618(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xea07
jp 0xea07
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(%r15), %xmm9
movsd 0x1c0(%r15), %xmm10
movsd %xmm9, 0x18(%rsp)
movsd %xmm10, 0x10(%rsp)
movsd %xmm8, 0x8(%rsp)
movq %rax, (%rsp)
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0xbd00
testl %eax, %eax
je 0xe9e6
movl %eax, %r13d
movq 0x2e5d1(%rip), %r14     # 0x3cf60
movslq 0xd670(%r14), %rax
cmpq $0x30, %rax
jg 0xe522
imulq $0x50, %rax, %rax
leaq (%r14,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x2182c(%rip), %rsi     # 0x301e2
pushq $0x50
popq %rdx
callq 0xb940
movslq 0xd670(%r14), %rax
imulq $0x50, %rax, %rcx
leaq (%r14,%rcx), %rbx
addq $0xc720, %rbx           # imm = 0xC720
movb $0x0, -0x1(%rbx)
incl %eax
movl %eax, 0xd670(%r14)
jmp 0xe51f
xorl %r13d, %r13d
jmp 0xe522
leaq 0x22555(%rip), %rsi     # 0x30f4a
pushq $0x49
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xb8e0
jmp 0xe4e6
movsd -0x68(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
movsd -0x70(%rbp), %xmm2
movsd 0x1a0(%r15), %xmm4
movsd 0x1c0(%r15), %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 0xeabd
movsd %xmm10, 0x10(%rsp)
movsd %xmm9, 0x8(%rsp)
movsd %xmm8, (%rsp)
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0xc5c0
jmp 0xe981
movsd -0x78(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
movsd -0x68(%rbp), %xmm2
movsd 0x1a0(%r15), %xmm3
movsd 0x1b0(%r15), %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 0xea4d
movsd %xmm10, 0x10(%rsp)
movsd %xmm9, 0x8(%rsp)
movsd %xmm8, (%rsp)
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0xb5e0
jmp 0xe981
nop