// File: /workspace/github_cpp_makefile_star2_O1/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 0xd7ef
leaq 0x2a66f(%rip), %rdi     # 0x37e5c
jmp 0xd841
movq %rcx, %r15
movq %rdx, %r12
movl %esi, %r13d
movb 0x198(%rdx), %al
movb $0x1, %cl
testb %al, %al
jne 0xd817
cmpb $0x0, 0x1a8(%r12)
jne 0xd817
movb 0x1b8(%r12), %cl
movb 0x229(%r12), %dl
movl %edx, %esi
orb %cl, %sil
testb $0x1, %sil
je 0xd83a
andb %cl, %dl
cmpb $0x1, %dl
jne 0xd8aa
leaq 0x2a698(%rip), %rdi     # 0x37ed0
jmp 0xd841
leaq 0x2a66d(%rip), %rdi     # 0x37eae
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x36706(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0x29970(%rip), %rsi     # 0x371e2
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r14d
movl %r14d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb 0xc689(%r15), %sil
movl 0x670(%r15), %edx
cmpl $0x2, %edx
je 0xd8ff
cmpl $0x1, %edx
je 0xd8dd
testl %edx, %edx
jne 0xd940
movsd 0x678(%r15), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xd940
jnp 0xd914
jmp 0xd940
movsd 0x148(%r12), %xmm0
ucomisd 0x28f81(%rip), %xmm0    # 0x36870
jne 0xd940
jp 0xd940
leaq 0x2a47f(%rip), %rdi     # 0x37d79
jmp 0xd841
movsd 0x678(%r15), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0xd920
jp 0xd920
leaq 0x2a43a(%rip), %rdi     # 0x37d55
jmp 0xd841
movsd 0xc6b8(%r15), %xmm1
ucomisd %xmm0, %xmm1
jne 0xd940
jp 0xd940
leaq 0x2a5b8(%rip), %rsi     # 0x37ef0
movq %rbx, %rdi
jmp 0xd84c
movl 0xc67c(%r15), %edx
testb %cl, %cl
je 0xd981
cmpl $0x3, %edx
je 0xda1a
cmpl $0x2, %edx
je 0xd9e0
cmpl $0x1, %edx
jne 0xdc52
cmpb $0x1, 0x1b8(%r12)
jne 0xda9a
leaq 0x2a5ad(%rip), %rdi     # 0x37f29
jmp 0xd841
cmpl $0x3, %edx
je 0xda31
cmpl $0x2, %edx
je 0xd9f0
cmpl $0x1, %edx
jne 0xdae7
cmpb $0x0, 0x270(%r12)
jne 0xdae7
cmpb $0x0, 0x280(%r12)
jne 0xdae7
cmpl $0x0, 0x2a0(%r12)
jne 0xdae7
cmpl $0x0, 0x2b0(%r12)
jne 0xdae7
leaq 0x2a5f2(%rip), %rdi     # 0x37fcd
jmp 0xd841
testb %al, %al
je 0xda5b
leaq 0x2a586(%rip), %rdi     # 0x37f71
jmp 0xd841
cmpb $0x0, 0x280(%r12)
jne 0xdae7
cmpb $0x0, 0x290(%r12)
jne 0xdae7
leaq 0x2a5e2(%rip), %rdi     # 0x37ff7
jmp 0xd841
cmpb $0x1, 0x1a8(%r12)
jne 0xda68
leaq 0x2a566(%rip), %rdi     # 0x37f92
jmp 0xd841
cmpb $0x0, 0x270(%r12)
jne 0xdae7
cmpb $0x0, 0x290(%r12)
jne 0xdae7
leaq 0x2a5cb(%rip), %rdi     # 0x38021
jmp 0xd841
cmpb $0x0, 0x1a8(%r12)
jne 0xda6c
jmp 0xdaa9
testb %al, %al
je 0xdacc
cmpb $0x0, 0x1b8(%r12)
jne 0xdae7
movl $0x1c0, %eax            # imm = 0x1C0
cmpl $0x0, 0x66c(%r15)
jne 0xdadf
leaq 0x2a4bd(%rip), %rsi     # 0x37f4a
movq %rbx, %rdi
movl $0x4b, %edx
jmp 0xddfa
testb %al, %al
je 0xdacc
cmpb $0x0, 0x1a8(%r12)
jne 0xdae7
movl $0x1b0, %eax            # imm = 0x1B0
cmpl $0x0, 0x66c(%r15)
jne 0xdadf
leaq 0x2a48b(%rip), %rsi     # 0x37f4a
movq %rbx, %rdi
movl $0x4a, %edx
jmp 0xddfa
movl $0x1a0, %eax            # imm = 0x1A0
cmpl $0x0, 0x66c(%r15)
je 0xddeb
movq $0x0, (%r12,%rax)
movb %sil, -0x29(%rbp)
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 %r15, %rdx
callq 0xaa70
movl %eax, %r14d
testl %eax, %eax
je 0xdba9
movq 0x36418(%rip), %rbx     # 0x43f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0xd895
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x2966f(%rip), %rsi     # 0x371e2
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 0xd895
movl %r13d, 0x1798(%r15)
movl 0xc67c(%r15), %eax
cmpl $0x3, %eax
je 0xdcc8
cmpl $0x2, %eax
je 0xdc5e
cmpl $0x1, %eax
jne 0xdc52
cmpl $0x0, 0x624(%r15)
je 0xdbf9
movsd 0x618(%r15), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xde2b
jp 0xde2b
leaq 0x600(%r15), %r8
leaq 0x608(%r15), %r9
leaq 0x610(%r15), %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 0xdcb5
leaq 0x2a35a(%rip), %rdi     # 0x37fb3
jmp 0xd841
leaq 0x608(%r15), %r8
leaq 0x610(%r15), %r9
leaq 0x600(%r15), %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 0xdd54
cmpl $0x0, 0x624(%r15)
je 0xdcef
movsd 0x618(%r15), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xde06
jp 0xde06
leaq 0x610(%r15), %r8
leaq 0x600(%r15), %r9
leaq 0x608(%r15), %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 %r15, %rcx
callq 0xac10
movl %eax, %ebx
testl %eax, %eax
je 0xdddb
movq 0x361e3(%rip), %r14     # 0x43f60
movslq 0xd670(%r14), %rax
cmpq $0x30, %rax
jg 0xddd8
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%r14,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x2943e(%rip), %rsi     # 0x371e2
movl $0x50, %edx
callq 0xa8a0
movslq 0xd670(%r14), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%r14,%rcx)
incl %eax
movl %eax, 0xd670(%r14)
movb %dl, 0xc720(%r14,%rcx)
movl %ebx, %r14d
testl %ebx, %ebx
jne 0xd895
xorl %r14d, %r14d
jmp 0xd895
leaq 0x2a158(%rip), %rsi     # 0x37f4a
movq %rbx, %rdi
movl $0x49, %edx
xorl %eax, %eax
callq 0xa850
jmp 0xd853
movsd -0x68(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
movsd -0x70(%rbp), %xmm2
movsd 0x1a0(%r12), %xmm4
movsd 0x1c0(%r12), %xmm3
jmp 0xde4e
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
cmpb $0x0, -0x29(%rbp)
je 0xde9f
movsd %xmm10, 0x10(%rsp)
movsd %xmm9, 0x8(%rsp)
movsd %xmm8, (%rsp)
movq %rbx, %rdi
movl %r13d, %esi
movq %r12, %rdx
movq %r15, %rcx
callq 0xb450
jmp 0xdd70
movsd %xmm10, 0x10(%rsp)
movsd %xmm9, 0x8(%rsp)
movsd %xmm8, (%rsp)
movq %rbx, %rdi
movl %r13d, %esi
movq %r12, %rdx
movq %r15, %rcx
callq 0xa5a0
jmp 0xdd70
nop