// File: /workspace/github_cpp_makefile_star2_O3/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 %r14
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movaps %xmm0, (%rsp)
movsd 0x2479d(%rip), %xmm0    # 0x33570
movsd 0x2588d(%rip), %xmm1    # 0x34668
movq %rsi, %rdi
callq 0x25f96
movsd 0x2441d(%rip), %xmm1    # 0x33208
testq %r14, %r14
js 0xee26
movapd %xmm0, 0x10(%rsp)
xorpd %xmm1, %xmm1
movapd (%rsp), %xmm0
callq 0x25bb9
testb %al, %al
jne 0xee1e
movsd 0x25868(%rip), %xmm1    # 0x34678
movapd (%rsp), %xmm0
callq 0x25bf9
testb %al, %al
je 0xee35
movsd 0x243e2(%rip), %xmm1    # 0x33208
movapd %xmm1, %xmm0
addq $0x98, %rsp
popq %rbx
popq %r14
retq
xorpd %xmm1, %xmm1
movapd (%rsp), %xmm0
callq 0x25b75
cmpq $0x1, %r14
movsd 0x243b9(%rip), %xmm1    # 0x33208
ja 0xee55
testb %al, %al
jne 0xee26
xorpd %xmm1, %xmm1
movaps (%rsp), %xmm0
callq 0x25b75
testb %al, %al
je 0xee7f
decq %r14
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
movsd 0x24367(%rip), %xmm1    # 0x331e0
divsd %xmm0, %xmm1
jmp 0xee26
testq %r14, %r14
je 0xef50
cmpq $0x1389, %r14           # imm = 0x1389
movapd (%rsp), %xmm0
jb 0xef73
cvtsi2sd %r14, %xmm6
movapd %xmm6, %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, 0x20(%rsp)
mulsd %xmm3, %xmm3
movsd 0x24327(%rip), %xmm1    # 0x331e0
movapd %xmm1, %xmm2
divsd %xmm3, %xmm2
movapd %xmm2, %xmm3
mulsd %xmm6, %xmm3
movsd 0x257af(%rip), %xmm4    # 0x34680
mulsd %xmm0, %xmm4
movsd 0x257ab(%rip), %xmm5    # 0x34688
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 0x2427d(%rip), %xmm0    # 0x331b0
movq %rbx, %rdi
callq 0x25f9b
movapd %xmm0, %xmm1
mulsd 0x10(%rsp), %xmm1
divsd 0x20(%rsp), %xmm1
jmp 0xee26
movapd 0x24258(%rip), %xmm0    # 0x331b0
xorpd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x25f9b
movapd %xmm0, %xmm1
divsd (%rsp), %xmm1
jmp 0xee26
movsd 0x24265(%rip), %xmm1    # 0x331e0
callq 0x25bd9
testb %al, %al
je 0xf0eb
movapd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x25f91
movsd 0x252c3(%rip), %xmm3    # 0x34260
subsd %xmm0, %xmm3
movq %r14, %rax
subq $0x1, %rax
je 0xefd3
movl $0x1, %ecx
movsd 0x24229(%rip), %xmm0    # 0x331e0
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
movapd %xmm0, %xmm2
divsd %xmm1, %xmm2
addsd %xmm2, %xmm3
incq %rcx
cmpq %rcx, %r14
jne 0xefb7
movsd %xmm3, 0x50(%rsp)
negq %rax
movapd (%rsp), %xmm2
xorpd 0x241c7(%rip), %xmm2    # 0x331b0
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd 0x241e7(%rip), %xmm3    # 0x331e0
xorpd %xmm4, %xmm4
xorpd %xmm1, %xmm1
cmpq $0x1, %r14
je 0xf00f
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movapd %xmm2, (%rsp)
movsd 0x241be(%rip), %xmm1    # 0x331e0
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 0x25b97
testb %al, %al
jne 0xf059
movsd 0x10(%rsp), %xmm0
jmp 0xf073
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 0x25b97
movsd 0x24156(%rip), %xmm0    # 0x331e0
testb %al, %al
je 0xf0a2
movsd 0x20(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25e30
movsd 0x24746(%rip), %xmm1    # 0x337f0
callq 0x25c15
testb %al, %al
movapd (%rsp), %xmm2
movsd 0x30(%rsp), %xmm0
movsd 0x20(%rsp), %xmm3
movsd 0x40(%rsp), %xmm4
jne 0xf01a
cmpq $0x1, %r14
jne 0xf2b3
movsd 0x24100(%rip), %xmm3    # 0x331e0
movsd 0x50(%rsp), %xmm0
jmp 0xf2de
movapd 0x10(%rsp), %xmm1
mulsd 0x25577(%rip), %xmm1    # 0x34670
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
movsd %xmm0, 0x68(%rsp)
movapd (%rsp), %xmm5
addsd %xmm5, %xmm0
movsd 0x240c8(%rip), %xmm4    # 0x331e0
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)
movl $0x1, %ecx
movapd %xmm5, %xmm0
movapd %xmm4, %xmm2
leaq 0x1(%rcx), %r14
testb $0x1, %cl
jne 0xf17e
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x24316(%rip), %xmm1    # 0x33488
addsd 0x68(%rsp), %xmm1
movapd %xmm2, %xmm0
jmp 0xf18e
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
mulsd 0x242fa(%rip), %xmm1    # 0x33488
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 0x25b97
testb %al, %al
je 0xf20b
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 0x25e30
movsd %xmm0, 0x40(%rsp)
movaps 0x80(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
jmp 0xf219
movsd 0x23fcd(%rip), %xmm0    # 0x331e0
movsd %xmm0, 0x40(%rsp)
movapd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25e30
movaps 0x10(%rsp), %xmm1
callq 0x25bf9
testb %al, %al
jne 0xf23d
movapd 0x30(%rsp), %xmm1
jmp 0xf25d
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 0x2457f(%rip), %xmm1    # 0x337f0
callq 0x25c15
movq %r14, %rcx
movapd 0x20(%rsp), %xmm3
testb %al, %al
movapd (%rsp), %xmm0
movsd 0x23f52(%rip), %xmm2    # 0x331e0
jne 0xf159
xorpd 0x23f14(%rip), %xmm0    # 0x331b0
movq %rbx, %rdi
callq 0x25f9b
movapd 0x50(%rsp), %xmm1
mulsd %xmm0, %xmm1
jmp 0xee26
movl $0x1, %eax
movsd 0x23f20(%rip), %xmm3    # 0x331e0
movsd 0x50(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd %xmm2, %xmm3
divsd %xmm1, %xmm3
incq %rax
cmpq %rax, %r14
jne 0xf2c6
mulsd %xmm3, %xmm0
subsd 0x10(%rsp), %xmm0
jmp 0xee2a