// File: /workspace/github_cpp_makefile_star2_O1/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_straight_comp1(int, block_struct*, setup_struct*, double, double, double, double, double, double, double, double, double)
int Interp::convert_straight_comp1(int move,     //!< either G_0 or G_1                        
                                   block_pointer block,  //!< pointer to a block of RS274 instructions 
                                   setup_pointer settings,       //!< pointer to machine settings              
                                   double px,    //!< X coordinate of end point                
                                   double py,    //!< Y coordinate of end point                
                                   double pz,    //!< Z coordinate of end point                
                                   double AA_end,        //!< A coordinate of end point          
                                   double BB_end,        //!< B coordinate of end point          
                                   double CC_end,        //!< C coordinate of end point          
                                   double u_end, double v_end, double w_end)
{
    double alpha;
    double distance;
    double radius = settings->cutter_comp_radius; /* always will be positive */
    double end_x, end_y;

    int side = settings->cutter_comp_side;
    double cx, cy, cz;

    comp_get_current(settings, &cx, &cy, &cz);
    distance = hypot((px - cx), (py - cy));

    CHKS(((side != LEFT) && (side != RIGHT)), NCE_BUG_SIDE_NOT_RIGHT_OR_LEFT);
    CHKS((distance <= radius), "Length of cutter compensation entry move is not greater than the tool radius");

    alpha = atan2(py - cy, px - cx) + (side == LEFT ? M_PIl/2. : -M_PIl/2.);

    end_x = (px + (radius * cos(alpha)));
    end_y = (py + (radius * sin(alpha)));

    // with these moves we don't need to record the direction vector.
    // they cannot get reversed because they are guaranteed to be long
    // enough.

    set_endpoint(cx, cy);

    if (move == G_0) {
        enqueue_STRAIGHT_TRAVERSE(settings, block->line_number, 
                                  cos(alpha), sin(alpha), 0, 
                                  end_x, end_y, pz,
                                  AA_end, BB_end, CC_end, u_end, v_end, w_end);
    }
    else if (move == G_1) {
        enqueue_STRAIGHT_FEED(settings, block->line_number, 
                              cos(alpha), sin(alpha), 0,
                              end_x, end_y, pz,
                              AA_end, BB_end, CC_end, u_end, v_end, w_end);
    } else
        ERS(NCE_BUG_CODE_NOT_G0_OR_G1);

    settings->cutter_comp_firstmove = OFF;

    comp_set_current(settings, end_x, end_y, pz);
    settings->AA_current = AA_end;
    settings->BB_current = BB_end;
    settings->CC_current = CC_end;
    settings->u_current = u_end;
    settings->v_current = v_end;
    settings->w_current = w_end;
    comp_set_programmed(settings, px, py, pz);
    return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movsd %xmm7, -0x78(%rbp)
movsd %xmm6, -0x70(%rbp)
movsd %xmm5, -0x68(%rbp)
movsd %xmm4, -0x60(%rbp)
movsd %xmm3, -0x58(%rbp)
movsd %xmm2, -0x50(%rbp)
movsd %xmm1, -0x88(%rbp)
movsd %xmm0, -0x80(%rbp)
movq %rcx, %r14
movq %rdx, -0x90(%rbp)
movl %esi, -0x48(%rbp)
movq %rdi, %rbx
movsd 0x618(%rcx), %xmm0
movsd %xmm0, -0x38(%rbp)
movl 0x624(%rcx), %r12d
leaq -0xc8(%rbp), %r13
leaq -0xc0(%rbp), %r15
leaq -0xb8(%rbp), %r8
movq %rcx, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0xb6b0
movsd (%r13), %xmm1
movsd -0x80(%rbp), %xmm0
movsd %xmm1, -0xa0(%rbp)
subsd %xmm1, %xmm0
movsd (%r15), %xmm2
movsd -0x88(%rbp), %xmm1
movsd %xmm2, -0x98(%rbp)
subsd %xmm2, %xmm1
movsd %xmm0, -0x30(%rbp)
movsd %xmm1, -0x40(%rbp)
callq 0xa290
leal -0x3(%r12), %eax
cmpl $-0x3, %eax
ja 0x18026
leaq 0x21471(%rip), %rdi     # 0x39487
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
jmp 0x18165
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x1815b
movsd -0x40(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
callq 0xa100
movsd %xmm0, -0xb0(%rbp)
xorl %eax, %eax
cmpl $0x2, %r12d
sete %al
shll $0x4, %eax
leaq 0x1fab1(%rip), %rcx     # 0x37b10
fldt (%rax,%rcx)
faddl -0xb0(%rbp)
fstpl -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xb550
mulsd -0x38(%rbp), %xmm0
addsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0xa1d0
mulsd -0x38(%rbp), %xmm0
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd -0x98(%rbp), %xmm1
callq 0xa9b0
movl -0x48(%rbp), %eax
cmpl $0xa, %eax
je 0x181bf
testl %eax, %eax
jne 0x182cc
movq -0x90(%rbp), %rax
movl 0x1d0(%rax), %r15d
movsd -0x30(%rbp), %xmm0
callq 0xb550
movsd %xmm0, -0x48(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0xa1d0
movaps %xmm0, %xmm1
movsd 0x10(%rbp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%rsp)
xorpd %xmm2, %xmm2
movq %r14, %rdi
movl %r15d, %esi
movsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm3
movsd -0x38(%rbp), %xmm4
movsd -0x50(%rbp), %xmm5
movsd -0x58(%rbp), %xmm6
movsd -0x60(%rbp), %xmm7
callq 0xb6f0
jmp 0x18241
leaq 0x213ce(%rip), %rsi     # 0x39530
movq %rbx, %rdi
xorl %eax, %eax
callq 0xa850
movq 0x2bded(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0x21317(%rip), %rsi     # 0x394a2
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x90(%rbp), %rax
movl 0x1d0(%rax), %r15d
movsd -0x30(%rbp), %xmm0
callq 0xb550
movsd %xmm0, -0x48(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0xa1d0
movaps %xmm0, %xmm1
movsd 0x10(%rbp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%rsp)
xorpd %xmm2, %xmm2
movq %r14, %rdi
movl %r15d, %esi
movsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm3
movsd -0x38(%rbp), %xmm4
movsd -0x50(%rbp), %xmm5
movsd -0x58(%rbp), %xmm6
movsd -0x60(%rbp), %xmm7
callq 0xb6e0
movb $0x0, 0xc689(%r14)
movq %rbx, %rdi
movq %r14, %rsi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
callq 0xb170
movsd -0x58(%rbp), %xmm0
movsd %xmm0, 0x8(%r14)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, 0x20(%r14)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, 0x38(%r14)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, 0x50(%r14)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, 0x68(%r14)
movsd 0x10(%rbp), %xmm0
movsd %xmm0, 0x80(%r14)
movq %rbx, %rdi
movq %r14, %rsi
movsd -0x80(%rbp), %xmm0
movsd -0x88(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
callq 0xad80
xorl %eax, %eax
jmp 0x181ad
leaq 0x210a8(%rip), %rdi     # 0x3937b
jmp 0x18016