// File: /workspace/github_cpp_makefile_star2_O3/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_nurbs(int, block_struct*, setup_struct*)
int Interp::convert_nurbs(int mode,
      block_pointer block,     //!< pointer to a block of RS274 instructions
      setup_pointer settings)  //!< pointer to machine settings
{
    double end_z, AA_end, BB_end, CC_end, u_end, v_end, w_end;
    CONTROL_POINT CP;   

    if (mode == G_5_2)  {
	CHKS((((block->x_flag) && !(block->y_flag)) || (!(block->x_flag) && (block->y_flag))), (
             "You must specify both X and Y coordinates for Control Points"));
	CHKS((!(block->x_flag) && !(block->y_flag) && (block->p_number > 0) && 
             (!nurbs_control_points.empty())), (
             "Can specify P without X and Y only for the first control point"));

        CHKS(((block->p_number <= 0) && (!nurbs_control_points.empty())), (
             "Must specify positive weight P for every Control Point"));
        if (settings->feed_mode == UNITS_PER_MINUTE) {
            CHKS((settings->feed_rate == 0.0), (
                 "Cannot make a NURBS with 0 feedrate"));
        }
        if (nurbs_control_points.empty()) {
            CP.X = settings->current_x;
            CP.Y = settings->current_y;
            if (!(block->x_flag) && !(block->y_flag) && (block->p_number > 0)) {
                CP.W = block->p_number;
            } else {
                CP.W = 1;
            }
            nurbs_order = 3;
            nurbs_control_points.push_back(CP);
        } 
        if (block->l_number != -1 && block->l_number > 3) {
            nurbs_order = block->l_number;  
        } 
        if ((block->x_flag) && (block->y_flag)) {
            CHP(find_ends(block, settings, &CP.X, &CP.Y, &end_z, &AA_end, &BB_end, &CC_end,
                          &u_end, &v_end, &w_end));
            CP.W = block->p_number;
            nurbs_control_points.push_back(CP);
            }

//for (i=0;i<nurbs_control_points.size();i++){
//                printf( "X %8.4f, Y %8.4f, W %8.4f\n",
//              nurbs_control_points[i].X,
//               nurbs_control_points[i].Y,
//               nurbs_control_points[i].W);
//       }
//        printf("*-----------------------------------------*\n");
        settings->motion_mode = mode;
    }
    
    else if (mode == G_5_3){
        CHKS((settings->motion_mode != G_5_2), (
             "Cannot use G5.3 without G5.2 first"));
        CHKS((nurbs_control_points.size()<nurbs_order), _("You must specify a number of control points at least equal to the order L = %d"), nurbs_order);
	settings->current_x = nurbs_control_points[nurbs_control_points.size()-1].X;
        settings->current_y = nurbs_control_points[nurbs_control_points.size()-1].Y;
        NURBS_FEED(block->line_number, nurbs_control_points, nurbs_order);
	//printf("hello\n");
	nurbs_control_points.clear();
	//printf("%d\n", 	nurbs_control_points.size());
	settings->motion_mode = -1;
    }
    return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r14
movq %rdx, %r12
movq %rdi, %r15
xorl %ebx, %ebx
cmpl $0x35, %esi
je 0xcb5f
cmpl $0x34, %esi
jne 0xcdd7
movb 0x270(%r12), %al
movb 0x280(%r12), %cl
cmpb $0x1, %al
jne 0xcbc2
testb %cl, %cl
je 0xcbc6
jmp 0xcc0e
cmpl $0x34, 0x1798(%r14)
jne 0xcbd2
movq 0x537e0(%rip), %rax     # 0x60350
movq 0x537d1(%rip), %rcx     # 0x60348
subq %rcx, %rax
movq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rsi
movl 0x537cb(%rip), %edx     # 0x60360
cmpq %rdx, %rsi
jae 0xccef
leaq 0x2812b(%rip), %rdi     # 0x34cd0
callq 0xa1f0
movl 0x537b0(%rip), %edx     # 0x60360
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
jmp 0xcda0
testb %cl, %cl
je 0xcbde
leaq 0x28009(%rip), %rsi     # 0x34bd6
jmp 0xcd96
leaq 0x280d4(%rip), %rsi     # 0x34cad
jmp 0xcd96
movsd 0x210(%r12), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xcc0e
movq 0x5374f(%rip), %rdx     # 0x60348
cmpq 0x53750(%rip), %rdx     # 0x60350
je 0xcc0e
leaq 0x2800a(%rip), %rsi     # 0x34c13
jmp 0xcd96
movsd 0x210(%r12), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jb 0xcc3e
movq 0x5371f(%rip), %rdx     # 0x60348
cmpq 0x53720(%rip), %rdx     # 0x60350
je 0xcc3e
leaq 0x28019(%rip), %rsi     # 0x34c52
jmp 0xcd96
cmpl $0x0, 0x670(%r14)
je 0xcd72
movq 0x536f5(%rip), %rdx     # 0x60348
movq 0x536f6(%rip), %rsi     # 0x60350
cmpq %rsi, %rdx
jne 0xcdf8
movsd 0x600(%r14), %xmm1
movsd %xmm1, -0x40(%rbp)
movsd 0x608(%r14), %xmm1
movsd %xmm1, -0x38(%rbp)
movsd 0x27219(%rip), %xmm1    # 0x33ea0
movapd %xmm1, %xmm2
testb $0x1, %cl
jne 0xcc94
movapd %xmm0, %xmm2
testb %al, %al
jne 0xccb5
xorpd %xmm3, %xmm3
cmpnltsd %xmm0, %xmm3
movapd %xmm3, %xmm0
andnpd %xmm2, %xmm0
andpd %xmm1, %xmm3
orpd %xmm0, %xmm3
movapd %xmm3, %xmm1
movsd %xmm1, -0x30(%rbp)
movl $0x3, 0x5369c(%rip)     # 0x60360
cmpq 0x5368d(%rip), %rdx     # 0x60358
je 0xcde8
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rsi)
movupd -0x40(%rbp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x53666(%rip)    # 0x60350
jmp 0xcdf8
movsd -0x18(%rcx,%rax), %xmm0
movsd %xmm0, 0x600(%r14)
movsd -0x10(%rcx,%rax), %xmm0
movsd %xmm0, 0x608(%r14)
movl 0x1d0(%r12), %r15d
leaq 0x5362c(%rip), %rsi     # 0x60348
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0xa5e0
movl 0x53632(%rip), %edx     # 0x60360
movl %r15d, %edi
movq %r12, %rsi
callq 0xa430
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0xcd4e
movq -0x48(%rbp), %rsi
subq %rdi, %rsi
callq 0xaae0
movq 0x535f3(%rip), %rax     # 0x60348
cmpq %rax, 0x535f4(%rip)     # 0x60350
je 0xcd65
movq %rax, 0x535eb(%rip)     # 0x60350
movl $0xffffffff, 0x1798(%r14) # imm = 0xFFFFFFFF
jmp 0xcdd7
movsd 0x678(%r14), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0xcc4c
jp 0xcc4c
leaq 0x27ef3(%rip), %rsi     # 0x34c89
movq %r15, %rdi
xorl %eax, %eax
callq 0xa850
movq 0x341b9(%rip), %rbx     # 0x40f60
leaq 0xc6d0(%rbx), %rdi
leaq 0x2738b(%rip), %rsi     # 0x34140
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %ebx
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x53559(%rip), %rdi     # 0x60348
leaq -0x40(%rbp), %rdx
callq 0xb410
movl 0x1c8(%r12), %eax
cmpl $0x4, %eax
jl 0xce0b
movl %eax, 0x53555(%rip)     # 0x60360
cmpb $0x1, 0x270(%r12)
jne 0xcf26
cmpb $0x1, 0x280(%r12)
jne 0xcf26
leaq -0x38(%rbp), %r8
leaq -0x60(%rbp), %rax
leaq -0x68(%rbp), %r10
leaq -0x70(%rbp), %r11
leaq -0x78(%rbp), %r13
leaq -0x40(%rbp), %rcx
leaq -0x90(%rbp), %r9
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
pushq %rax
pushq %r10
pushq %r11
pushq %r13
leaq -0x80(%rbp), %rax
pushq %rax
leaq -0x88(%rbp), %rax
pushq %rax
callq 0xaa70
addq $0x30, %rsp
testl %eax, %eax
je 0xcedc
movl %eax, %r15d
movq 0x340e4(%rip), %rbx     # 0x40f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0xced4
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x2729d(%rip), %rsi     # 0x34140
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)
movl %r15d, %ebx
jmp 0xcdd7
movsd 0x210(%r12), %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x5345e(%rip), %rsi     # 0x60350
cmpq 0x5345f(%rip), %rsi     # 0x60358
je 0xcf16
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rsi)
movupd -0x40(%rbp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x5343c(%rip)    # 0x60350
jmp 0xcf26
leaq 0x5342b(%rip), %rdi     # 0x60348
leaq -0x40(%rbp), %rdx
callq 0xb410
movl $0x34, 0x1798(%r14)
jmp 0xcdd7
movq %rax, %rbx
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0xcf4e
movq -0x48(%rbp), %rsi
subq %rdi, %rsi
callq 0xaae0
movq %rbx, %rdi
callq 0xb3b0