// File: /workspace/github_cpp_makefile_star2_O1/mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::besseljn(long, double, alglib_impl::ae_state*)
double besseljn(ae_int_t n, double x, ae_state *_state)
{
    double pkm2;
    double pkm1;
    double pk;
    double xk;
    double r;
    double ans;
    ae_int_t k;
    ae_int_t sg;
    double result;


    if( n<0 )
    {
        n = -n;
        if( n%2==0 )
        {
            sg = 1;
        }
        else
        {
            sg = -1;
        }
    }
    else
    {
        sg = 1;
    }
    if( ae_fp_less(x,0) )
    {
        if( n%2!=0 )
        {
            sg = -sg;
        }
        x = -x;
    }
    if( n==0 )
    {
        result = sg*besselj0(x, _state);
        return result;
    }
    if( n==1 )
    {
        result = sg*besselj1(x, _state);
        return result;
    }
    if( n==2 )
    {
        if( ae_fp_eq(x,0) )
        {
            result = 0;
        }
        else
        {
            result = sg*(2.0*besselj1(x, _state)/x-besselj0(x, _state));
        }
        return result;
    }
    if( ae_fp_less(x,ae_machineepsilon) )
    {
        result = 0;
        return result;
    }
    k = 53;
    pk = 2*(n+k);
    ans = pk;
    xk = x*x;
    do
    {
        pk = pk-2.0;
        ans = pk-xk/ans;
        k = k-1;
    }
    while(k!=0);
    ans = x/ans;
    pk = 1.0;
    pkm1 = 1.0/ans;
    k = n-1;
    r = 2*k;
    do
    {
        pkm2 = (pkm1*r-pk*x)/x;
        pk = pkm1;
        pkm1 = pkm2;
        r = r-2.0;
        k = k-1;
    }
    while(k!=0);
    if( ae_fp_greater(ae_fabs(pk, _state),ae_fabs(pkm1, _state)) )
    {
        ans = besselj1(x, _state)/pk;
    }
    else
    {
        ans = besselj0(x, _state)/pkm1;
    }
    result = sg*ans;
    return result;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rsi, %rbx
movl %edi, %eax
andl $0x1, %eax
negq %rax
orq $0x1, %rax
movq %rdi, %r15
negq %r15
cmovsq %rdi, %r15
testq %rdi, %rdi
movl $0x1, %r14d
cmovsq %rax, %r14
xorpd %xmm1, %xmm1
movaps %xmm0, (%rsp)
callq 0x262fe
testb %al, %al
je 0x7cfb
movq %r14, %rax
negq %rax
testb $0x1, %r15b
cmovneq %rax, %r14
movapd (%rsp), %xmm0
xorpd 0x2c4e7(%rip), %xmm0    # 0x341e0
jmp 0x7d00
movapd (%rsp), %xmm0
cmpq $0x2, %r15
je 0x7d58
cmpq $0x1, %r15
je 0x7d2c
testq %r15, %r15
jne 0x7dba
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd %xmm1, (%rsp)
movq %rbx, %rdi
callq 0x7730
jmp 0x7d41
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd %xmm1, (%rsp)
movq %rbx, %rdi
callq 0x79b6
movapd %xmm0, %xmm1
mulsd (%rsp), %xmm1
movapd %xmm1, %xmm0
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
retq
xorpd %xmm1, %xmm1
movapd %xmm0, (%rsp)
callq 0x262ba
xorpd %xmm1, %xmm1
testb %al, %al
jne 0x7d4a
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x18(%rsp)
movapd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x79b6
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
movapd (%rsp), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movq %rbx, %rdi
callq 0x7730
movsd 0x20(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x18(%rsp), %xmm1
jmp 0x7d4a
movsd 0x2cb5e(%rip), %xmm1    # 0x34920
movapd %xmm0, (%rsp)
callq 0x262fe
xorpd %xmm1, %xmm1
testb %al, %al
jne 0x7d4a
leaq 0x6a(,%r15,2), %rax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movapd (%rsp), %xmm5
movapd %xmm5, %xmm2
mulsd %xmm5, %xmm2
movq $-0x35, %rax
movsd 0x2c5ec(%rip), %xmm6    # 0x343f0
movapd %xmm1, %xmm3
movapd %xmm2, %xmm4
divsd %xmm3, %xmm4
addsd %xmm6, %xmm1
movapd %xmm1, %xmm3
subsd %xmm4, %xmm3
incq %rax
jne 0x7e08
movapd %xmm5, %xmm1
divsd %xmm3, %xmm1
movsd 0x2c36f(%rip), %xmm0    # 0x341a0
movapd %xmm0, %xmm3
divsd %xmm1, %xmm3
leaq -0x2(,%r15,2), %rax
decq %r15
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movapd %xmm0, %xmm2
movapd %xmm3, %xmm0
mulsd %xmm5, %xmm2
mulsd %xmm1, %xmm3
subsd %xmm2, %xmm3
divsd %xmm5, %xmm3
addsd %xmm6, %xmm1
decq %r15
jne 0x7e4c
movsd %xmm0, 0x28(%rsp)
movq %rbx, %rdi
movsd %xmm3, 0x18(%rsp)
callq 0x26575
movsd %xmm0, 0x20(%rsp)
movsd 0x18(%rsp), %xmm0
movq %rbx, %rdi
callq 0x26575
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
callq 0x2633e
testb %al, %al
je 0x7ebc
movapd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x79b6
divsd 0x28(%rsp), %xmm0
jmp 0x7ecf
movapd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x7730
divsd 0x18(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
mulsd %xmm0, %xmm1
jmp 0x7d4a