// File: /workspace/github_cpp_makefile_star2_O2/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 $0x90, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movaps %xmm0, (%rsp)
movsd 0x220e5(%rip), %xmm0    # 0x30570
movsd 0x231d5(%rip), %xmm1    # 0x31668
movq %rsi, %rdi
callq 0x24564
movsd 0x21d5d(%rip), %xmm1    # 0x30200
testq %r14, %r14
js 0xe4de
movapd %xmm0, 0x10(%rsp)
xorpd %xmm1, %xmm1
movapd (%rsp), %xmm0
callq 0x24239
testb %al, %al
jne 0xe4d6
movsd 0x231b0(%rip), %xmm1    # 0x31678
movapd (%rsp), %xmm0
callq 0x24279
testb %al, %al
je 0xe4ef
movsd 0x21d22(%rip), %xmm1    # 0x30200
movapd %xmm1, %xmm0
addq $0x90, %rsp
popq %rbx
popq %r14
popq %r15
retq
xorpd %xmm1, %xmm1
movapd (%rsp), %xmm0
callq 0x241f5
movq %r14, %r15
subq $0x1, %r15
movsd 0x21cf4(%rip), %xmm1    # 0x30200
ja 0xe512
testb %al, %al
jne 0xe4de
xorpd %xmm1, %xmm1
movaps (%rsp), %xmm0
callq 0x241f5
testb %al, %al
je 0xe539
decq %r14
cvtsi2sd %r14, %xmm0
movsd 0x21cc5(%rip), %xmm1    # 0x301f8
divsd %xmm0, %xmm1
jmp 0xe4de
testq %r14, %r14
je 0xe60a
cmpq $0x1389, %r14           # imm = 0x1389
movapd (%rsp), %xmm0
jb 0xe62d
cvtsi2sd %r14, %xmm6
movapd %xmm6, %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, 0x20(%rsp)
mulsd %xmm3, %xmm3
movsd 0x21c85(%rip), %xmm1    # 0x301f8
movapd %xmm1, %xmm2
divsd %xmm3, %xmm2
movapd %xmm2, %xmm3
mulsd %xmm6, %xmm3
movsd 0x230f5(%rip), %xmm4    # 0x31680
mulsd %xmm0, %xmm4
movsd 0x230f1(%rip), %xmm5    # 0x31688
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, 0x10(%rsp)
xorpd 0x21bc3(%rip), %xmm0    # 0x301b0
movq %rbx, %rdi
callq 0x24569
movapd %xmm0, %xmm1
mulsd 0x10(%rsp), %xmm1
divsd 0x20(%rsp), %xmm1
jmp 0xe4de
movapd 0x21b9e(%rip), %xmm0    # 0x301b0
xorpd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x24569
movapd %xmm0, %xmm1
divsd (%rsp), %xmm1
jmp 0xe4de
movsd 0x21bc3(%rip), %xmm1    # 0x301f8
callq 0x24259
testb %al, %al
je 0xe681
movapd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x2455f
movsd 0x22c0d(%rip), %xmm2    # 0x31260
subsd %xmm0, %xmm2
pushq $0x1
popq %rax
movsd 0x21b96(%rip), %xmm3    # 0x301f8
cmpq %rax, %r14
je 0xe83e
cvtsi2sd %rax, %xmm0
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
addsd %xmm1, %xmm2
incq %rax
jmp 0xe662
movapd 0x10(%rsp), %xmm1
mulsd 0x22fe1(%rip), %xmm1    # 0x31670
cvtsi2sd %r14, %xmm0
movsd %xmm0, 0x68(%rsp)
movapd (%rsp), %xmm5
addsd %xmm5, %xmm0
movsd 0x21b4d(%rip), %xmm4    # 0x301f8
movapd %xmm4, %xmm2
divsd %xmm0, %xmm2
movapd %xmm2, 0x50(%rsp)
movapd %xmm4, %xmm3
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
movapd %xmm4, %xmm0
unpcklpd %xmm5, %xmm0            # xmm0 = xmm0[0],xmm5[0]
movapd %xmm0, 0x30(%rsp)
movapd %xmm1, 0x10(%rsp)
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd %xmm1, 0x70(%rsp)
pushq $0x1
popq %rcx
movapd %xmm5, %xmm0
movapd %xmm4, %xmm2
leaq 0x1(%rcx), %r14
testb $0x1, %cl
jne 0xe70c
cvtsi2sd %rcx, %xmm1
mulsd 0x21d88(%rip), %xmm1    # 0x30488
addsd 0x68(%rsp), %xmm1
movapd %xmm2, %xmm0
jmp 0xe719
cvtsi2sd %r14, %xmm1
mulsd 0x21d6f(%rip), %xmm1    # 0x30488
movapd 0x30(%rsp), %xmm2
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm1, %xmm2
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm3, 0x30(%rsp)
mulpd %xmm3, %xmm0
addpd %xmm2, %xmm0
movapd %xmm0, 0x20(%rsp)
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
xorpd %xmm1, %xmm1
movapd %xmm0, 0x40(%rsp)
callq 0x24217
testb %al, %al
je 0xe796
movapd 0x20(%rsp), %xmm1
divsd 0x40(%rsp), %xmm1
movapd %xmm1, 0x80(%rsp)
movapd 0x50(%rsp), %xmm0
subsd %xmm1, %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x2440c
movsd %xmm0, 0x40(%rsp)
movaps 0x80(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
jmp 0xe7a4
movsd 0x21a5a(%rip), %xmm0    # 0x301f8
movsd %xmm0, 0x40(%rsp)
movapd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2440c
movaps 0x10(%rsp), %xmm1
callq 0x24279
testb %al, %al
jne 0xe7c8
movapd 0x30(%rsp), %xmm1
jmp 0xe7e8
movapd 0x70(%rsp), %xmm0
movapd 0x30(%rsp), %xmm1
divpd %xmm0, %xmm1
movapd 0x20(%rsp), %xmm2
divpd %xmm0, %xmm2
movapd %xmm2, 0x20(%rsp)
movsd 0x40(%rsp), %xmm0
movapd %xmm1, 0x30(%rsp)
movsd 0x21ff4(%rip), %xmm1    # 0x307f0
callq 0x24295
movq %r14, %rcx
movapd 0x20(%rsp), %xmm3
testb %al, %al
movapd (%rsp), %xmm0
movsd 0x219df(%rip), %xmm2    # 0x301f8
jne 0xe6ea
xorpd 0x21989(%rip), %xmm0    # 0x301b0
movq %rbx, %rdi
callq 0x24569
movapd 0x50(%rsp), %xmm1
mulsd %xmm0, %xmm1
jmp 0xe4de
movsd %xmm2, 0x50(%rsp)
negq %r15
movapd (%rsp), %xmm2
xorpd 0x2195c(%rip), %xmm2    # 0x301b0
cvtsi2sd %r15, %xmm0
xorpd %xmm4, %xmm4
xorpd %xmm1, %xmm1
cmpq $0x1, %r14
je 0xe86f
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movapd %xmm2, (%rsp)
movsd 0x21976(%rip), %xmm1    # 0x301f8
addsd %xmm1, %xmm4
mulsd %xmm2, %xmm3
movsd %xmm4, 0x40(%rsp)
divsd %xmm4, %xmm3
movsd %xmm3, 0x20(%rsp)
addsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
xorpd %xmm1, %xmm1
callq 0x24217
testb %al, %al
jne 0xe8b9
movsd 0x10(%rsp), %xmm0
jmp 0xe8d3
movsd 0x20(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm0, 0x10(%rsp)
callq 0x24217
movsd 0x2190e(%rip), %xmm0    # 0x301f8
testb %al, %al
je 0xe902
movsd 0x20(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2440c
movsd 0x21ee6(%rip), %xmm1    # 0x307f0
callq 0x24295
testb %al, %al
movapd (%rsp), %xmm2
movsd 0x20(%rsp), %xmm3
movsd 0x30(%rsp), %xmm0
movsd 0x40(%rsp), %xmm4
jne 0xe87a
movsd 0x218c2(%rip), %xmm3    # 0x301f8
pushq $0x1
popq %rax
cmpq %rax, %r14
je 0xe950
mulsd %xmm2, %xmm3
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm3
incq %rax
jmp 0xe939
movsd 0x50(%rsp), %xmm0
mulsd %xmm3, %xmm0
subsd 0x10(%rsp), %xmm0
jmp 0xe4e2