// File: 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 %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movsd %xmm0, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movsd 0x40200(%rip), %xmm0    # 0x55440
movsd %xmm0, -0xa0(%rbp)
movq -0x20(%rbp), %rdi
movsd 0x402d4(%rip), %xmm0    # 0x55528
movsd 0x4189c(%rip), %xmm1    # 0x56af8
callq 0x3cda0
movaps %xmm0, %xmm1
movsd 0x41884(%rip), %xmm0    # 0x56af0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
cmpq $0x0, -0x18(%rbp)
jl 0x152c0
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x152c0
movsd -0x10(%rbp), %xmm0
movsd 0x41863(%rip), %xmm1    # 0x56b00
callq 0x3c4c0
testb $0x1, %al
jne 0x152c0
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c3d0
testb $0x1, %al
jne 0x152b9
jmp 0x152e2
cmpq $0x2, -0x18(%rbp)
jge 0x152e2
movsd 0x3ff08(%rip), %xmm0    # 0x551d0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x15a03
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c3d0
testb $0x1, %al
jne 0x152f5
jmp 0x15328
movq -0x18(%rbp), %rax
subq $0x1, %rax
cvtsi2sd %rax, %xmm1
movsd 0x3fcfe(%rip), %xmm0    # 0x55008
divsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x15a03
cmpq $0x0, -0x18(%rbp)
jne 0x15373
movsd -0x10(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cdd0
divsd -0x10(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x15a03
cmpq $0x1388, -0x18(%rbp)    # imm = 0x1388
jle 0x154e7
movsd -0x10(%rbp), %xmm0
cvtsi2sdq -0x18(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm1
mulsd -0x40(%rbp), %xmm1
movsd 0x3fc61(%rip), %xmm0    # 0x55008
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
cvtsi2sdq -0x18(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
movsd 0x4109b(%rip), %xmm2    # 0x56468
mulsd -0x10(%rbp), %xmm2
movsd -0x10(%rbp), %xmm3
movsd 0x40241(%rip), %xmm1    # 0x55620
mulsd -0x30(%rbp), %xmm1
mulsd -0x10(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd -0x30(%rbp), %xmm1
movsd -0x30(%rbp), %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x38(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm2
movsd -0x30(%rbp), %xmm1
movsd -0x30(%rbp), %xmm3
movsd -0x10(%rbp), %xmm4
addsd %xmm4, %xmm4
subsd %xmm4, %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x38(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm1
addsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd 0x3fb84(%rip), %xmm0    # 0x55008
addsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x10(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cdd0
movaps %xmm0, %xmm1
movsd -0xb0(%rbp), %xmm0
mulsd %xmm1, %xmm0
divsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x15a03
movsd -0x10(%rbp), %xmm0
movsd 0x3fb14(%rip), %xmm1    # 0x55008
callq 0x3c480
testb $0x1, %al
jne 0x15502
jmp 0x15781
movsd -0xa0(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x10(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd70
movaps %xmm0, %xmm1
movsd -0xb8(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movq $0x1, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jg 0x155a1
movsd -0x78(%rbp), %xmm0
cvtsi2sdq -0x88(%rbp), %xmm2
movsd 0x3fa88(%rip), %xmm1    # 0x55008
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x15556
movsd -0x10(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x80(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x3fa36(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x38(%rbp)
movl $0x1, %eax
subq -0x18(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x48(%rbp)
cmpq $0x1, -0x18(%rbp)
jne 0x155fe
xorps %xmm0, %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0x15613
movsd 0x3fa02(%rip), %xmm0    # 0x55008
divsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0x15615
movsd 0x3f9eb(%rip), %xmm0    # 0x55008
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x38(%rbp), %xmm0
mulsd -0x80(%rbp), %xmm0
divsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x3f9c5(%rip), %xmm0    # 0x55008
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c410
testb $0x1, %al
jne 0x15660
jmp 0x1567e
movsd -0xa8(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
divsd -0x48(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c410
testb $0x1, %al
jne 0x15694
jmp 0x156b1
movsd -0x38(%rbp), %xmm0
divsd -0xa8(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd %xmm0, -0x30(%rbp)
jmp 0x156be
movsd 0x3f94f(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x30(%rbp)
jmp 0x156c0
movsd -0x30(%rbp), %xmm0
movsd 0x4024b(%rip), %xmm1    # 0x55918
callq 0x3c500
testb $0x1, %al
jne 0x15615
movsd 0x3f926(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x30(%rbp)
movq $0x1, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jg 0x15736
movsd -0x30(%rbp), %xmm0
mulsd -0x80(%rbp), %xmm0
cvtsi2sdq -0x88(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x156f2
movsd -0x78(%rbp), %xmm0
movsd -0x30(%rbp), %xmm2
movsd -0xa8(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x15a03
movq $0x1, -0x90(%rbp)
movsd 0x3f874(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x58(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd 0x3f85d(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x50(%rbp)
movsd -0x10(%rbp), %xmm0
cvtsi2sdq -0x18(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x50(%rbp), %xmm0
divsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x1, %rdx
jne 0x15839
movsd 0x3f801(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x38(%rbp)
cvtsi2sdq -0x18(%rbp), %xmm0
movq -0x90(%rbp), %rax
subq $0x1, %rax
cvtsi2sd %rax, %xmm1
movsd 0x3fb9e(%rip), %xmm2    # 0x553c8
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x1585d
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
cvtsi2sdq -0x90(%rbp), %xmm0
movsd 0x3fb74(%rip), %xmm1    # 0x553c8
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x50(%rbp), %xmm0
movsd -0x38(%rbp), %xmm2
movsd -0x58(%rbp), %xmm1
mulsd -0x40(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x68(%rbp), %xmm0
movsd -0x38(%rbp), %xmm2
movsd -0x70(%rbp), %xmm1
mulsd -0x40(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c410
testb $0x1, %al
jne 0x158b2
jmp 0x158f0
movsd -0x48(%rbp), %xmm0
divsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0xa8(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
divsd -0x28(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd %xmm0, -0x30(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0x158fd
movsd 0x3f710(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x30(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd -0x98(%rbp), %xmm1
callq 0x3c4c0
testb $0x1, %al
jne 0x15946
jmp 0x1598e
movsd -0x58(%rbp), %xmm0
divsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x50(%rbp), %xmm0
divsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x70(%rbp), %xmm0
divsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x68(%rbp), %xmm0
divsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x15990
movsd -0x30(%rbp), %xmm0
movsd 0x3ff7b(%rip), %xmm1    # 0x55918
callq 0x3c500
testb $0x1, %al
jne 0x157d6
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0x10(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cdd0
movaps %xmm0, %xmm1
movsd -0xc0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)