// File: /workspace/github_cpp_makefile_star2_O2/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_spline(int, block_struct*, setup_struct*)
int Interp::convert_spline(int mode,
       block_pointer block,     //!< pointer to a block of RS274 instructions
       setup_pointer settings)  //!< pointer to machine settings
{
    double x1, y1, x2, y2, x3, y3;
    double end_z, AA_end, BB_end, CC_end, u_end, v_end, w_end;
    CONTROL_POINT cp;

    CHKS((settings->cutter_comp_side != OFF), _("Cannot convert spline with cutter radius compensation")); // XXX

    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 == INVERSE_TIME) {
      CHKS((block->f_number == -1.0),
        NCE_F_WORD_MISSING_WITH_INVERSE_TIME_ARC_MOVE);
    }

    CHKS((settings->plane != CANON_PLANE_XY), _("Splines must be in the XY plane")); // XXX
       //Error (for now): Splines must be in XY plane

    CHKS((block->z_flag == ON || block->a_flag == ON || block->b_flag == ON
          || block->c_flag == ON),
          ("Splines may not have motion in Z, A, B, or C"));

    if(mode == G_5_1) {
      CHKS(block->i_flag != ON || block->j_flag != ON,
                  ("Must specify both I and J with G5.1"));
      x1 = settings->current_x + block->i_number;
      y1 = settings->current_y + block->j_number;
      CHP(find_ends(block, settings, &x2, &y2, &end_z, &AA_end, &BB_end, &CC_end,
                    &u_end, &v_end, &w_end));
      cp.W = 1;
      cp.X = settings->current_x, cp.Y = settings->current_y;
      nurbs_control_points.push_back(cp);
      cp.X = x1, cp.Y = y1;
      nurbs_control_points.push_back(cp);
      cp.X = x2, cp.Y = y2;
      nurbs_control_points.push_back(cp);
      NURBS_FEED(block->line_number, nurbs_control_points, 3);
      nurbs_control_points.clear();
      settings->current_x = x2;
      settings->current_y = y2;
    } else {
      if(block->i_flag != ON || block->j_flag != ON) {
          CHKS(block->i_flag == ON || block->j_flag == ON,
                  ("Must specify both I and J, or neither"));
          x1 = settings->current_x + settings->cycle_i;
          y1 = settings->current_y + settings->cycle_j;
      } else {
          x1 = settings->current_x + block->i_number;
          y1 = settings->current_y + block->j_number;
      }
      CHP(find_ends(block, settings, &x3, &y3, &end_z, &AA_end, &BB_end, &CC_end,
                    &u_end, &v_end, &w_end));

      CHKS(block->p_flag != ON || block->q_flag != ON,
	      ("Must specify both P and Q with G5"));
      x2 = x3 + block->p_number;
      y2 = y3 + block->q_number;

      cp.W = 1;
      cp.X = settings->current_x, cp.Y = settings->current_y;
      nurbs_control_points.push_back(cp);
      cp.X = x1, cp.Y = y1;
      nurbs_control_points.push_back(cp);
      cp.X = x2, cp.Y = y2;
      nurbs_control_points.push_back(cp);
      cp.X = x3, cp.Y = y3;
      nurbs_control_points.push_back(cp);
      NURBS_FEED(block->line_number, nurbs_control_points, 4);
      nurbs_control_points.clear();

      settings->cycle_i = -block->p_number;
      settings->cycle_j = -block->q_number;
      settings->current_x = x3;
      settings->current_y = y3;
    }
    return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %r15
cmpl $0x0, 0x624(%rcx)
je 0xdf47
leaq 0x22e32(%rip), %rdi     # 0x30d1f
callq 0xb220
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x2f05a(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x2227d(%rip), %rsi     # 0x30191
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %r12
movl %r12d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %rbx
movq %rdx, %r14
movl 0x670(%rcx), %eax
cmpl $0x1, %eax
je 0xdf7c
testl %eax, %eax
jne 0xdf9d
movsd 0x678(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xdf9d
jp 0xdf9d
leaq 0x22dde(%rip), %rdi     # 0x30d55
jmp 0xdeed
movsd 0x148(%r14), %xmm0
ucomisd 0x218e3(%rip), %xmm0    # 0x2f870
jne 0xdf9d
jp 0xdf9d
leaq 0x22de1(%rip), %rdi     # 0x30d79
jmp 0xdeed
cmpl $0x1, 0xc67c(%rbx)
jne 0xdfd3
cmpb $0x0, 0x290(%r14)
jne 0xdfc4
cmpb $0x0, (%r14)
jne 0xdfc4
cmpb $0x0, 0x10(%r14)
jne 0xdfc4
cmpb $0x1, 0x20(%r14)
jne 0xdfdf
leaq 0x22df8(%rip), %rsi     # 0x30dc3
movq %r15, %rdi
jmp 0xdef8
leaq 0x22dc9(%rip), %rdi     # 0x30da3
jmp 0xdeed
movb 0x198(%r14), %al
cmpl $0x33, %esi
jne 0xe190
testb %al, %al
je 0xe1be
cmpb $0x0, 0x1a8(%r14)
je 0xe1be
movsd 0x600(%rbx), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x608(%rbx), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0x1a0(%r14), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x1b0(%r14), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0x70(%rbp), %rax
leaq -0x78(%rbp), %r10
leaq -0x80(%rbp), %r11
leaq -0x88(%rbp), %r12
leaq -0x90(%rbp), %r13
leaq -0x68(%rbp), %rcx
leaq -0x60(%rbp), %r8
leaq -0xa0(%rbp), %r9
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
pushq %rax
pushq %r10
pushq %r11
pushq %r12
pushq %r13
leaq -0x98(%rbp), %rax
pushq %rax
callq 0xbb30
addq $0x30, %rsp
testl %eax, %eax
jne 0xe257
movsd -0x30(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
leaq -0xe8(%rbp), %r15
movq %rax, 0x10(%r15)
movsd 0x600(%rbx), %xmm0
movsd %xmm0, (%r15)
movsd 0x608(%rbx), %xmm0
movsd %xmm0, 0x8(%r15)
leaq 0x4e324(%rip), %r12     # 0x5c408
movq %r12, %rdi
movq %r15, %rsi
callq 0xb070
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x8(%r15)
movq %r12, %rdi
movq %r15, %rsi
callq 0xb070
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, 0x8(%r15)
movq %r12, %rdi
movq %r15, %rsi
callq 0xb070
movl 0x1d0(%r14), %r14d
leaq -0xd0(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0xb620
pushq $0x3
popq %rdx
movl %r14d, %edi
movq %r15, %rsi
callq 0xb470
leaq -0xd0(%rbp), %rdi
callq 0xb180
movq 0x4e29f(%rip), %rax     # 0x5c408
cmpq %rax, 0x4e2a0(%rip)     # 0x5c410
je 0xe179
movq %rax, 0x4e297(%rip)     # 0x5c410
movsd -0x68(%rbp), %xmm0
movsd %xmm0, 0x600(%rbx)
movsd -0x60(%rbp), %xmm0
jmp 0xe42a
movb 0x1a8(%r14), %cl
testb %al, %al
je 0xe1ca
testb %cl, %cl
je 0xe1ce
movsd 0x600(%rbx), %xmm0
addsd 0x1a0(%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x1b0(%r14), %rax
jmp 0xe1f6
leaq 0x22c2b(%rip), %rsi     # 0x30df0
jmp 0xdfcb
testb %cl, %cl
je 0xe1da
leaq 0x22c3f(%rip), %rsi     # 0x30e14
jmp 0xdfcb
movsd 0x600(%rbx), %xmm0
addsd 0x630(%rbx), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x638(%rbx), %rax
movsd 0x608(%rbx), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x70(%rbp), %rax
leaq -0x78(%rbp), %r10
leaq -0x80(%rbp), %r11
leaq -0x88(%rbp), %r12
leaq -0x90(%rbp), %r13
leaq -0x58(%rbp), %rcx
leaq -0x50(%rbp), %r8
leaq -0xa0(%rbp), %r9
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
pushq %rax
pushq %r10
pushq %r11
pushq %r12
pushq %r13
leaq -0x98(%rbp), %rax
pushq %rax
callq 0xbb30
addq $0x30, %rsp
testl %eax, %eax
je 0xe2b8
movl %eax, %r12d
movq 0x2ecff(%rip), %rbx     # 0x3cf60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0xdf32
imulq $0x50, %rax, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x21f09(%rip), %rsi     # 0x30191
pushq $0x50
popq %rdx
callq 0xb940
movslq 0xd670(%rbx), %rax
imulq $0x50, %rax, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%rbx,%rcx)
incl %eax
movl %eax, 0xd670(%rbx)
movb %dl, 0xc720(%rbx,%rcx)
jmp 0xdf32
cmpb $0x0, 0x218(%r14)
je 0xe43a
cmpb $0x0, 0x228(%r14)
je 0xe43a
movsd -0x58(%rbp), %xmm0
addsd 0x210(%r14), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x50(%rbp), %xmm0
addsd 0x220(%r14), %xmm0
movsd %xmm0, -0x40(%rbp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
leaq -0xe8(%rbp), %r15
movq %rax, 0x10(%r15)
movsd 0x600(%rbx), %xmm0
movsd %xmm0, (%r15)
movsd 0x608(%rbx), %xmm0
movsd %xmm0, 0x8(%r15)
leaq 0x4e0d7(%rip), %r12     # 0x5c408
movq %r12, %rdi
movq %r15, %rsi
callq 0xb070
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x8(%r15)
movq %r12, %rdi
movq %r15, %rsi
callq 0xb070
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, 0x8(%r15)
movq %r12, %rdi
movq %r15, %rsi
callq 0xb070
movsd -0x58(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, 0x8(%r15)
movq %r12, %rdi
movq %r15, %rsi
callq 0xb070
movl 0x1d0(%r14), %r13d
leaq -0xb8(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0xb620
pushq $0x4
popq %rdx
movl %r13d, %edi
movq %r15, %rsi
callq 0xb470
leaq -0xb8(%rbp), %rdi
callq 0xb180
movq 0x4e032(%rip), %rax     # 0x5c408
cmpq %rax, 0x4e033(%rip)     # 0x5c410
je 0xe3e6
movq %rax, 0x4e02a(%rip)     # 0x5c410
movsd 0x210(%r14), %xmm0
movapd 0x21b19(%rip), %xmm1    # 0x2ff10
xorpd %xmm1, %xmm0
movlpd %xmm0, 0x630(%rbx)
movsd 0x220(%r14), %xmm0
xorpd %xmm1, %xmm0
movlpd %xmm0, 0x638(%rbx)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, 0x600(%rbx)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, 0x608(%rbx)
xorl %r12d, %r12d
jmp 0xdf32
leaq 0x229f9(%rip), %rsi     # 0x30e3a
jmp 0xdfcb
jmp 0xe448
movq %rax, %rbx
movq %r15, %rdi
callq 0xb180
movq %rbx, %rdi
callq 0xc520
nop