// File: /workspace/github_cpp_makefile_star2_O3/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 0x240a8(%rip), %rsi     # 0x35a1b
movq %r14, %rdx
callq 0x2510e
xorpd %xmm1, %xmm1
movaps 0x30(%rsp), %xmm0
callq 0x25b75
testb %al, %al
je 0x1199a
movsd 0x21af3(%rip), %xmm0    # 0x33488
jmp 0x11c48
movsd 0x21a6e(%rip), %xmm1    # 0x33410
movaps 0x30(%rsp), %xmm0
callq 0x25bb9
testb %al, %al
je 0x119ef
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movapd 0x30(%rsp), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movapd %xmm0, %xmm2
divsd %xmm1, %xmm2
movsd 0x21ab2(%rip), %xmm1    # 0x33488
mulsd %xmm1, %xmm0
movq %r14, %rdi
callq 0xa477
mulsd 0x21a9e(%rip), %xmm0    # 0x33488
jmp 0x11c48
xorps %xmm1, %xmm1
movaps 0x30(%rsp), %xmm0
callq 0x25bb9
testb %al, %al
jne 0x11a08
movapd 0x30(%rsp), %xmm1
jmp 0x11a1a
movapd 0x217a0(%rip), %xmm1    # 0x331b0
movapd 0x30(%rsp), %xmm3
xorpd %xmm3, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm0, %xmm2
addsd 0x217aa(%rip), %xmm2    # 0x331e0
movsd %xmm2, 0x28(%rsp)
testb $0x1, %bl
movapd %xmm1, 0x10(%rsp)
jne 0x11a60
movsd %xmm0, 0x40(%rsp)
cmpq $0x4, %rbx
jge 0x11aab
movsd 0x21785(%rip), %xmm1    # 0x331e0
jmp 0x11b29
movq %r14, %rdi
callq 0x25e48
movapd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
movq %r14, %rdi
callq 0x25f87
cmpq $0x2, %rbx
jl 0x11bfe
cmpq $0x5, %rbx
movsd %xmm0, 0x40(%rsp)
jae 0x11b62
movsd 0x2173a(%rip), %xmm1    # 0x331e0
jmp 0x11be0
addq $-0x2, %rbx
movsd 0x21729(%rip), %xmm0    # 0x331e0
movl $0x2, %r15d
movapd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x48(%rsp)
divsd %xmm1, %xmm0
movsd 0x21d17(%rip), %xmm1    # 0x337f0
callq 0x25bf9
testb %al, %al
je 0x11b23
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 0x11ac1
jmp 0x11b29
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 0x25e48
movapd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
jmp 0x11c10
addq $-0x2, %rbx
movsd 0x21672(%rip), %xmm0    # 0x331e0
movl $0x3, %r14d
movapd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x48(%rsp)
divsd %xmm1, %xmm0
movsd 0x21c60(%rip), %xmm1    # 0x337f0
callq 0x25bf9
testb %al, %al
je 0x11bda
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 0x11b78
jmp 0x11be0
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 0x21886(%rip), %xmm0    # 0x33490
movapd %xmm0, 0x10(%rsp)
xorpd %xmm1, %xmm1
movaps 0x30(%rsp), %xmm0
callq 0x25bb9
testb %al, %al
jne 0x11c2a
movapd 0x10(%rsp), %xmm0
jmp 0x11c38
movapd 0x10(%rsp), %xmm0
xorpd 0x21578(%rip), %xmm0    # 0x331b0
movsd 0x21848(%rip), %xmm1    # 0x33488
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
addq $0x50, %rsp
popq %rbx
popq %r14
popq %r15
retq