// File: /workspace/github_cpp_makefile_star2_O1/mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::incompleteellipticintegrale(double, double, alglib_impl::ae_state*)
double incompleteellipticintegrale(double phi, double m, ae_state *_state)
{
    double pio2;
    double a;
    double b;
    double c;
    double e;
    double temp;
    double lphi;
    double t;
    double ebig;
    ae_int_t d;
    ae_int_t md;
    ae_int_t npio2;
    ae_int_t s;
    double result;


    pio2 = 1.57079632679489661923;
    if( ae_fp_eq(m,0) )
    {
        result = phi;
        return result;
    }
    lphi = phi;
    npio2 = ae_ifloor(lphi/pio2, _state);
    if( npio2%2!=0 )
    {
        npio2 = npio2+1;
    }
    lphi = lphi-npio2*pio2;
    if( ae_fp_less(lphi,0) )
    {
        lphi = -lphi;
        s = -1;
    }
    else
    {
        s = 1;
    }
    a = 1.0-m;
    ebig = ellipticintegrale(m, _state);
    if( ae_fp_eq(a,0) )
    {
        temp = ae_sin(lphi, _state);
        if( s<0 )
        {
            temp = -temp;
        }
        result = temp+npio2*ebig;
        return result;
    }
    t = ae_tan(lphi, _state);
    b = ae_sqrt(a, _state);
    
    /*
     * Thanks to Brian Fitzgerald <fitzgb@mml0.meche.rpi.edu>
     * for pointing out an instability near odd multiples of pi/2
     */
    if( ae_fp_greater(ae_fabs(t, _state),10) )
    {
        
        /*
         * Transform the amplitude
         */
        e = 1.0/(b*t);
        
        /*
         * ... but avoid multiple recursions.
         */
        if( ae_fp_less(ae_fabs(e, _state),10) )
        {
            e = ae_atan(e, _state);
            temp = ebig+m*ae_sin(lphi, _state)*ae_sin(e, _state)-incompleteellipticintegrale(e, m, _state);
            if( s<0 )
            {
                temp = -temp;
            }
            result = temp+npio2*ebig;
            return result;
        }
    }
    c = ae_sqrt(m, _state);
    a = 1.0;
    d = 1;
    e = 0.0;
    md = 0;
    while(ae_fp_greater(ae_fabs(c/a, _state),ae_machineepsilon))
    {
        temp = b/a;
        lphi = lphi+ae_atan(t*temp, _state)+md*ae_pi;
        md = ae_trunc((lphi+pio2)/ae_pi, _state);
        t = t*(1.0+temp)/(1.0-temp*t*t);
        c = 0.5*(a-b);
        temp = ae_sqrt(a*b, _state);
        a = 0.5*(a+b);
        b = temp;
        d = d+d;
        e = e+c*ae_sin(lphi, _state);
    }
    temp = ebig/ellipticintegralk(m, _state);
    temp = temp*((ae_atan(t, _state)+md*ae_pi)/(d*a));
    temp = temp+e;
    if( s<0 )
    {
        temp = -temp;
    }
    result = temp+npio2*ebig;
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movapd %xmm1, %xmm2
movaps %xmm0, 0x10(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm2, 0x8(%rsp)
movapd %xmm2, %xmm0
callq 0x262ba
testb %al, %al
je 0xe377
movapd 0x10(%rsp), %xmm0
jmp 0xe795
movapd 0x10(%rsp), %xmm0
divsd 0x273c3(%rip), %xmm0    # 0x35748
movq %rbx, %rdi
callq 0x265d3
movl %eax, %ecx
andl $0x1, %ecx
addq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x38(%rsp)
movapd %xmm0, %xmm1
mulsd 0x27399(%rip), %xmm1    # 0x35748
movapd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
movapd %xmm0, 0x10(%rsp)
callq 0x262fe
movl %eax, %ebp
testb %al, %al
je 0xe3e2
movapd 0x10(%rsp), %xmm0
xorpd 0x25e04(%rip), %xmm0    # 0x341e0
movapd %xmm0, 0x10(%rsp)
movsd 0x25db6(%rip), %xmm1    # 0x341a0
movsd 0x8(%rsp), %xmm0
subsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
movq %rbx, %rdi
callq 0xe0d7
movsd %xmm0, 0x48(%rsp)
xorpd %xmm1, %xmm1
movsd 0x50(%rsp), %xmm0
callq 0x262ba
testb %al, %al
je 0xe44f
movapd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266a4
testb %bpl, %bpl
je 0xe436
xorpd 0x25daa(%rip), %xmm0    # 0x341e0
movsd 0x38(%rsp), %xmm1
mulsd 0x48(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0xe795
movaps 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266ae
movsd %xmm0, 0x28(%rsp)
movsd 0x50(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2658d
movsd %xmm0, 0x30(%rsp)
movsd 0x28(%rsp), %xmm0
movq %rbx, %rdi
callq 0x26575
movsd 0x260bc(%rip), %xmm1    # 0x34548
callq 0x2633e
testb %al, %al
je 0xe541
movsd 0x28(%rsp), %xmm1
mulsd 0x30(%rsp), %xmm1
movsd 0x25cf3(%rip), %xmm0    # 0x341a0
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq %rbx, %rdi
callq 0x26575
movsd 0x26081(%rip), %xmm1    # 0x34548
callq 0x262fe
testb %al, %al
je 0xe541
movsd 0x40(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266cc
movsd %xmm0, 0x28(%rsp)
movapd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266a4
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x28(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266a4
mulsd 0x10(%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movapd %xmm0, 0x10(%rsp)
movsd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %rbx, %rdi
callq 0xe33f
movapd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
jmp 0xe778
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2658d
movq %rbx, %rdi
callq 0x26575
movsd 0x263c1(%rip), %xmm1    # 0x34920
callq 0x2633e
testb %al, %al
je 0xe6ff
movsd 0x25c2c(%rip), %xmm1    # 0x341a0
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movl $0x1, %r15d
xorl %r14d, %r14d
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd %xmm1, 0x8(%rsp)
divsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
mulsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq %rbx, %rdi
callq 0x266cc
addsd 0x10(%rsp), %xmm0
xorps %xmm2, %xmm2
cvtsi2sd %r14, %xmm2
movsd 0x25ea4(%rip), %xmm1    # 0x34470
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
movapd %xmm2, 0x10(%rsp)
movapd %xmm2, %xmm0
addsd 0x27162(%rip), %xmm0    # 0x35748
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x265e0
movq %rax, %r14
movsd 0x25ba3(%rip), %xmm0    # 0x341a0
movsd 0x58(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x28(%rsp), %xmm3
mulsd %xmm3, %xmm1
movsd 0x60(%rsp), %xmm2
mulsd %xmm3, %xmm2
subsd %xmm2, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
movsd 0x8(%rsp), %xmm2
movsd 0x30(%rsp), %xmm1
subsd %xmm1, %xmm2
movsd 0x25e27(%rip), %xmm0    # 0x34468
mulsd %xmm0, %xmm2
movsd %xmm2, 0x58(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x2658d
movsd %xmm0, 0x60(%rsp)
movsd 0x8(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd 0x25de5(%rip), %xmm0    # 0x34468
movsd %xmm0, 0x8(%rsp)
addq %r15, %r15
movapd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266a4
movsd 0x58(%rsp), %xmm2
mulsd %xmm2, %xmm0
movsd 0x40(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
divsd 0x8(%rsp), %xmm2
movapd %xmm2, %xmm0
movq %rbx, %rdi
callq 0x26575
movsd 0x26252(%rip), %xmm1    # 0x34920
callq 0x2633e
movsd 0x8(%rsp), %xmm1
movsd 0x60(%rsp), %xmm0
testb %al, %al
jne 0xe58c
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
movapd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
jmp 0xe71e
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x25a90(%rip), %xmm1    # 0x341a0
movapd %xmm1, %xmm0
xorpd %xmm2, %xmm2
movapd %xmm2, 0x10(%rsp)
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x50(%rsp), %xmm0
movq %rbx, %rdi
callq 0xd9a3
movsd 0x48(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
movsd 0x28(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266cc
movapd 0x10(%rsp), %xmm1
mulsd 0x25d0e(%rip), %xmm1    # 0x34470
addsd %xmm0, %xmm1
divsd 0x8(%rsp), %xmm1
mulsd 0x30(%rsp), %xmm1
addsd 0x40(%rsp), %xmm1
testb %bpl, %bpl
je 0xe785
xorpd 0x25a5b(%rip), %xmm1    # 0x341e0
movsd 0x38(%rsp), %xmm0
mulsd 0x48(%rsp), %xmm0
addsd %xmm1, %xmm0
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq