// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %rdi, %rbx
movapd %xmm1, %xmm2
movaps %xmm0, 0x20(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm2, 0x40(%rsp)
movapd %xmm2, %xmm0
callq 0x241f5
testb %al, %al
je 0xd9a7
movapd 0x20(%rsp), %xmm0
jmp 0xddb1
movapd 0x20(%rsp), %xmm0
divsd 0x23b8b(%rip), %xmm0    # 0x31540
movq %rbx, %rdi
callq 0x24468
movl %eax, %ecx
andl $0x1, %ecx
addq %rax, %rcx
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x48(%rsp)
movapd %xmm0, %xmm1
mulsd 0x23b64(%rip), %xmm1    # 0x31540
movapd 0x20(%rsp), %xmm0
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
movapd %xmm0, 0x20(%rsp)
callq 0x24239
movl %eax, %ebp
testb %al, %al
je 0xda0f
movapd 0x20(%rsp), %xmm0
xorpd 0x227a7(%rip), %xmm0    # 0x301b0
movapd %xmm0, 0x20(%rsp)
movsd 0x227e1(%rip), %xmm1    # 0x301f8
movsd 0x40(%rsp), %xmm0
subsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movq %rbx, %rdi
callq 0xd706
movapd %xmm0, 0x60(%rsp)
xorpd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
callq 0x241f5
testb %al, %al
je 0xda80
movapd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2452d
testb %bpl, %bpl
je 0xda63
xorpd 0x2274d(%rip), %xmm0    # 0x301b0
movapd 0x60(%rsp), %xmm2
movsd 0x48(%rsp), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0xddb1
movaps 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24537
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24424
movsd %xmm0, 0x30(%rsp)
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2440c
movsd 0x22ab3(%rip), %xmm1    # 0x30570
callq 0x24279
testb %al, %al
je 0xdb8f
movsd 0x8(%rsp), %xmm1
mulsd 0x30(%rsp), %xmm1
movsd 0x2271a(%rip), %xmm0    # 0x301f8
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
callq 0x2440c
movsd 0x22a78(%rip), %xmm1    # 0x30570
callq 0x24239
testb %al, %al
je 0xdb8f
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24555
movsd %xmm0, 0x10(%rsp)
movapd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2452d
mulsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2452d
mulsd 0x30(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
movapd %xmm0, 0x30(%rsp)
movsd 0x10(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movq %rbx, %rdi
callq 0xd96c
movapd 0x30(%rsp), %xmm1
subsd %xmm0, %xmm1
testb %bpl, %bpl
je 0xdb7e
xorpd 0x22632(%rip), %xmm1    # 0x301b0
movsd 0x48(%rsp), %xmm0
mulsd 0x60(%rsp), %xmm0
jmp 0xddad
movsd 0x40(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24424
movapd %xmm0, %xmm2
pushq $0x1
popq %r15
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
xorl %r14d, %r14d
movsd 0x2263e(%rip), %xmm0    # 0x301f8
movapd %xmm0, 0x10(%rsp)
divsd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm0
movq %rbx, %rdi
callq 0x2440c
movsd 0x22c16(%rip), %xmm1    # 0x307f0
callq 0x24279
testb %al, %al
je 0xdd1f
movsd 0x30(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movq %rbx, %rdi
callq 0x24555
movapd 0x20(%rsp), %xmm2
addsd %xmm0, %xmm2
cvtsi2sd %r14, %xmm0
movsd 0x2286c(%rip), %xmm1    # 0x30490
mulsd %xmm1, %xmm0
addsd %xmm0, %xmm2
movapd %xmm2, 0x20(%rsp)
movapd %xmm2, %xmm0
addsd 0x23902(%rip), %xmm0    # 0x31540
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x24475
movq %rax, %r14
movsd 0x225a3(%rip), %xmm0    # 0x301f8
movsd 0x58(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm3
mulsd %xmm3, %xmm1
movsd 0x50(%rsp), %xmm2
mulsd %xmm3, %xmm2
subsd %xmm2, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x58(%rsp)
movapd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm3
movsd 0x30(%rsp), %xmm1
subsd %xmm1, %xmm3
movsd 0x227eb(%rip), %xmm0    # 0x30488
mulsd %xmm0, %xmm3
movsd %xmm3, 0x50(%rsp)
movapd %xmm2, %xmm0
mulsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x24424
movsd %xmm0, 0x8(%rsp)
movapd 0x10(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
mulsd 0x227b7(%rip), %xmm0    # 0x30488
movapd %xmm0, 0x10(%rsp)
addq %r15, %r15
movapd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2452d
movsd 0x50(%rsp), %xmm2
mulsd %xmm2, %xmm0
movapd 0x70(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, 0x70(%rsp)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0xdbc0
movsd 0x40(%rsp), %xmm0
movq %rbx, %rdi
callq 0xcf84
movaps %xmm0, 0x30(%rsp)
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24555
cvtsi2sd %r14, %xmm1
mulsd 0x22743(%rip), %xmm1    # 0x30490
addsd %xmm0, %xmm1
cvtsi2sd %r15, %xmm0
movapd 0x10(%rsp), %xmm3
mulsd %xmm0, %xmm3
movapd 0x60(%rsp), %xmm2
movapd %xmm2, %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movapd 0x30(%rsp), %xmm1
unpcklpd %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0]
divpd %xmm1, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
mulsd %xmm0, %xmm1
movapd 0x70(%rsp), %xmm0
addsd %xmm1, %xmm0
movapd %xmm0, %xmm1
testb %bpl, %bpl
je 0xdda3
xorpd 0x2240d(%rip), %xmm1    # 0x301b0
movsd 0x48(%rsp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addq $0x88, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq