// File: /workspace/github_cpp_makefile_star2_O2/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, 0x20(%rsp)
movq %rdi, %rbx
xorl %edi, %edi
testq %rbx, %rbx
setg %dil
leaq 0x21bf5(%rip), %rsi     # 0x32a0b
movq %r14, %rdx
callq 0x238ca
xorpd %xmm1, %xmm1
movaps 0x20(%rsp), %xmm0
callq 0x241f5
testb %al, %al
je 0x10e3d
movsd 0x1f650(%rip), %xmm0    # 0x30488
jmp 0x110b1
movsd 0x1f5bb(%rip), %xmm1    # 0x30400
movaps 0x20(%rsp), %xmm0
callq 0x24239
testb %al, %al
je 0x10e8f
cvtsi2sd %rbx, %xmm0
movapd 0x20(%rsp), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movapd %xmm0, %xmm2
divsd %xmm1, %xmm2
movsd 0x1f612(%rip), %xmm1    # 0x30488
mulsd %xmm1, %xmm0
movq %r14, %rdi
callq 0x9cf5
mulsd 0x1f5fe(%rip), %xmm0    # 0x30488
jmp 0x110b1
xorps %xmm1, %xmm1
movapd 0x20(%rsp), %xmm0
callq 0x24239
testb %al, %al
jne 0x10ea9
movapd 0x20(%rsp), %xmm1
jmp 0x10ebb
movapd 0x1f2ff(%rip), %xmm1    # 0x301b0
movapd 0x20(%rsp), %xmm0
xorpd %xmm0, %xmm1
cvtsi2sd %rbx, %xmm2
movapd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
addsd 0x1f324(%rip), %xmm0    # 0x301f8
movsd %xmm0, 0x8(%rsp)
testb $0x1, %bl
movapd %xmm1, 0x40(%rsp)
jne 0x10f6d
addq $-0x2, %rbx
pushq $0x2
popq %r15
movsd 0x1f2ff(%rip), %xmm3    # 0x301f8
movapd %xmm3, %xmm4
movsd %xmm2, 0x10(%rsp)
cmpq %rbx, %r15
jg 0x11019
movapd %xmm4, %xmm0
divsd %xmm3, %xmm0
movsd 0x1f8d4(%rip), %xmm1    # 0x307f0
movsd %xmm3, 0x38(%rsp)
movsd %xmm4, 0x30(%rsp)
callq 0x24279
movsd 0x30(%rsp), %xmm4
movsd 0x38(%rsp), %xmm3
movsd 0x10(%rsp), %xmm2
testb %al, %al
je 0x11019
leaq -0x1(%r15), %rax
cvtsi2sd %rax, %xmm0
cvtsi2sd %r15, %xmm1
mulsd 0x8(%rsp), %xmm1
divsd %xmm1, %xmm0
mulsd %xmm0, %xmm4
addsd %xmm4, %xmm3
addq $0x2, %r15
jmp 0x10f03
movapd %xmm2, %xmm0
movq %r14, %rdi
callq 0x24424
movapd 0x40(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
movapd %xmm1, %xmm0
movq %r14, %rdi
callq 0x24555
cmpq $0x2, %rbx
jl 0x11067
movapd %xmm0, 0x10(%rsp)
addq $-0x2, %rbx
pushq $0x3
popq %r14
movsd 0x1f243(%rip), %xmm2    # 0x301f8
movapd %xmm2, %xmm3
cmpq %rbx, %r14
jg 0x1104d
movapd %xmm3, %xmm0
divsd %xmm2, %xmm0
movsd 0x1f81e(%rip), %xmm1    # 0x307f0
movsd %xmm2, 0x38(%rsp)
movsd %xmm3, 0x30(%rsp)
callq 0x24279
movsd 0x30(%rsp), %xmm3
movsd 0x38(%rsp), %xmm2
testb %al, %al
je 0x1104d
leaq -0x1(%r14), %rax
cvtsi2sd %rax, %xmm0
cvtsi2sd %r14, %xmm1
mulsd 0x8(%rsp), %xmm1
divsd %xmm1, %xmm0
mulsd %xmm0, %xmm3
addsd %xmm3, %xmm2
addq $0x2, %r14
jmp 0x10fb9
movapd 0x40(%rsp), %xmm0
mulsd %xmm3, %xmm0
movapd %xmm0, 0x40(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd %xmm2, %xmm0
movq %r14, %rdi
callq 0x24424
movapd 0x40(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
jmp 0x11079
movapd 0x40(%rsp), %xmm1
mulsd %xmm2, %xmm1
divsd 0x8(%rsp), %xmm1
movapd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
divsd 0x1f41d(%rip), %xmm0    # 0x30490
movapd %xmm0, 0x10(%rsp)
xorpd %xmm1, %xmm1
movaps 0x20(%rsp), %xmm0
callq 0x24239
testb %al, %al
jne 0x11093
movapd 0x10(%rsp), %xmm0
jmp 0x110a1
movapd 0x10(%rsp), %xmm0
xorpd 0x1f10f(%rip), %xmm0    # 0x301b0
movsd 0x1f3df(%rip), %xmm1    # 0x30488
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
addq $0x50, %rsp
popq %rbx
popq %r14
popq %r15
retq