// File: /workspace/github_cpp_makefile_star2_O1/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 0x262ba
testb %al, %al
je 0xdc1b
movapd 0x20(%rsp), %xmm0
jmp 0xe012
movsd 0x2657d(%rip), %xmm2    # 0x341a0
subsd 0x8(%rsp), %xmm2
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm2, 0x18(%rsp)
movapd %xmm2, %xmm0
callq 0x262ba
testb %al, %al
je 0xdc7c
movapd 0x20(%rsp), %xmm0
addsd 0x27af0(%rip), %xmm0    # 0x35748
mulsd 0x26808(%rip), %xmm0    # 0x34468
movq %rbx, %rdi
callq 0x266ae
movq %rbx, %rdi
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x266d6
movapd 0x20(%rsp), %xmm0
divsd 0x27abe(%rip), %xmm0    # 0x35748
movq %rbx, %rdi
callq 0x265d3
movl %eax, %r15d
andl $0x1, %r15d
addq %rax, %r15
je 0xdcde
movsd 0x2652a(%rip), %xmm0    # 0x341d0
addsd 0x18(%rsp), %xmm0
addsd 0x264ec(%rip), %xmm0    # 0x341a0
movq %rbx, %rdi
callq 0xd9a3
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
movsd %xmm0, 0x30(%rsp)
mulsd 0x27a7e(%rip), %xmm1    # 0x35750
movapd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
jmp 0xdce4
movapd 0x20(%rsp), %xmm0
xorpd %xmm1, %xmm1
movapd %xmm0, 0x20(%rsp)
callq 0x262fe
movl %eax, %ebp
testb %al, %al
je 0xdd0d
movapd 0x20(%rsp), %xmm0
xorpd 0x264d9(%rip), %xmm0    # 0x341e0
movapd %xmm0, 0x20(%rsp)
movsd 0x18(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2658d
movsd %xmm0, 0x40(%rsp)
movapd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266ae
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
callq 0x26575
movsd 0x26803(%rip), %xmm1    # 0x34548
callq 0x2633e
testb %al, %al
je 0xde0e
movsd 0x40(%rsp), %xmm1
mulsd 0x10(%rsp), %xmm1
movsd 0x2643a(%rip), %xmm0    # 0x341a0
divsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
callq 0x26575
movsd 0x267c8(%rip), %xmm1    # 0x34548
callq 0x262fe
testb %al, %al
je 0xde0e
movsd 0x38(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266cc
testq %r15, %r15
jne 0xddd0
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
addsd 0x2641c(%rip), %xmm0    # 0x341d0
addsd 0x263e4(%rip), %xmm0    # 0x341a0
movq %rbx, %rdi
callq 0xd9a3
movsd %xmm0, 0x30(%rsp)
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %rbx, %rdi
callq 0xdbe1
movsd 0x30(%rsp), %xmm2
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
testb %bpl, %bpl
je 0xddf9
xorpd 0x263e7(%rip), %xmm1    # 0x341e0
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
jmp 0xe012
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2658d
movq %rbx, %rdi
callq 0x26575
movsd 0x26af4(%rip), %xmm1    # 0x34920
callq 0x2633e
movsd 0x26367(%rip), %xmm1    # 0x341a0
testb %al, %al
je 0xdfad
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 0x266cc
addsd 0x20(%rsp), %xmm0
xorps %xmm2, %xmm2
cvtsi2sd %r14, %xmm2
movsd 0x265d6(%rip), %xmm1    # 0x34470
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
movapd %xmm2, 0x20(%rsp)
movapd %xmm2, %xmm0
addsd 0x27894(%rip), %xmm0    # 0x35748
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x265e0
movq %rax, %r14
movsd 0x262d5(%rip), %xmm0    # 0x341a0
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 0x26559(%rip), %xmm0    # 0x34468
mulsd %xmm0, %xmm2
movsd %xmm2, 0x38(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x2658d
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd 0x26517(%rip), %xmm0    # 0x34468
movsd %xmm0, 0x8(%rsp)
addq %r12, %r12
movsd 0x38(%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x26575
movsd 0x269aa(%rip), %xmm1    # 0x34920
callq 0x2633e
movsd 0x10(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
movsd 0x18(%rsp), %xmm0
testb %al, %al
jne 0xde56
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
movapd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
jmp 0xdfc1
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 0x266cc
movapd 0x40(%rsp), %xmm2
mulsd 0x2648b(%rip), %xmm2    # 0x34470
addsd %xmm0, %xmm2
divsd 0x8(%rsp), %xmm2
testb %bpl, %bpl
je 0xdffc
xorpd 0x261e4(%rip), %xmm2    # 0x341e0
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