// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movq %rdi, -0x20(%rbp)
movsd 0x42da7(%rip), %xmm0    # 0x566e8
movsd %xmm0, -0x28(%rbp)
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c3d0
testb $0x1, %al
jne 0x13959
jmp 0x13978
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x13f3d
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
divsd -0x28(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c940
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x139b9
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
movsd -0x58(%rbp), %xmm1
cvtsi2sdq -0x80(%rbp), %xmm0
movsd -0x28(%rbp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x13a00
jmp 0x13a2e
movsd -0x58(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x58(%rbp)
movq $-0x1, -0x88(%rbp)
jmp 0x13a39
movq $0x1, -0x88(%rbp)
movsd 0x415c7(%rip), %xmm0    # 0x55008
subsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x13480
movsd %xmm0, -0x68(%rbp)
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c3d0
testb $0x1, %al
jne 0x13a71
jmp 0x13ae1
movsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cb90
movsd %xmm0, -0x50(%rbp)
cmpq $0x0, -0x88(%rbp)
jge 0x13aaf
movsd -0x50(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm1
cvtsi2sdq -0x80(%rbp), %xmm0
movsd -0x68(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x13f3d
movsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cbf0
movsd %xmm0, -0x60(%rbp)
movsd -0x30(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c890
movsd %xmm0, -0x38(%rbp)
movsd -0x60(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd 0x41a0b(%rip), %xmm1    # 0x55528
callq 0x3c4c0
testb $0x1, %al
jne 0x13b2b
jmp 0x13c73
movsd -0x38(%rbp), %xmm1
mulsd -0x60(%rbp), %xmm1
movsd 0x414cb(%rip), %xmm0    # 0x55008
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd 0x419cc(%rip), %xmm1    # 0x55528
callq 0x3c440
testb $0x1, %al
jne 0x13b6a
jmp 0x13c71
movsd -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd10
movsd %xmm0, -0x48(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cb90
movaps %xmm0, %xmm1
movsd -0xb0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cb90
movsd -0xa8(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0xa0(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x48(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
movq -0x20(%rbp), %rdi
callq 0x13920
movaps %xmm0, %xmm1
movsd -0x98(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
cmpq $0x0, -0x88(%rbp)
jge 0x13c3f
movsd -0x50(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm1
cvtsi2sdq -0x80(%rbp), %xmm0
movsd -0x68(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x13f3d
jmp 0x13c73
movsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c890
movsd %xmm0, -0x40(%rbp)
movsd 0x4137a(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x30(%rbp)
movq $0x1, -0x70(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movq $0x0, -0x78(%rbp)
movsd -0x40(%rbp), %xmm0
divsd -0x30(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd 0x41c52(%rip), %xmm1    # 0x55918
callq 0x3c4c0
testb $0x1, %al
jne 0x13cd4
jmp 0x13e53
movsd -0x38(%rbp), %xmm0
divsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0x60(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd10
movsd -0xc8(%rbp), %xmm1
addsd %xmm0, %xmm1
cvtsi2sdq -0x78(%rbp), %xmm0
movsd 0x4173b(%rip), %xmm2    # 0x55458
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
addsd -0x28(%rbp), %xmm0
movsd 0x4171c(%rip), %xmm1    # 0x55458
divsd %xmm1, %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c970
movq %rax, -0x78(%rbp)
movsd -0x60(%rbp), %xmm0
movsd 0x412ae(%rip), %xmm1    # 0x55008
addsd -0x50(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd -0x50(%rbp), %xmm1
mulsd -0x60(%rbp), %xmm1
movsd -0x60(%rbp), %xmm2
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm1
movsd 0x41273(%rip), %xmm2    # 0x55008
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x30(%rbp), %xmm1
subsd -0x38(%rbp), %xmm1
movsd 0x4169c(%rip), %xmm0    # 0x55450
mulsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c890
movsd %xmm0, -0x50(%rbp)
movsd -0x30(%rbp), %xmm1
addsd -0x38(%rbp), %xmm1
movsd 0x41669(%rip), %xmm0    # 0x55450
mulsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x70(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cb90
movsd -0xc0(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0xb8(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x13cab
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x12870
movaps %xmm0, %xmm1
movsd -0xd8(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0x60(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd10
movaps %xmm0, %xmm2
movsd -0xd0(%rbp), %xmm0
cvtsi2sdq -0x78(%rbp), %xmm1
movsd 0x415a2(%rip), %xmm3    # 0x55458
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
cvtsi2sdq -0x70(%rbp), %xmm2
mulsd -0x30(%rbp), %xmm2
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
cmpq $0x0, -0x88(%rbp)
jge 0x13f10
movsd -0x50(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm1
cvtsi2sdq -0x80(%rbp), %xmm0
movsd -0x68(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax,%rax)