// File: /workspace/github_cpp_makefile_star2_O3/mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::incompleteellipticintegralk(double, double, alglib_impl::ae_state*)
double incompleteellipticintegralk(double phi, double m, ae_state *_state)
{
    double a;
    double b;
    double c;
    double e;
    double temp;
    double pio2;
    double t;
    double k;
    ae_int_t d;
    ae_int_t md;
    ae_int_t s;
    ae_int_t npio2;
    double result;


    pio2 = 1.57079632679489661923;
    if( ae_fp_eq(m,0) )
    {
        result = phi;
        return result;
    }
    a = 1-m;
    if( ae_fp_eq(a,0) )
    {
        result = ae_log(ae_tan(0.5*(pio2+phi), _state), _state);
        return result;
    }
    npio2 = ae_ifloor(phi/pio2, _state);
    if( npio2%2!=0 )
    {
        npio2 = npio2+1;
    }
    if( npio2!=0 )
    {
        k = ellipticintegralk(1-a, _state);
        phi = phi-npio2*pio2;
    }
    else
    {
        k = 0;
    }
    if( ae_fp_less(phi,0) )
    {
        phi = -phi;
        s = -1;
    }
    else
    {
        s = 0;
    }
    b = ae_sqrt(a, _state);
    t = ae_tan(phi, _state);
    if( ae_fp_greater(ae_fabs(t, _state),10) )
    {
        e = 1.0/(b*t);
        if( ae_fp_less(ae_fabs(e, _state),10) )
        {
            e = ae_atan(e, _state);
            if( npio2==0 )
            {
                k = ellipticintegralk(1-a, _state);
            }
            temp = k-incompleteellipticintegralk(e, m, _state);
            if( s<0 )
            {
                temp = -temp;
            }
            result = temp+npio2*k;
            return result;
        }
    }
    a = 1.0;
    c = ae_sqrt(m, _state);
    d = 1;
    md = 0;
    while(ae_fp_greater(ae_fabs(c/a, _state),ae_machineepsilon))
    {
        temp = b/a;
        phi = phi+ae_atan(t*temp, _state)+md*ae_pi;
        md = ae_trunc((phi+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;
    }
    temp = (ae_atan(t, _state)+md*ae_pi)/(d*a);
    if( s<0 )
    {
        temp = -temp;
    }
    result = temp+npio2*k;
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
movapd %xmm1, %xmm2
movaps %xmm0, 0x20(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm2, 0x8(%rsp)
movapd %xmm2, %xmm0
callq 0x25b75
testb %al, %al
je 0xdb5f
movapd 0x20(%rsp), %xmm0
jmp 0xdf56
movsd 0x25679(%rip), %xmm2    # 0x331e0
subsd 0x8(%rsp), %xmm2
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm2, 0x18(%rsp)
movapd %xmm2, %xmm0
callq 0x25b75
testb %al, %al
je 0xdbc0
movapd 0x20(%rsp), %xmm0
addsd 0x269a4(%rip), %xmm0    # 0x34540
mulsd 0x258e4(%rip), %xmm0    # 0x33488
movq %rbx, %rdi
callq 0x25f69
movq %rbx, %rdi
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x25f91
movapd 0x20(%rsp), %xmm0
divsd 0x26972(%rip), %xmm0    # 0x34540
movq %rbx, %rdi
callq 0x25e8e
movl %eax, %r15d
andl $0x1, %r15d
addq %rax, %r15
je 0xdc22
movsd 0x2561e(%rip), %xmm0    # 0x33208
addsd 0x18(%rsp), %xmm0
addsd 0x255e8(%rip), %xmm0    # 0x331e0
movq %rbx, %rdi
callq 0xd8e7
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
movsd %xmm0, 0x30(%rsp)
mulsd 0x26932(%rip), %xmm1    # 0x34548
movapd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
jmp 0xdc28
movapd 0x20(%rsp), %xmm0
xorpd %xmm1, %xmm1
movapd %xmm0, 0x20(%rsp)
callq 0x25bb9
movl %eax, %ebp
testb %al, %al
je 0xdc51
movapd 0x20(%rsp), %xmm0
xorpd 0x25565(%rip), %xmm0    # 0x331b0
movapd %xmm0, 0x20(%rsp)
movsd 0x18(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25e48
movsd %xmm0, 0x40(%rsp)
movapd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25f69
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
callq 0x25e30
movsd 0x258e7(%rip), %xmm1    # 0x33570
callq 0x25bf9
testb %al, %al
je 0xdd52
movsd 0x40(%rsp), %xmm1
mulsd 0x10(%rsp), %xmm1
movsd 0x25536(%rip), %xmm0    # 0x331e0
divsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
callq 0x25e30
movsd 0x258ac(%rip), %xmm1    # 0x33570
callq 0x25bb9
testb %al, %al
je 0xdd52
movsd 0x38(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25f87
testq %r15, %r15
jne 0xdd14
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
addsd 0x25510(%rip), %xmm0    # 0x33208
addsd 0x254e0(%rip), %xmm0    # 0x331e0
movq %rbx, %rdi
callq 0xd8e7
movsd %xmm0, 0x30(%rsp)
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %rbx, %rdi
callq 0xdb25
movsd 0x30(%rsp), %xmm2
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
testb %bpl, %bpl
je 0xdd3d
xorpd 0x25473(%rip), %xmm1    # 0x331b0
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
jmp 0xdf56
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25e48
movq %rbx, %rdi
callq 0x25e30
movsd 0x25a80(%rip), %xmm1    # 0x337f0
callq 0x25bf9
movsd 0x25463(%rip), %xmm1    # 0x331e0
testb %al, %al
je 0xdef1
movl $0x1, %r12d
xorl %r14d, %r14d
movsd 0x10(%rsp), %xmm2
movsd 0x40(%rsp), %xmm0
movsd %xmm2, 0x10(%rsp)
movsd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x8(%rsp)
divsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
mulsd %xmm2, %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
callq 0x25f87
addsd 0x20(%rsp), %xmm0
xorps %xmm2, %xmm2
cvtsi2sd %r14, %xmm2
movsd 0x256b2(%rip), %xmm1    # 0x33490
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
movapd %xmm2, 0x20(%rsp)
movapd %xmm2, %xmm0
addsd 0x26748(%rip), %xmm0    # 0x34540
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x25e9b
movq %rax, %r14
movsd 0x253d1(%rip), %xmm0    # 0x331e0
movsd 0x38(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm3
mulsd %xmm3, %xmm1
movsd 0x18(%rsp), %xmm2
mulsd %xmm3, %xmm2
subsd %xmm2, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm2
movsd 0x40(%rsp), %xmm1
subsd %xmm1, %xmm2
movsd 0x25635(%rip), %xmm0    # 0x33488
mulsd %xmm0, %xmm2
movsd %xmm2, 0x38(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x25e48
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd 0x255f3(%rip), %xmm0    # 0x33488
movsd %xmm0, 0x8(%rsp)
addq %r12, %r12
movsd 0x38(%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25e30
movsd 0x25936(%rip), %xmm1    # 0x337f0
callq 0x25bf9
movsd 0x10(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
movsd 0x18(%rsp), %xmm0
testb %al, %al
jne 0xdd9a
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
movapd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
jmp 0xdf05
movapd %xmm1, %xmm0
xorpd %xmm2, %xmm2
movapd %xmm2, 0x40(%rsp)
movsd 0x10(%rsp), %xmm2
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movapd %xmm2, %xmm0
movq %rbx, %rdi
callq 0x25f87
movapd 0x40(%rsp), %xmm2
mulsd 0x25567(%rip), %xmm2    # 0x33490
addsd %xmm0, %xmm2
divsd 0x8(%rsp), %xmm2
testb %bpl, %bpl
je 0xdf40
xorpd 0x25270(%rip), %xmm2    # 0x331b0
movsd 0x30(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
mulsd %xmm1, %xmm0
addsd %xmm2, %xmm0
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq