// File: 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 %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
setg %al
movq -0x20(%rbp), %rdx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x3e03a(%rip), %rsi     # 0x577fb
callq 0x3b240
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c3d0
testb $0x1, %al
jne 0x197d9
jmp 0x197f5
movsd 0x3bc6f(%rip), %xmm0    # 0x55450
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x19b6a
movsd -0x18(%rbp), %xmm0
movsd 0x3be26(%rip), %xmm1    # 0x55628
callq 0x3c440
testb $0x1, %al
jne 0x1980d
jmp 0x19883
cvtsi2sdq -0x10(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd -0x30(%rbp), %xmm2
movsd -0x18(%rbp), %xmm1
movsd -0x18(%rbp), %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x3bc0b(%rip), %xmm0    # 0x55450
mulsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm2
movq -0x20(%rbp), %rdi
movsd 0x3bbf5(%rip), %xmm1    # 0x55450
callq 0xeb20
movaps %xmm0, %xmm1
movsd 0x3bbe5(%rip), %xmm0    # 0x55450
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x19b6a
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x19896
jmp 0x198b9
movsd -0x18(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0x198c3
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
cvtsi2sdq -0x10(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x28(%rbp), %xmm1
mulsd -0x28(%rbp), %xmm1
divsd -0x30(%rbp), %xmm1
movsd 0x3b723(%rip), %xmm0    # 0x55008
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x19a36
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x30(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c890
movaps %xmm0, %xmm1
movsd -0x70(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd10
movsd %xmm0, -0x50(%rbp)
cmpq $0x1, -0x10(%rbp)
jle 0x19a13
movsd 0x3b6b3(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x40(%rbp)
movsd 0x3b6a6(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x48(%rbp)
movq $0x3, -0x60(%rbp)
movq -0x60(%rbp), %rcx
movq -0x10(%rbp), %rdx
subq $0x2, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x71(%rbp)
jg 0x1999f
movsd -0x48(%rbp), %xmm0
divsd -0x40(%rbp), %xmm0
movsd 0x3bf81(%rip), %xmm1    # 0x55918
callq 0x3c4c0
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x199a8
jmp 0x199f6
movsd -0x48(%rbp), %xmm0
movq -0x60(%rbp), %rax
subq $0x1, %rax
cvtsi2sd %rax, %xmm1
movsd -0x38(%rbp), %xmm2
cvtsi2sdq -0x60(%rbp), %xmm3
mulsd %xmm3, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
jmp 0x1996f
movsd -0x50(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
mulsd -0x58(%rbp), %xmm1
divsd -0x38(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x3b9ad(%rip), %xmm0    # 0x553c8
mulsd -0x50(%rbp), %xmm0
movsd 0x3ba30(%rip), %xmm1    # 0x55458
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x19b12
movsd 0x3b5ca(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x40(%rbp)
movsd 0x3b5bd(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x48(%rbp)
movq $0x2, -0x60(%rbp)
movq -0x60(%rbp), %rcx
movq -0x10(%rbp), %rdx
subq $0x2, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x72(%rbp)
jg 0x19a88
movsd -0x48(%rbp), %xmm0
divsd -0x40(%rbp), %xmm0
movsd 0x3be98(%rip), %xmm1    # 0x55918
callq 0x3c4c0
movb %al, -0x72(%rbp)
movb -0x72(%rbp), %al
testb $0x1, %al
jne 0x19a91
jmp 0x19adf
movsd -0x48(%rbp), %xmm0
movq -0x60(%rbp), %rax
subq $0x1, %rax
cvtsi2sd %rax, %xmm1
movsd -0x38(%rbp), %xmm2
cvtsi2sdq -0x60(%rbp), %xmm3
mulsd %xmm3, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
jmp 0x19a58
movsd -0x40(%rbp), %xmm0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x38(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c890
movaps %xmm0, %xmm1
movsd -0x80(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x19b25
jmp 0x19b46
movsd -0x50(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movsd 0x3b8fd(%rip), %xmm1    # 0x55450
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)