// File: /workspace/github_cpp_makefile_star2_O1/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 0xccc4
cmpl $0x34, %esi
jne 0xcee7
movb 0x270(%r12), %al
cmpb $0x1, %al
jne 0xccad
cmpb $0x1, 0x280(%r12)
jne 0xccb8
testb %al, %al
jne 0xcd72
cmpb $0x1, 0x280(%r12)
jne 0xcd33
leaq 0x2af17(%rip), %rsi     # 0x37bd6
jmp 0xce9c
cmpl $0x34, 0x1798(%r14)
jne 0xcd27
movq 0x5667b(%rip), %rax     # 0x63350
movq 0x5666c(%rip), %rcx     # 0x63348
subq %rcx, %rax
movq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rsi
movl 0x56666(%rip), %edx     # 0x63360
cmpq %rdx, %rsi
jae 0xcdf5
leaq 0x2afc6(%rip), %rdi     # 0x37cd0
callq 0xa1f0
movl 0x5664b(%rip), %edx     # 0x63360
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
jmp 0xcea6
leaq 0x2af7f(%rip), %rsi     # 0x37cad
jmp 0xce9c
testb %al, %al
jne 0xcd72
cmpb $0x0, 0x280(%r12)
jne 0xcd72
movsd 0x210(%r12), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xcd72
movq 0x565eb(%rip), %rcx     # 0x63348
cmpq 0x565ec(%rip), %rcx     # 0x63350
je 0xcd72
leaq 0x2aea6(%rip), %rsi     # 0x37c13
jmp 0xce9c
movsd 0x210(%r12), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jb 0xcda2
movq 0x565bb(%rip), %rcx     # 0x63348
cmpq 0x565bc(%rip), %rcx     # 0x63350
je 0xcda2
leaq 0x2aeb5(%rip), %rsi     # 0x37c52
jmp 0xce9c
cmpl $0x0, 0x670(%r14)
je 0xce78
movq 0x56599(%rip), %rsi     # 0x63350
cmpq %rsi, 0x5658a(%rip)     # 0x63348
jne 0xcf58
movsd 0x600(%r14), %xmm1
movsd %xmm1, -0x40(%rbp)
movsd 0x608(%r14), %xmm1
movsd %xmm1, -0x38(%rbp)
testb %al, %al
je 0xcef8
movsd 0x2a0b0(%rip), %xmm0    # 0x36ea0
jmp 0xcf15
movsd -0x18(%rcx,%rax), %xmm0
movsd %xmm0, 0x600(%r14)
movsd -0x10(%rcx,%rax), %xmm0
movsd %xmm0, 0x608(%r14)
movl 0x1d0(%r12), %r15d
leaq 0x56526(%rip), %rsi     # 0x63348
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0xa5e0
movl 0x5652c(%rip), %edx     # 0x63360
movl %r15d, %edi
movq %r12, %rsi
callq 0xa430
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0xce54
movq -0x48(%rbp), %rsi
subq %rdi, %rsi
callq 0xaae0
movq 0x564ed(%rip), %rax     # 0x63348
cmpq %rax, 0x564ee(%rip)     # 0x63350
je 0xce6b
movq %rax, 0x564e5(%rip)     # 0x63350
movl $0xffffffff, 0x1798(%r14) # imm = 0xFFFFFFFF
jmp 0xcee7
movsd 0x678(%r14), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0xcdb0
jp 0xcdb0
leaq 0x2aded(%rip), %rsi     # 0x37c89
movq %r15, %rdi
xorl %eax, %eax
callq 0xa850
movq 0x370b3(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0x2a27b(%rip), %rsi     # 0x37140
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
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xcde8
cmpb $0x0, 0x280(%r12)
jne 0xcde8
movsd %xmm0, -0x30(%rbp)
movl $0x3, 0x5643c(%rip)     # 0x63360
cmpq 0x5642d(%rip), %rsi     # 0x63358
je 0xcf48
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rsi)
movupd -0x40(%rbp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x5640a(%rip)    # 0x63350
jmp 0xcf58
leaq 0x563f9(%rip), %rdi     # 0x63348
leaq -0x40(%rbp), %rdx
callq 0xb410
movl 0x1c8(%r12), %eax
cmpl $0x4, %eax
jl 0xcf6b
movl %eax, 0x563f5(%rip)     # 0x63360
cmpb $0x1, 0x270(%r12)
jne 0xd086
cmpb $0x1, 0x280(%r12)
jne 0xd086
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 0xd03c
movl %eax, %r15d
movq 0x36f84(%rip), %rbx     # 0x43f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0xd034
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x2a13d(%rip), %rsi     # 0x37140
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 0xcee7
movsd 0x210(%r12), %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x562fe(%rip), %rsi     # 0x63350
cmpq 0x562ff(%rip), %rsi     # 0x63358
je 0xd076
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rsi)
movupd -0x40(%rbp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x562dc(%rip)    # 0x63350
jmp 0xd086
leaq 0x562cb(%rip), %rdi     # 0x63348
leaq -0x40(%rbp), %rdx
callq 0xb410
movl $0x34, 0x1798(%r14)
jmp 0xcee7
movq %rax, %rbx
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0xd0ae
movq -0x48(%rbp), %rsi
subq %rdi, %rsi
callq 0xaae0
movq %rbx, %rdi
callq 0xb3b0