// File: /workspace/github_cpp_makefile_star2_O2/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_arc_comp1(int, block_struct*, setup_struct*, double, double, double, double, double, double, double, double, double, double, double)
int Interp::convert_arc_comp1(int move,  //!< either G_2 (cw arc) or G_3 (ccw arc)            
                              block_pointer block,       //!< pointer to a block of RS274/NGC instructions    
                              setup_pointer settings,    //!< pointer to machine settings                     
                              double end_x,      //!< x-value at end of programmed (then actual) arc  
                              double end_y,      //!< y-value at end of programmed (then actual) arc  
                              double end_z,      //!< z-value at end of arc                           
                              double offset_x, double offset_y, 
                              double AA_end,     //!< a-value at end of arc                     
                              double BB_end,     //!< b-value at end of arc                     
                              double CC_end,     //!< c-value at end of arc                     
                              double u_end, double v_end, double w_end) //!< uvw at end of arc
{
    double center_x, center_y;
    double gamma;                 /* direction of perpendicular to arc at end */
    int side;                     /* offset side - right or left              */
    double tolerance;             /* tolerance for difference of radii        */
    double tool_radius;
    int turn;                     /* 1 for counterclockwise, -1 for clockwise */
    double cx, cy, cz; // current
    int plane = settings->plane;

    side = settings->cutter_comp_side;
    tool_radius = settings->cutter_comp_radius;   /* always is positive */
    tolerance = (settings->length_units == CANON_UNITS_INCHES) ? TOLERANCE_INCH : TOLERANCE_MM;

    comp_get_current(settings, &cx, &cy, &cz);

    CHKS((hypot((end_x - cx), (end_y - cy)) <= tool_radius),
         "Radius of cutter compensation entry arc is not greater than the tool radius");

    if (block->r_flag) {
        CHP(arc_data_comp_r(move, plane, side, tool_radius, cx, cy, end_x, end_y, 
                            block->r_number,
                            &center_x, &center_y, &turn, tolerance));
    } else {
        CHP(arc_data_comp_ijk(move, plane, side, tool_radius, cx, cy, end_x, end_y,
                              (settings->ijk_distance_mode == MODE_ABSOLUTE),
                              offset_x, offset_y,
                              &center_x, &center_y, &turn, tolerance));
    }

    inverse_time_rate_arc(cx, cy, cz, center_x, center_y,
                          turn, end_x, end_y, end_z, block, settings);


    // the tool will end up in gamma direction from the programmed arc endpoint
    if TOOL_INSIDE_ARC(side, turn) {
        // tool inside the arc: ends up toward the center
        gamma = atan2((center_y - end_y), (center_x - end_x));
    } else {
        // outside: away from the center
        gamma = atan2((end_y - center_y), (end_x - center_x));
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movsd %xmm7, -0xb8(%rbp)
movsd %xmm6, -0xb0(%rbp)
movsd %xmm5, -0xa8(%rbp)
movsd %xmm4, -0xd0(%rbp)
movsd %xmm3, -0xc8(%rbp)
movsd %xmm2, -0x90(%rbp)
movsd %xmm1, -0x70(%rbp)
movsd %xmm0, -0x30(%rbp)
movq %rdx, %r13
movl %esi, -0x98(%rbp)
movq %rdi, %r14
movl 0xc67c(%rcx), %eax
movl %eax, -0xa0(%rbp)
movl 0x624(%rcx), %eax
movl %eax, -0x88(%rbp)
movsd 0x618(%rcx), %xmm0
movsd %xmm0, -0x50(%rbp)
xorl %r15d, %r15d
cmpl $0x1, 0x1690(%rcx)
sete -0xc0(%rbp)
leaq -0xe8(%rbp), %rbx
leaq -0xe0(%rbp), %r12
leaq -0xd8(%rbp), %r8
movq %rcx, -0x40(%rbp)
movq %rcx, %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0xc820
movsd (%rbx), %xmm1
movsd -0x30(%rbp), %xmm0
movsd %xmm1, -0x80(%rbp)
subsd %xmm1, %xmm0
movsd (%r12), %xmm2
movsd -0x70(%rbp), %xmm1
movsd %xmm2, -0x78(%rbp)
subsd %xmm2, %xmm1
callq 0xb2c0
movsd -0x50(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jae 0xef15
movapd %xmm1, %xmm0
movb -0xc0(%rbp), %al
movb %al, %r15b
leaq 0x210e7(%rip), %rax     # 0x2ff20
movsd (%rax,%r15,8), %xmm7
cmpb $0x1, 0x229(%r13)
movq %r13, %rbx
movsd %xmm7, -0xc0(%rbp)
jne 0xef24
movsd 0x230(%rbx), %xmm5
leaq -0x34(%rbp), %rax
movq %rax, (%rsp)
leaq -0x48(%rbp), %r8
leaq -0x58(%rbp), %r9
movq %r14, %r15
movq %r14, %rdi
movl -0x98(%rbp), %esi
movl -0xa0(%rbp), %edx
movl -0x88(%rbp), %r14d
movl %r14d, %ecx
movsd -0x80(%rbp), %xmm1
movsd -0x78(%rbp), %xmm2
movsd -0x30(%rbp), %xmm3
movsd -0x70(%rbp), %xmm4
movaps %xmm7, %xmm6
callq 0xb130
testl %eax, %eax
movq -0x40(%rbp), %r12
je 0xef9a
movl %eax, %r13d
movq 0x2e0a2(%rip), %rbx     # 0x3cf60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0xf225
imulq $0x50, %rax, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x22264(%rip), %rsi     # 0x31149
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 0xf225
leaq 0x221e1(%rip), %rsi     # 0x310fd
movq %r14, %rdi
jmp 0xf1eb
xorl %r8d, %r8d
movq -0x40(%rbp), %r12
cmpl $0x0, 0x66c(%r12)
sete %r8b
leaq -0x34(%rbp), %rax
movq %rax, 0x8(%rsp)
leaq -0x58(%rbp), %rax
movq %rax, (%rsp)
leaq -0x48(%rbp), %r9
movq %r14, %r15
movq %r14, %rdi
movl -0x98(%rbp), %esi
movl -0xa0(%rbp), %edx
movl -0x88(%rbp), %r14d
movl %r14d, %ecx
movsd -0x80(%rbp), %xmm1
movsd -0x78(%rbp), %xmm2
movsd -0x30(%rbp), %xmm3
movsd -0x70(%rbp), %xmm4
movsd -0xc8(%rbp), %xmm5
movsd -0xd0(%rbp), %xmm6
callq 0xc2b0
testl %eax, %eax
jne 0xeeb4
movsd -0xd8(%rbp), %xmm2
movsd -0x48(%rbp), %xmm3
movsd -0x58(%rbp), %xmm4
movl -0x34(%rbp), %esi
movq %r15, %rdi
movsd -0x80(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
movsd %xmm2, -0x98(%rbp)
movsd -0x30(%rbp), %xmm5
movsd -0x70(%rbp), %xmm6
movsd -0x90(%rbp), %xmm7
movq %rbx, %rdx
movq %r12, %rcx
callq 0xbd20
movl %r14d, %ecx
xorl $0x2, %ecx
movl -0x34(%rbp), %eax
movl %eax, %edx
xorl $0x1, %edx
orl %ecx, %edx
je 0xeffe
xorl $0x1, %r14d
notl %eax
orl %r14d, %eax
jne 0xf014
movsd -0x58(%rbp), %xmm0
subsd -0x70(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
jmp 0xf028
movsd -0x70(%rbp), %xmm0
subsd -0x58(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
subsd -0x48(%rbp), %xmm1
callq 0xb110
movsd %xmm0, -0x40(%rbp)
movb $0x0, 0xc689(%r12)
movq %r15, %rdi
movq %r12, %rsi
movsd -0x30(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
movsd -0x90(%rbp), %xmm2
callq 0xbe80
movsd -0x40(%rbp), %xmm0
callq 0xc6c0
mulsd -0x50(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0xb200
movapd %xmm0, %xmm1
mulsd -0x50(%rbp), %xmm1
addsd -0x70(%rbp), %xmm1
movsd %xmm1, -0x50(%rbp)
movsd -0x78(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x80(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
movsd %xmm1, -0xa0(%rbp)
callq 0xb2c0
movsd %xmm0, -0x70(%rbp)
movsd -0x58(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
callq 0xb110
movsd %xmm0, -0x40(%rbp)
movsd -0x88(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm1
callq 0xb110
subsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
callq 0xc6c0
andpd 0x1ef18(%rip), %xmm0    # 0x2e020
movsd 0x20750(%rip), %xmm1    # 0x2f860
ucomisd %xmm0, %xmm1
jbe 0xf122
leaq 0x1f054(%rip), %rdi     # 0x2e171
jmp 0xf1e0
movsd -0x70(%rbp), %xmm0
mulsd 0x1eed9(%rip), %xmm0    # 0x2e008
movsd %xmm0, -0x70(%rbp)
movsd -0x88(%rbp), %xmm0
callq 0xc6c0
movsd -0x70(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x70(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0xc6c0
mulsd -0x70(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0xb200
movsd -0x70(%rbp), %xmm2
mulsd %xmm0, %xmm2
movsd -0x50(%rbp), %xmm1
addsd %xmm1, %xmm2
movsd %xmm2, -0x58(%rbp)
movsd -0x48(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
subsd %xmm1, %xmm2
movapd %xmm2, %xmm1
callq 0xb2c0
movapd %xmm0, -0x70(%rbp)
movsd -0x48(%rbp), %xmm0
subsd -0x80(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
subsd -0x78(%rbp), %xmm1
callq 0xb2c0
movapd -0x70(%rbp), %xmm1
subsd %xmm0, %xmm1
andpd 0x1ee51(%rip), %xmm1    # 0x2e020
ucomisd -0xc0(%rbp), %xmm1
jbe 0xf23a
leaq 0x22002(%rip), %rdi     # 0x311e2
callq 0xb220
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x2dd67(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x21f42(%rip), %rsi     # 0x31149
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %r13
movl %r13d, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x620(%r12), %eax
testl %eax, %eax
je 0xf2c3
cmpl $0x9, %eax
je 0xf2c3
movl 0x1d0(%rbx), %esi
movsd 0x20(%rbp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x18(%rbp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rbp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, (%rsp)
xorps %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq %r12, %rdi
movsd -0x80(%rbp), %xmm3
movsd -0x78(%rbp), %xmm4
movsd -0x98(%rbp), %xmm5
movsd -0xa8(%rbp), %xmm6
movsd -0xb0(%rbp), %xmm7
callq 0xc850
movsd -0x80(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
callq 0xba60
movl 0x1d0(%rbx), %ebx
movsd -0x48(%rbp), %xmm2
movsd -0x58(%rbp), %xmm3
movl -0x34(%rbp), %esi
movq %r15, %rdi
movsd -0x80(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
movsd -0x30(%rbp), %xmm4
movsd -0x50(%rbp), %xmm5
callq 0xbc80
movsd -0x48(%rbp), %xmm3
movsd -0x58(%rbp), %xmm4
movl -0x34(%rbp), %edx
movsd 0x20(%rbp), %xmm1
movsd %xmm1, 0x18(%rsp)
movsd 0x18(%rbp), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x10(%rbp), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd -0xb8(%rbp), %xmm1
movsd %xmm1, (%rsp)
movq %r12, %rdi
movl %ebx, %esi
movsd -0x30(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
movsd -0x90(%rbp), %xmm5
movsd -0xa8(%rbp), %xmm6
movsd -0xb0(%rbp), %xmm7
callq 0xb3f0
movq %r15, %rdi
movq %r12, %rsi
movsd -0x30(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
movsd -0x90(%rbp), %xmm2
callq 0xc2c0
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, 0x8(%r12)
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, 0x20(%r12)
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, 0x38(%r12)
movsd 0x10(%rbp), %xmm0
movsd %xmm0, 0x50(%r12)
movsd 0x18(%rbp), %xmm0
movsd %xmm0, 0x68(%r12)
movsd 0x20(%rbp), %xmm0
movsd %xmm0, 0x80(%r12)
xorl %r13d, %r13d
jmp 0xf225