// File: /workspace/github_cpp_makefile_star2_O3/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 0x25bb9
testb %al, %al
je 0x7bd9
movq %r14, %rax
negq %rax
testb $0x1, %r15b
cmovneq %rax, %r14
movapd (%rsp), %xmm0
xorpd 0x2b5d9(%rip), %xmm0    # 0x331b0
jmp 0x7bde
movapd (%rsp), %xmm0
cmpq $0x2, %r15
je 0x7c36
cmpq $0x1, %r15
je 0x7c0a
testq %r15, %r15
jne 0x7c98
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd %xmm1, (%rsp)
movq %rbx, %rdi
callq 0x7653
jmp 0x7c1f
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd %xmm1, (%rsp)
movq %rbx, %rdi
callq 0x7894
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 0x25b75
xorpd %xmm1, %xmm1
testb %al, %al
jne 0x7c28
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x18(%rsp)
movapd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x7894
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
movapd (%rsp), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movq %rbx, %rdi
callq 0x7653
movsd 0x20(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x18(%rsp), %xmm1
jmp 0x7c28
movsd 0x2bb50(%rip), %xmm1    # 0x337f0
movapd %xmm0, (%rsp)
callq 0x25bb9
xorpd %xmm1, %xmm1
testb %al, %al
jne 0x7c28
leaq 0x6a(,%r15,2), %rax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movapd (%rsp), %xmm5
movapd %xmm5, %xmm2
mulsd %xmm5, %xmm2
movq $-0x35, %rax
movsd 0x2b72e(%rip), %xmm6    # 0x33410
movapd %xmm1, %xmm3
movapd %xmm2, %xmm4
divsd %xmm3, %xmm4
addsd %xmm6, %xmm1
movapd %xmm1, %xmm3
subsd %xmm4, %xmm3
incq %rax
jne 0x7ce6
movapd %xmm5, %xmm1
divsd %xmm3, %xmm1
movsd 0x2b4d1(%rip), %xmm0    # 0x331e0
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 0x7d2a
movsd %xmm0, 0x28(%rsp)
movq %rbx, %rdi
movsd %xmm3, 0x18(%rsp)
callq 0x25e30
movsd %xmm0, 0x20(%rsp)
movsd 0x18(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25e30
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
callq 0x25bf9
testb %al, %al
je 0x7d9a
movapd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x7894
divsd 0x28(%rsp), %xmm0
jmp 0x7dad
movapd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x7653
divsd 0x18(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
mulsd %xmm0, %xmm1
jmp 0x7c28