// File: /workspace/github_cpp_makefile_star2_O2/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_threading_cycle(block_struct*, setup_struct*, double, double, double)
int Interp::convert_threading_cycle(block_pointer block, 
				    setup_pointer settings,
				    double end_x, double end_y, double end_z) {


    CHKS((settings->cutter_comp_side != OFF),
         (_("Cannot use G76 threading cycle with cutter radius compensation on")));

    CHKS((block->i_number == 0),
        (_("In G76, I must not be 0")));
    CHKS((block->j_number <= 0),
        (_("In G76, J must be greater than 0")));
    CHKS((block->k_number <= block->j_number),
        (_("In G76, K must be greater than J")));

    double start_x = settings->current_x;
    double start_y = settings->current_y;
    double start_z = settings->current_z;

    double i_number = block->i_number;
    double j_number = block->j_number;
    double k_number = block->k_number;

    if(_setup.lathe_diameter_mode){
      i_number /= 2;
      j_number /= 2;
      k_number /= 2;
    }


    int boring = 0;

    if (i_number > 0.0)
	boring = 1;

    double safe_x = start_x;
    double full_dia_depth = fabs(i_number);
    double start_depth = fabs(i_number) + fabs(j_number);
    double cut_increment = fabs(j_number);
    double full_threadheight = fabs(k_number);
    double end_depth = fabs(k_number) + fabs(i_number);

    double pitch = block->p_number;
    double compound_angle = block->q_number;
    if(compound_angle == -1) compound_angle = 0;
    compound_angle *= M_PIl/180.0;
    if(end_z > start_z) compound_angle = -compound_angle;

    int spring_cuts = block->h_flag == ON ? block->h_number: 0;

    double degression = block->r_number;
    if(degression < 1.0 || !block->r_flag) degression = 1.0;

    double taper_dist = block->e_flag? block->e_number: 0.0;
    if(taper_dist < 0.0) taper_dist = 0.0;
    double taper_pitch = taper_dist > 0.0? 
	pitch * hypot(taper_dist, full_threadheight)/taper_dist: pitch;

    if(end_z > start_z) taper_dist = -taper_dist;

    int taper_flags = block->l_number;
    if(taper_flags < 0) taper_flags = 0;

    int entry_taper = taper_flags & 1;
    int exit_taper = taper_flags & 2;

    double depth, zoff;
    int pass = 1;

    double target_z = end_z + fabs(k_number) * tan(compound_angle);

    depth = start_depth;
    zoff = (depth - full_dia_depth) * tan(compound_angle);
    while (depth < end_depth) {
	threading_pass(settings, block, boring, safe_x, depth, end_depth, start_y, 
		       start_z, zoff, taper_dist, entry_taper, exit_taper, 
		       taper_pitch, pitch, full_threadheight, target_z);
        depth = full_dia_depth + cut_increment * pow(++pass, 1.0/degression);
        zoff = (depth - full_dia_depth) * tan(compound_angle);
    } 
    // full specified depth now
    depth = end_depth;
    zoff = (depth - full_dia_depth) * tan(compound_angle);
    // cut at least once -- more if spring cuts.
    for(int i = 0; i<spring_cuts+1; i++) {
	threading_pass(settings, block, boring, safe_x, depth, end_depth, start_y, 
		       start_z, zoff, taper_dist, entry_taper, exit_taper, 
		       taper_pitch, pitch, full_threadheight, target_z);
    } 
    STRAIGHT_TRAVERSE(block->line_number, end_x, end_y, end_z, AABBCC);
    settings->current_x = end_x;
    settings->current_y = end_y;
    settings->current_z = end_z;
#undef AABBC
    return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %r15
cmpl $0x0, 0x624(%rdx)
je 0x18852
leaq 0x19b4e(%rip), %rdi     # 0x3239b
jmp 0x189d0
movq %rsi, %r14
movsd 0x1a0(%rsi), %xmm4
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm4
jne 0x18875
jp 0x18875
leaq 0x19bc7(%rip), %rdi     # 0x32437
jmp 0x189d0
movsd 0x1b0(%r14), %xmm5
ucomisd %xmm5, %xmm3
jae 0x189c0
movsd 0x1c0(%r14), %xmm3
movapd %xmm3, -0x40(%rbp)
ucomisd %xmm3, %xmm5
jae 0x189c9
movq %rdx, %rbx
movsd 0x610(%rdx), %xmm3
movsd %xmm3, -0x88(%rbp)
movq 0x246a6(%rip), %rax     # 0x3cf60
cmpb $0x0, 0x1e6d8(%rax)
movsd %xmm1, -0xb0(%rbp)
movsd %xmm0, -0xa8(%rbp)
je 0x188f1
movsd 0x1572d(%rip), %xmm0    # 0x2e008
mulsd %xmm0, %xmm4
mulsd %xmm0, %xmm5
movapd -0x40(%rbp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, -0x40(%rbp)
movsd 0x600(%rbx), %xmm0
movsd %xmm0, -0xc8(%rbp)
xorpd %xmm0, %xmm0
movl $0x0, -0x2c(%rbp)
ucomisd %xmm0, %xmm4
movsd 0x608(%rbx), %xmm0
movsd %xmm0, -0xc0(%rbp)
seta %r12b
movsd 0x210(%r14), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x220(%r14), %xmm0
movsd 0x16f2d(%rip), %xmm1    # 0x2f870
cmpeqsd %xmm0, %xmm1
andnpd %xmm0, %xmm1
movlpd %xmm1, -0x110(%rbp)
fldt 0x17666(%rip)           # 0x2ffc0
fmull -0x110(%rbp)
movapd 0x156b8(%rip), %xmm0    # 0x2e020
fstpl -0x108(%rbp)
movsd -0x108(%rbp), %xmm3
movapd 0x17592(%rip), %xmm1    # 0x2ff10
xorpd %xmm3, %xmm1
movsd -0x88(%rbp), %xmm6
cmpltsd %xmm2, %xmm6
movapd %xmm6, %xmm7
andnpd %xmm3, %xmm7
movapd %xmm7, -0xa0(%rbp)
movapd %xmm6, -0x100(%rbp)
andpd %xmm6, %xmm1
cmpb $0x1, 0x190(%r14)
jne 0x18a26
movl 0x194(%r14), %eax
incl %eax
jmp 0x18a29
leaq 0x19a88(%rip), %rdi     # 0x3244f
jmp 0x189d0
leaq 0x19aa0(%rip), %rdi     # 0x32470
callq 0xb220
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x24577(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x199e6(%rip), %rsi     # 0x323dd
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rax
movl %eax, -0x30(%rbp)
movapd -0x40(%rbp), %xmm3
andpd %xmm0, %xmm3
movapd %xmm3, -0x40(%rbp)
movapd -0xa0(%rbp), %xmm3
orpd %xmm1, %xmm3
movapd %xmm3, -0xa0(%rbp)
movsd 0x230(%r14), %xmm3
movsd 0x17441(%rip), %xmm1    # 0x2fea0
movsd %xmm1, -0x70(%rbp)
ucomisd %xmm3, %xmm1
ja 0x18a74
cmpb $0x0, 0x229(%r14)
jne 0x18a7c
movsd 0x17424(%rip), %xmm3    # 0x2fea0
andpd %xmm0, %xmm4
andpd %xmm0, %xmm5
xorpd %xmm0, %xmm0
cmpb $0x1, 0x139(%r14)
xorpd %xmm1, %xmm1
jne 0x18a9f
movsd 0x140(%r14), %xmm1
movsd %xmm3, -0x78(%rbp)
movsd %xmm2, -0x68(%rbp)
movapd %xmm4, %xmm2
movapd %xmm5, -0x130(%rbp)
addsd %xmm5, %xmm2
movapd %xmm2, -0x60(%rbp)
xorpd %xmm2, %xmm2
maxsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movapd %xmm4, -0xe0(%rbp)
jbe 0x18b12
movapd %xmm2, %xmm0
movapd -0x40(%rbp), %xmm1
movapd %xmm2, -0xf0(%rbp)
callq 0xb2c0
movapd -0xf0(%rbp), %xmm2
movapd -0xe0(%rbp), %xmm4
mulsd -0x48(%rbp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, -0x80(%rbp)
movl -0x2c(%rbp), %eax
movb %r12b, %al
movl %eax, -0x2c(%rbp)
movapd -0x40(%rbp), %xmm0
addsd %xmm4, %xmm0
movapd %xmm0, -0xf0(%rbp)
movapd 0x173dc(%rip), %xmm0    # 0x2ff10
xorpd %xmm2, %xmm0
movapd -0x100(%rbp), %xmm1
andpd %xmm1, %xmm0
andnpd %xmm2, %xmm1
movl 0x1c8(%r14), %eax
xorl %r12d, %r12d
testl %eax, %eax
cmovgl %eax, %r12d
orpd %xmm0, %xmm1
movapd %xmm1, -0x100(%rbp)
movl %r12d, %r13d
andl $0x1, %r13d
andl $0x2, %r12d
movapd -0xa0(%rbp), %xmm0
callq 0xb5c0
mulsd -0x40(%rbp), %xmm0
addsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movapd -0x60(%rbp), %xmm0
subsd -0xe0(%rbp), %xmm0
movapd %xmm0, -0x120(%rbp)
movapd -0xa0(%rbp), %xmm0
callq 0xb5c0
movapd %xmm0, %xmm5
mulsd -0x120(%rbp), %xmm5
movsd -0x70(%rbp), %xmm0
divsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
pushq $0x2
popq %r15
movapd -0xf0(%rbp), %xmm2
movapd -0x60(%rbp), %xmm1
ucomisd %xmm1, %xmm2
jbe 0x18c90
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, 0x10(%rsp)
movaps -0x40(%rbp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movl -0x2c(%rbp), %edx
movsd -0xc8(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm3
movsd -0x88(%rbp), %xmm4
movapd -0x100(%rbp), %xmm6
movl %r13d, %ecx
movl %r12d, %r8d
movsd -0x80(%rbp), %xmm7
callq 0x18daf
cvtsi2sd %r15d, %xmm0
movsd -0x70(%rbp), %xmm1
callq 0xc4c0
mulsd -0x130(%rbp), %xmm0
movapd -0xe0(%rbp), %xmm1
addsd %xmm1, %xmm0
movapd %xmm0, -0x60(%rbp)
subsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movapd -0xa0(%rbp), %xmm0
callq 0xb5c0
movapd %xmm0, %xmm5
mulsd -0x78(%rbp), %xmm5
incl %r15d
jmp 0x18bcf
subsd -0xe0(%rbp), %xmm2
movapd %xmm2, -0x60(%rbp)
movapd -0xa0(%rbp), %xmm0
callq 0xb5c0
mulsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
xorl %r15d, %r15d
movl -0x30(%rbp), %eax
testl %eax, %eax
cmovgl %eax, %r15d
subl $0x1, %r15d
jb 0x18d34
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, 0x10(%rsp)
movaps -0x40(%rbp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movl -0x2c(%rbp), %edx
movsd -0xc8(%rbp), %xmm0
movapd -0xf0(%rbp), %xmm1
movapd %xmm1, %xmm2
movsd -0xc0(%rbp), %xmm3
movsd -0x88(%rbp), %xmm4
movsd -0x60(%rbp), %xmm5
movapd -0x100(%rbp), %xmm6
movl %r13d, %ecx
movl %r12d, %r8d
movsd -0x80(%rbp), %xmm7
callq 0x18daf
jmp 0x18cc0
movl 0x1d0(%r14), %edi
movsd 0x8(%rbx), %xmm3
movsd 0x20(%rbx), %xmm4
movsd 0x38(%rbx), %xmm5
movsd 0x50(%rbx), %xmm6
movsd 0x68(%rbx), %xmm7
movsd 0x80(%rbx), %xmm0
movsd %xmm0, (%rsp)
movsd -0xa8(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm1
movsd -0x68(%rbp), %xmm2
callq 0xb970
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, 0x600(%rbx)
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, 0x608(%rbx)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, 0x610(%rbx)
xorl %eax, %eax
jmp 0x18a14