// File: mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::besselkn(long, double, alglib_impl::ae_state*)
double besselkn(ae_int_t nn, double x, ae_state *_state)
{
    double k;
    double kf;
    double nk1f;
    double nkf;
    double zn;
    double t;
    double s;
    double z0;
    double z;
    double ans;
    double fn;
    double pn;
    double pk;
    double zmn;
    double tlg;
    double tox;
    ae_int_t i;
    ae_int_t n;
    double eul;
    double result;


    eul = 5.772156649015328606065e-1;
    if( nn<0 )
    {
        n = -nn;
    }
    else
    {
        n = nn;
    }
    ae_assert(n<=31, "Overflow in BesselKN", _state);
    ae_assert(ae_fp_greater(x,0), "Domain error in BesselKN", _state);
    if( ae_fp_less_eq(x,9.55) )
    {
        ans = 0.0;
        z0 = 0.25*x*x;
        fn = 1.0;
        pn = 0.0;
        zmn = 1.0;
        tox = 2.0/x;
        if( n>0 )
        {
            pn = -eul;
            k = 1.0;
            for(i=1; i<=n-1; i++)
            {
                pn = pn+1.0/k;
                k = k+1.0;
                fn = fn*k;
            }
            zmn = tox;
            if( n==1 )
            {
                ans = 1.0/x;
            }
            else
            {
                nk1f = fn/n;
                kf = 1.0;
                s = nk1f;
                z = -z0;
                zn = 1.0;
                for(i=1; i<=n-1; i++)
                {
                    nk1f = nk1f/(n-i);
                    kf = kf*i;
                    zn = zn*z;
                    t = nk1f*zn/kf;
                    s = s+t;
                    ae_assert(ae_fp_greater(ae_maxrealnumber-ae_fabs(t, _state),ae_fabs(s, _state)), "Overflow in BesselKN", _state);
                    ae_assert(!(ae_fp_greater(tox,1.0)&&ae_fp_less(ae_maxrealnumber/tox,zmn)), "Overflow in BesselKN", _state);
                    zmn = zmn*tox;
                }
                s = s*0.5;
                t = ae_fabs(s, _state);
                ae_assert(!(ae_fp_greater(zmn,1.0)&&ae_fp_less(ae_maxrealnumber/zmn,t)), "Overflow in BesselKN", _state);
                ae_assert(!(ae_fp_greater(t,1.0)&&ae_fp_less(ae_maxrealnumber/t,zmn)), "Overflow in BesselKN", _state);
                ans = s*zmn;
            }
        }
        tlg = 2.0*ae_log(0.5*x, _state);
        pk = -eul;
        if( n==0 )
        {
            pn = pk;
            t = 1.0;
        }
        else
        {
            pn = pn+1.0/n;
            t = 1.0/fn;
        }
        s = (pk+pn-tlg)*t;
        k = 1.0;
        do
        {
            t = t*(z0/(k*(k+n)));
            pk = pk+1.0/k;
            pn = pn+1.0/(k+n);
            s = s+(pk+pn-tlg)*t;
            k = k+1.0;
        }
        while(ae_fp_greater(ae_fabs(t/s, _state),ae_machineepsilon));
        s = 0.5*s/zmn;
        if( n%2!=0 )
        {
            s = -s;
        }
        ans = ans+s;
        result = ans;
        return result;
    }
    if( ae_fp_greater(x,ae_log(ae_maxrealnumber, _state)) )
    {
        result = 0;
        return result;
    }
    k = n;
    pn = 4.0*k*k;
    pk = 1.0;
    z0 = 8.0*x;
    fn = 1.0;
    t = 1.0;
    s = t;
    nkf = ae_maxrealnumber;
    i = 0;
    do
    {
        z = pn-pk*pk;
        t = t*z/(fn*z0);
        nk1f = ae_fabs(t, _state);
        if( i>=n&&ae_fp_greater(nk1f,nkf) )
        {
            break;
        }
        nkf = nk1f;
        s = s+t;
        fn = fn+1.0;
        pk = pk+2.0;
        i = i+1;
    }
    while(ae_fp_greater(ae_fabs(t/s, _state),ae_machineepsilon));
    result = ae_exp(-x, _state)*ae_sqrt(ae_pi/(2.0*x), _state)*s;
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movsd 0x477e0(%rip), %xmm0    # 0x55440
movsd %xmm0, -0xb8(%rbp)
cmpq $0x0, -0x10(%rbp)
jge 0xdc7e
xorl %eax, %eax
subq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0xdc89
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x1f, -0xb0(%rbp)
setle %al
movq -0x20(%rbp), %rdx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x4987f(%rip), %rsi     # 0x57524
callq 0x3b240
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c4c0
movq -0x20(%rbp), %rdx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x49871(%rip), %rsi     # 0x57539
callq 0x3b240
movsd -0x18(%rbp), %xmm0
movsd 0x48736(%rip), %xmm1    # 0x56410
callq 0x3c480
testb $0x1, %al
jne 0xdce8
jmp 0xe33c
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd 0x48720(%rip), %xmm0    # 0x56418
mulsd -0x18(%rbp), %xmm0
mulsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x472f9(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x78(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x472e4(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x90(%rbp)
movsd 0x47694(%rip), %xmm0    # 0x553c8
divsd -0x18(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
cmpq $0x0, -0xb0(%rbp)
jle 0xe0fc
movsd -0xb8(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x4728d(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x28(%rbp)
movq $0x1, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq -0xb0(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jg 0xddf2
movsd -0x80(%rbp), %xmm0
movsd 0x47259(%rip), %xmm1    # 0x55008
divsd -0x28(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x47243(%rip), %xmm0    # 0x55008
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x78(%rbp), %xmm0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0xdd8b
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
cmpq $0x1, -0xb0(%rbp)
jne 0xde23
movsd 0x471f4(%rip), %xmm0    # 0x55008
divsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0xe0fa
movsd -0x78(%rbp), %xmm0
cvtsi2sdq -0xb0(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x471c6(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x60(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd 0x4718e(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x48(%rbp)
movq $0x1, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq -0xb0(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jg 0xdffe
movsd -0x38(%rbp), %xmm0
movq -0xb0(%rbp), %rax
subq -0xa8(%rbp), %rax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
cvtsi2sdq -0xa8(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x48(%rbp), %xmm0
mulsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x38(%rbp), %xmm0
mulsd -0x48(%rbp), %xmm0
divsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x58(%rbp), %xmm0
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x50(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movaps %xmm0, %xmm1
movsd 0x47880(%rip), %xmm0    # 0x557a8
subsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movaps %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
callq 0x3c4c0
movq -0x20(%rbp), %rdx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x495c1(%rip), %rsi     # 0x57524
callq 0x3b240
movsd -0xa0(%rbp), %xmm0
movsd 0x47090(%rip), %xmm1    # 0x55008
callq 0x3c4c0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xc1(%rbp)
jne 0xdf8e
jmp 0xdfb1
movsd 0x47812(%rip), %xmm0    # 0x557a8
divsd -0xa0(%rbp), %xmm0
movsd -0x90(%rbp), %xmm1
callq 0x3c440
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
xorb $-0x1, %al
movq -0x20(%rbp), %rdx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x4955a(%rip), %rsi     # 0x57524
callq 0x3b240
movsd -0x90(%rbp), %xmm0
mulsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0xde8a
movsd 0x4744a(%rip), %xmm0    # 0x55450
mulsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd %xmm0, -0x50(%rbp)
movsd -0x90(%rbp), %xmm0
movsd 0x46fd5(%rip), %xmm1    # 0x55008
callq 0x3c4c0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xd1(%rbp)
jne 0xe049
jmp 0xe069
movsd 0x47757(%rip), %xmm0    # 0x557a8
divsd -0x90(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
callq 0x3c440
movb %al, -0xd1(%rbp)
movb -0xd1(%rbp), %al
xorb $-0x1, %al
movq -0x20(%rbp), %rdx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x494a2(%rip), %rsi     # 0x57524
callq 0x3b240
movsd -0x50(%rbp), %xmm0
movsd 0x46f74(%rip), %xmm1    # 0x55008
callq 0x3c4c0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xd2(%rbp)
jne 0xe0aa
jmp 0xe0ca
movsd 0x476f6(%rip), %xmm0    # 0x557a8
divsd -0x50(%rbp), %xmm0
movsd -0x90(%rbp), %xmm1
callq 0x3c440
movb %al, -0xd2(%rbp)
movb -0xd2(%rbp), %al
xorb $-0x1, %al
movq -0x20(%rbp), %rdx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x49441(%rip), %rsi     # 0x57524
callq 0x3b240
movsd -0x58(%rbp), %xmm0
mulsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0xe0fc
movsd 0x4734c(%rip), %xmm0    # 0x55450
mulsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd70
movaps %xmm0, %xmm1
movsd 0x472ab(%rip), %xmm0    # 0x553c8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0xb8(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x88(%rbp)
cmpq $0x0, -0xb0(%rbp)
jne 0xe176
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x46e99(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x50(%rbp)
jmp 0xe1ab
movsd -0x80(%rbp), %xmm0
cvtsi2sdq -0xb0(%rbp), %xmm2
movsd 0x46e7c(%rip), %xmm1    # 0x55008
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x46e67(%rip), %xmm0    # 0x55008
divsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x88(%rbp), %xmm0
addsd -0x80(%rbp), %xmm0
subsd -0x98(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x46e36(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x28(%rbp)
movsd -0x50(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
movsd -0x28(%rbp), %xmm2
movsd -0x28(%rbp), %xmm3
cvtsi2sdq -0xb0(%rbp), %xmm4
addsd %xmm4, %xmm3
mulsd %xmm3, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x88(%rbp), %xmm0
movsd 0x46def(%rip), %xmm1    # 0x55008
divsd -0x28(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x80(%rbp), %xmm0
movsd -0x28(%rbp), %xmm2
cvtsi2sdq -0xb0(%rbp), %xmm1
addsd %xmm1, %xmm2
movsd 0x46dbf(%rip), %xmm1    # 0x55008
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x58(%rbp), %xmm1
movsd -0x88(%rbp), %xmm0
addsd -0x80(%rbp), %xmm0
subsd -0x98(%rbp), %xmm0
movsd -0x50(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x46d7e(%rip), %xmm0    # 0x55008
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x50(%rbp), %xmm0
divsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd 0x47669(%rip), %xmm1    # 0x55918
callq 0x3c4c0
testb $0x1, %al
jne 0xe1d7
movsd 0x4718c(%rip), %xmm0    # 0x55450
mulsd -0x58(%rbp), %xmm0
divsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0xb0(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0xe30e
movsd -0x58(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x70(%rbp), %xmm0
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0xe595
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movq -0x20(%rbp), %rdi
movsd 0x47453(%rip), %xmm0    # 0x557a8
callq 0x3cd70
movaps %xmm0, %xmm1
movsd -0xe0(%rbp), %xmm0
callq 0x3c4c0
testb $0x1, %al
jne 0xe370
jmp 0xe38d
xorps %xmm0, %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0xe595
cvtsi2sdq -0xb0(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd 0x46e15(%rip), %xmm0    # 0x551b8
mulsd -0x28(%rbp), %xmm0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x46c4e(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x88(%rbp)
movsd 0x47256(%rip), %xmm0    # 0x55620
mulsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x46c2c(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x78(%rbp)
movsd 0x46c1f(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x473a8(%rip), %xmm0    # 0x557a8
movsd %xmm0, -0x40(%rbp)
movq $0x0, -0xa8(%rbp)
movsd -0x80(%rbp), %xmm1
movsd -0x88(%rbp), %xmm0
movsd -0x88(%rbp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x50(%rbp), %xmm0
mulsd -0x68(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
mulsd -0x60(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd %xmm0, -0x38(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jl 0xe4a0
movsd -0x38(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
callq 0x3c4c0
testb $0x1, %al
jne 0xe49e
jmp 0xe4a0
jmp 0xe51d
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x58(%rbp), %xmm0
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x46b47(%rip), %xmm0    # 0x55008
addsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd 0x46ef5(%rip), %xmm0    # 0x553c8
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
movsd -0x50(%rbp), %xmm0
divsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd 0x47408(%rip), %xmm1    # 0x55918
callq 0x3c4c0
testb $0x1, %al
jne 0xe410
movsd -0x18(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cdd0
movsd %xmm0, -0xe8(%rbp)
movsd 0x46e76(%rip), %xmm1    # 0x553c8
mulsd -0x18(%rbp), %xmm1
movsd 0x46ef9(%rip), %xmm0    # 0x55458
divsd %xmm1, %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c890
movaps %xmm0, %xmm1
movsd -0xe8(%rbp), %xmm0
mulsd %xmm1, %xmm0
mulsd -0x58(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)