// File: /workspace/github_cpp_makefile_star2_O2/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 0xc820
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 0xb2c0
leal -0x3(%r12), %eax
cmpl $-0x3, %eax
ja 0x17a32
leaq 0x1aa6f(%rip), %rdi     # 0x32491
callq 0xb220
movq %rbx, %rdi
movq %rax, %rsi
jmp 0x17b71
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x17b67
movsd -0x40(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
callq 0xb110
movsd %xmm0, -0xb0(%rbp)
xorl %eax, %eax
cmpl $0x2, %r12d
sete %al
shll $0x4, %eax
leaq 0x190a5(%rip), %rcx     # 0x30b10
fldt (%rax,%rcx)
faddl -0xb0(%rbp)
fstpl -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xc6c0
mulsd -0x38(%rbp), %xmm0
addsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0xb200
mulsd -0x38(%rbp), %xmm0
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd -0x98(%rbp), %xmm1
callq 0xba60
movl -0x48(%rbp), %eax
cmpl $0xa, %eax
je 0x17bbc
testl %eax, %eax
jne 0x17cc9
movq -0x90(%rbp), %rax
movl 0x1d0(%rax), %r15d
movsd -0x30(%rbp), %xmm0
callq 0xc6c0
movsd %xmm0, -0x48(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0xb200
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 0xc860
jmp 0x17c3e
leaq 0x1a9cc(%rip), %rsi     # 0x3253a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xb8e0
movq 0x253e1(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x1a91f(%rip), %rsi     # 0x324ac
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %rax
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 0xc6c0
movsd %xmm0, -0x48(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0xb200
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 0xc850
movb $0x0, 0xc689(%r14)
movq %rbx, %rdi
movq %r14, %rsi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
callq 0xc2c0
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 0xbe80
xorl %eax, %eax
jmp 0x17baa
leaq 0x1a6b5(%rip), %rdi     # 0x32385
jmp 0x17a22
nop