// File: /workspace/github_cpp_makefile_star2_O1/mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::studenttdistribution(long, double, alglib_impl::ae_state*)
double studenttdistribution(ae_int_t k, double t, ae_state *_state)
{
    double x;
    double rk;
    double z;
    double f;
    double tz;
    double p;
    double xsqk;
    ae_int_t j;
    double result;


    ae_assert(k>0, "Domain error in StudentTDistribution", _state);
    if( ae_fp_eq(t,0) )
    {
        result = 0.5;
        return result;
    }
    if( ae_fp_less(t,-2.0) )
    {
        rk = k;
        z = rk/(rk+t*t);
        result = 0.5*incompletebeta(0.5*rk, 0.5, z, _state);
        return result;
    }
    if( ae_fp_less(t,0) )
    {
        x = -t;
    }
    else
    {
        x = t;
    }
    rk = k;
    z = 1.0+x*x/rk;
    if( k%2!=0 )
    {
        xsqk = x/ae_sqrt(rk, _state);
        p = ae_atan(xsqk, _state);
        if( k>1 )
        {
            f = 1.0;
            tz = 1.0;
            j = 3;
            while(j<=k-2&&ae_fp_greater(tz/f,ae_machineepsilon))
            {
                tz = tz*((j-1)/(z*j));
                f = f+tz;
                j = j+2;
            }
            p = p+f*xsqk/z;
        }
        p = p*2.0/ae_pi;
    }
    else
    {
        f = 1.0;
        tz = 1.0;
        j = 2;
        while(j<=k-2&&ae_fp_greater(tz/f,ae_machineepsilon))
        {
            tz = tz*((j-1)/(z*j));
            f = f+tz;
            j = j+2;
        }
        p = f*x/ae_sqrt(z*rk, _state);
    }
    if( ae_fp_less(t,0) )
    {
        p = -p;
    }
    result = 0.5+0.5*p;
    return result;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x50, %rsp
movq %rsi, %r14
movaps %xmm0, 0x30(%rsp)
movq %rdi, %rbx
xorl %edi, %edi
testq %rbx, %rbx
setg %dil
leaq 0x24d32(%rip), %rsi     # 0x3687b
movq %r14, %rdx
callq 0x2581c
xorpd %xmm1, %xmm1
movaps 0x30(%rsp), %xmm0
callq 0x262ba
testb %al, %al
je 0x11b70
movsd 0x228fd(%rip), %xmm0    # 0x34468
jmp 0x11e1e
movsd 0x22878(%rip), %xmm1    # 0x343f0
movaps 0x30(%rsp), %xmm0
callq 0x262fe
testb %al, %al
je 0x11bc5
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movapd 0x30(%rsp), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movapd %xmm0, %xmm2
divsd %xmm1, %xmm2
movsd 0x228bc(%rip), %xmm1    # 0x34468
mulsd %xmm1, %xmm0
movq %r14, %rdi
callq 0xa5e4
mulsd 0x228a8(%rip), %xmm0    # 0x34468
jmp 0x11e1e
xorps %xmm1, %xmm1
movaps 0x30(%rsp), %xmm0
callq 0x262fe
testb %al, %al
jne 0x11bde
movapd 0x30(%rsp), %xmm1
jmp 0x11bf0
movapd 0x225fa(%rip), %xmm1    # 0x341e0
movapd 0x30(%rsp), %xmm3
xorpd %xmm3, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm0, %xmm2
addsd 0x22594(%rip), %xmm2    # 0x341a0
movsd %xmm2, 0x28(%rsp)
testb $0x1, %bl
movapd %xmm1, 0x10(%rsp)
jne 0x11c36
movsd %xmm0, 0x40(%rsp)
cmpq $0x4, %rbx
jge 0x11c81
movsd 0x2256f(%rip), %xmm1    # 0x341a0
jmp 0x11cff
movq %r14, %rdi
callq 0x2658d
movapd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
movq %r14, %rdi
callq 0x266cc
cmpq $0x2, %rbx
jl 0x11dd4
cmpq $0x5, %rbx
movsd %xmm0, 0x40(%rsp)
jge 0x11d38
movsd 0x22524(%rip), %xmm1    # 0x341a0
jmp 0x11db6
addq $-0x2, %rbx
movsd 0x22513(%rip), %xmm0    # 0x341a0
movl $0x2, %r15d
movapd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x48(%rsp)
divsd %xmm1, %xmm0
movsd 0x22c71(%rip), %xmm1    # 0x34920
callq 0x2633e
testb %al, %al
je 0x11cf9
leaq -0x1(%r15), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
mulsd 0x28(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd 0x48(%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
addq $0x2, %r15
cmpq %rbx, %r15
jle 0x11c97
jmp 0x11cff
movsd 0x8(%rsp), %xmm1
movapd 0x10(%rsp), %xmm0
mulsd %xmm1, %xmm0
movapd %xmm0, 0x10(%rsp)
movsd 0x28(%rsp), %xmm0
mulsd 0x40(%rsp), %xmm0
movq %r14, %rdi
callq 0x2658d
movapd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
jmp 0x11de6
addq $-0x2, %rbx
movsd 0x2245c(%rip), %xmm0    # 0x341a0
movl $0x3, %r14d
movapd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x48(%rsp)
divsd %xmm1, %xmm0
movsd 0x22bba(%rip), %xmm1    # 0x34920
callq 0x2633e
testb %al, %al
je 0x11db0
leaq -0x1(%r14), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
mulsd 0x28(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd 0x48(%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
addq $0x2, %r14
cmpq %rbx, %r14
jle 0x11d4e
jmp 0x11db6
movsd 0x8(%rsp), %xmm1
movapd 0x10(%rsp), %xmm0
mulsd %xmm1, %xmm0
divsd 0x28(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
addsd %xmm0, %xmm0
divsd 0x22690(%rip), %xmm0    # 0x34470
movapd %xmm0, 0x10(%rsp)
xorpd %xmm1, %xmm1
movaps 0x30(%rsp), %xmm0
callq 0x262fe
testb %al, %al
jne 0x11e00
movapd 0x10(%rsp), %xmm0
jmp 0x11e0e
movapd 0x10(%rsp), %xmm0
xorpd 0x223d2(%rip), %xmm0    # 0x341e0
movsd 0x22652(%rip), %xmm1    # 0x34468
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
addq $0x50, %rsp
popq %rbx
popq %r14
popq %r15
retq