// File: /workspace/github_cpp_makefile_star2_O1/mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::exponentialintegralen(double, long, alglib_impl::ae_state*)
double exponentialintegralen(double x, ae_int_t n, ae_state *_state)
{
    double r;
    double t;
    double yk;
    double xk;
    double pk;
    double pkm1;
    double pkm2;
    double qk;
    double qkm1;
    double qkm2;
    double psi;
    double z;
    ae_int_t i;
    ae_int_t k;
    double big;
    double eul;
    double result;


    eul = 0.57721566490153286060;
    big = 1.44115188075855872*ae_pow(10, 17, _state);
    if( ((n<0||ae_fp_less(x,0))||ae_fp_greater(x,170))||(ae_fp_eq(x,0)&&n<2) )
    {
        result = -1;
        return result;
    }
    if( ae_fp_eq(x,0) )
    {
        result = (double)1/(double)(n-1);
        return result;
    }
    if( n==0 )
    {
        result = ae_exp(-x, _state)/x;
        return result;
    }
    if( n>5000 )
    {
        xk = x+n;
        yk = 1/(xk*xk);
        t = n;
        result = yk*t*(6*x*x-8*t*x+t*t);
        result = yk*(result+t*(t-2.0*x));
        result = yk*(result+t);
        result = (result+1)*ae_exp(-x, _state)/xk;
        return result;
    }
    if( ae_fp_less_eq(x,1) )
    {
        psi = -eul-ae_log(x, _state);
        for(i=1; i<=n-1; i++)
        {
            psi = psi+(double)1/(double)i;
        }
        z = -x;
        xk = 0;
        yk = 1;
        pk = 1-n;
        if( n==1 )
        {
            result = 0.0;
        }
        else
        {
            result = 1.0/pk;
        }
        do
        {
            xk = xk+1;
            yk = yk*z/xk;
            pk = pk+1;
            if( ae_fp_neq(pk,0) )
            {
                result = result+yk/pk;
            }
            if( ae_fp_neq(result,0) )
            {
                t = ae_fabs(yk/result, _state);
            }
            else
            {
                t = 1;
            }
        }
        while(ae_fp_greater_eq(t,ae_machineepsilon));
        t = 1;
        for(i=1; i<=n-1; i++)
        {
            t = t*z/i;
        }
        result = psi*t-result;
        return result;
    }
    else
    {
        k = 1;
        pkm2 = 1;
        qkm2 = x;
        pkm1 = 1.0;
        qkm1 = x+n;
        result = pkm1/qkm1;
        do
        {
            k = k+1;
            if( k%2==1 )
            {
                yk = 1;
                xk = n+(double)(k-1)/(double)2;
            }
            else
            {
                yk = x;
                xk = (double)k/(double)2;
            }
            pk = pkm1*yk+pkm2*xk;
            qk = qkm1*yk+qkm2*xk;
            if( ae_fp_neq(qk,0) )
            {
                r = pk/qk;
                t = ae_fabs((result-r)/r, _state);
                result = r;
            }
            else
            {
                t = 1;
            }
            pkm2 = pkm1;
            pkm1 = pk;
            qkm2 = qkm1;
            qkm1 = qk;
            if( ae_fp_greater(ae_fabs(pk, _state),big) )
            {
                pkm2 = pkm2/big;
                pkm1 = pkm1/big;
                qkm2 = qkm2/big;
                qkm1 = qkm1/big;
            }
        }
        while(ae_fp_greater_eq(t,ae_machineepsilon));
        result = result*ae_exp(-x, _state);
    }
    return result;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x60, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movaps %xmm0, 0x30(%rsp)
movsd 0x2552d(%rip), %xmm0    # 0x34548
movsd 0x26b35(%rip), %xmm1    # 0x35b58
movq %rsi, %rdi
callq 0x266db
movsd 0x2519d(%rip), %xmm1    # 0x341d0
testq %r14, %r14
js 0xf070
movsd %xmm0, 0x10(%rsp)
xorpd %xmm1, %xmm1
movapd 0x30(%rsp), %xmm0
callq 0x262fe
testb %al, %al
jne 0xf068
movsd 0x26b0f(%rip), %xmm1    # 0x35b68
movapd 0x30(%rsp), %xmm0
callq 0x2633e
testb %al, %al
je 0xf07e
movsd 0x25160(%rip), %xmm1    # 0x341d0
movapd %xmm1, %xmm0
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
retq
xorpd %xmm1, %xmm1
movapd 0x30(%rsp), %xmm0
callq 0x262ba
movq %r14, %r15
subq $0x1, %r15
movsd 0x25134(%rip), %xmm1    # 0x341d0
jg 0xf0a2
testb %al, %al
jne 0xf070
xorpd %xmm1, %xmm1
movaps 0x30(%rsp), %xmm0
callq 0x262ba
testb %al, %al
je 0xf0cd
decq %r14
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
movsd 0x250d9(%rip), %xmm1    # 0x341a0
divsd %xmm0, %xmm1
jmp 0xf070
testq %r14, %r14
je 0xf19f
cmpq $0x1389, %r14           # imm = 0x1389
movapd 0x30(%rsp), %xmm0
jl 0xf1c4
cvtsi2sd %r14, %xmm6
movapd %xmm6, %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, 0x10(%rsp)
mulsd %xmm3, %xmm3
movsd 0x25098(%rip), %xmm1    # 0x341a0
movapd %xmm1, %xmm2
divsd %xmm3, %xmm2
movapd %xmm2, %xmm3
mulsd %xmm6, %xmm3
movsd 0x26398(%rip), %xmm4    # 0x354b8
mulsd %xmm0, %xmm4
movsd 0x26a44(%rip), %xmm5    # 0x35b70
mulsd %xmm6, %xmm5
mulsd %xmm0, %xmm5
mulsd %xmm0, %xmm4
addsd %xmm5, %xmm4
movapd %xmm6, %xmm5
mulsd %xmm6, %xmm5
addsd %xmm4, %xmm5
mulsd %xmm3, %xmm5
movapd %xmm0, %xmm3
addsd %xmm0, %xmm3
movapd %xmm6, %xmm4
subsd %xmm3, %xmm4
mulsd %xmm6, %xmm4
addsd %xmm5, %xmm4
mulsd %xmm2, %xmm4
addsd %xmm6, %xmm4
mulsd %xmm2, %xmm4
addsd %xmm1, %xmm4
movsd %xmm4, 0x8(%rsp)
xorpd 0x2505e(%rip), %xmm0    # 0x341e0
movq %rbx, %rdi
callq 0x266e0
movapd %xmm0, %xmm1
mulsd 0x8(%rsp), %xmm1
divsd 0x10(%rsp), %xmm1
jmp 0xf070
movapd 0x25039(%rip), %xmm0    # 0x341e0
xorpd 0x30(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266e0
movapd %xmm0, %xmm1
divsd 0x30(%rsp), %xmm1
jmp 0xf070
movsd 0x24fd4(%rip), %xmm1    # 0x341a0
callq 0x2631e
testb %al, %al
je 0xf35a
movapd 0x30(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266d6
movsd 0x26279(%rip), %xmm3    # 0x35468
subsd %xmm0, %xmm3
cmpq $0x2, %r14
jl 0xf222
movl $0x1, %eax
movsd 0x24f9a(%rip), %xmm0    # 0x341a0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movapd %xmm0, %xmm2
divsd %xmm1, %xmm2
addsd %xmm2, %xmm3
incq %rax
cmpq %rax, %r14
jne 0xf206
movsd %xmm3, 0x18(%rsp)
negq %r15
movapd 0x30(%rsp), %xmm2
xorpd 0x24fa7(%rip), %xmm2    # 0x341e0
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
movsd 0x24f57(%rip), %xmm3    # 0x341a0
xorpd %xmm4, %xmm4
xorpd %xmm1, %xmm1
cmpq $0x1, %r14
je 0xf25f
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movapd %xmm2, 0x30(%rsp)
movsd 0x24f2d(%rip), %xmm1    # 0x341a0
addsd %xmm1, %xmm4
mulsd %xmm2, %xmm3
movsd %xmm4, 0x20(%rsp)
divsd %xmm4, %xmm3
movsd %xmm3, 0x10(%rsp)
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
xorpd %xmm1, %xmm1
callq 0x262dc
testb %al, %al
jne 0xf2aa
movsd 0x8(%rsp), %xmm0
jmp 0xf2c4
movsd 0x10(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm0, 0x8(%rsp)
callq 0x262dc
movsd 0x24ec5(%rip), %xmm0    # 0x341a0
testb %al, %al
je 0xf2f3
movsd 0x10(%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x26575
movsd 0x25625(%rip), %xmm1    # 0x34920
callq 0x2635a
testb %al, %al
movapd 0x30(%rsp), %xmm2
movsd 0x28(%rsp), %xmm0
movsd 0x10(%rsp), %xmm3
movsd 0x20(%rsp), %xmm4
jne 0xf26b
cmpq $0x2, %r14
jl 0xf549
movl $0x1, %eax
movsd 0x24e69(%rip), %xmm3    # 0x341a0
movsd 0x18(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd %xmm2, %xmm3
divsd %xmm1, %xmm3
incq %rax
cmpq %rax, %r14
jne 0xf33d
jmp 0xf557
movsd 0x10(%rsp), %xmm0
mulsd 0x267f8(%rip), %xmm0    # 0x35b60
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
movsd %xmm0, 0x50(%rsp)
movapd %xmm0, %xmm3
movapd 0x30(%rsp), %xmm1
addsd %xmm1, %xmm3
movsd 0x24e0e(%rip), %xmm2    # 0x341a0
movapd %xmm2, %xmm0
divsd %xmm3, %xmm0
movsd %xmm0, 0x40(%rsp)
movl $0x1, %ecx
movapd %xmm2, %xmm4
movsd %xmm2, 0x18(%rsp)
movsd %xmm1, 0x20(%rsp)
movapd %xmm1, %xmm0
leaq 0x1(%rcx), %r14
testb $0x1, %cl
jne 0xf3de
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x25096(%rip), %xmm1    # 0x34468
addsd 0x50(%rsp), %xmm1
movapd %xmm2, %xmm0
jmp 0xf3ee
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
mulsd 0x2507a(%rip), %xmm1    # 0x34468
movsd 0x20(%rsp), %xmm2
movsd 0x18(%rsp), %xmm5
mulsd %xmm1, %xmm5
movsd %xmm4, 0x18(%rsp)
mulsd %xmm0, %xmm4
addsd %xmm5, %xmm4
movsd %xmm4, 0x8(%rsp)
mulsd %xmm1, %xmm2
movsd %xmm3, 0x20(%rsp)
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm0, 0x28(%rsp)
callq 0x262dc
testb %al, %al
je 0xf473
movsd 0x8(%rsp), %xmm1
divsd 0x28(%rsp), %xmm1
movsd %xmm1, 0x58(%rsp)
movsd 0x40(%rsp), %xmm0
subsd %xmm1, %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x26575
movsd %xmm0, 0x48(%rsp)
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
jmp 0xf481
movsd 0x24d25(%rip), %xmm0    # 0x341a0
movsd %xmm0, 0x48(%rsp)
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x26575
movsd 0x10(%rsp), %xmm1
callq 0x2633e
testb %al, %al
je 0xf4da
movsd 0x18(%rsp), %xmm1
movsd 0x10(%rsp), %xmm3
divsd %xmm3, %xmm1
movsd 0x8(%rsp), %xmm0
divsd %xmm3, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x20(%rsp), %xmm2
divsd %xmm3, %xmm2
movsd 0x28(%rsp), %xmm0
divsd %xmm3, %xmm0
movsd %xmm0, 0x28(%rsp)
jmp 0xf4e6
movsd 0x20(%rsp), %xmm2
movsd 0x18(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
movsd %xmm2, 0x20(%rsp)
movsd %xmm1, 0x18(%rsp)
movsd 0x25420(%rip), %xmm1    # 0x34920
callq 0x2635a
movsd 0x8(%rsp), %xmm4
movsd 0x28(%rsp), %xmm3
movq %r14, %rcx
testb %al, %al
movapd 0x30(%rsp), %xmm0
movsd 0x24c7c(%rip), %xmm2    # 0x341a0
jne 0xf3b9
xorpd 0x24cae(%rip), %xmm0    # 0x341e0
movq %rbx, %rdi
callq 0x266e0
movsd 0x40(%rsp), %xmm1
mulsd %xmm0, %xmm1
jmp 0xf070
movsd 0x24c4f(%rip), %xmm3    # 0x341a0
movsd 0x18(%rsp), %xmm0
mulsd %xmm3, %xmm0
subsd 0x8(%rsp), %xmm0
jmp 0xf074