// File: /workspace/github_cpp_makefile_star2_O2/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 0x241f5
testb %al, %al
je 0xd2c5
movapd 0x20(%rsp), %xmm0
jmp 0xd643
movsd 0x22f2b(%rip), %xmm2    # 0x301f8
subsd 0x8(%rsp), %xmm2
xorpd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm2, 0x10(%rsp)
movapd %xmm2, %xmm0
callq 0x241f5
testb %al, %al
je 0xd326
movapd 0x20(%rsp), %xmm0
addsd 0x2423e(%rip), %xmm0    # 0x31540
mulsd 0x2317e(%rip), %xmm0    # 0x30488
movq %rbx, %rdi
callq 0x24537
movq %rbx, %rdi
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2455f
movapd 0x20(%rsp), %xmm0
divsd 0x2420c(%rip), %xmm0    # 0x31540
movq %rbx, %rdi
callq 0x24468
movl %eax, %r15d
andl $0x1, %r15d
addq %rax, %r15
je 0xd37d
movsd 0x22ea8(%rip), %xmm0    # 0x301f8
subsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0xcf84
cvtsi2sd %r15, %xmm1
movsd %xmm0, 0x38(%rsp)
mulsd 0x241d7(%rip), %xmm1    # 0x31548
movapd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
jmp 0xd383
movapd 0x20(%rsp), %xmm0
xorpd %xmm1, %xmm1
movapd %xmm0, 0x20(%rsp)
callq 0x24239
movl %eax, %ebp
testb %al, %al
je 0xd3ac
movapd 0x20(%rsp), %xmm0
xorpd 0x22e0a(%rip), %xmm0    # 0x301b0
movapd %xmm0, 0x20(%rsp)
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24424
movsd %xmm0, 0x18(%rsp)
movapd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24537
movsd %xmm0, 0x48(%rsp)
movq %rbx, %rdi
callq 0x2440c
movsd 0x2318c(%rip), %xmm1    # 0x30570
callq 0x24279
testb %al, %al
je 0xd499
movsd 0x18(%rsp), %xmm0
mulsd 0x48(%rsp), %xmm0
movsd 0x22df3(%rip), %xmm1    # 0x301f8
divsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
movapd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x2440c
movsd 0x2314d(%rip), %xmm1    # 0x30570
callq 0x24239
testb %al, %al
je 0xd499
movsd 0x40(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24555
testq %r15, %r15
jne 0xd467
movsd %xmm0, 0x18(%rsp)
movsd 0x22dab(%rip), %xmm0    # 0x301f8
subsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0xcf84
movsd %xmm0, 0x38(%rsp)
movsd 0x18(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %rbx, %rdi
callq 0xd28b
movsd 0x38(%rsp), %xmm2
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
testb %bpl, %bpl
je 0xd636
xorpd 0x22d1c(%rip), %xmm1    # 0x301b0
jmp 0xd636
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24424
movapd %xmm0, %xmm1
pushq $0x1
popq %r12
xorl %r14d, %r14d
movsd 0x22d3e(%rip), %xmm0    # 0x301f8
movsd %xmm0, 0x8(%rsp)
divsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x2440c
movsd 0x23316(%rip), %xmm1    # 0x307f0
callq 0x24279
testb %al, %al
je 0xd5f1
movsd 0x18(%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
mulsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %rbx, %rdi
callq 0x24555
movapd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
cvtsi2sd %r14, %xmm0
movsd 0x22f6c(%rip), %xmm2    # 0x30490
mulsd %xmm2, %xmm0
addsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movapd %xmm1, %xmm0
addsd 0x24002(%rip), %xmm0    # 0x31540
divsd %xmm2, %xmm0
movq %rbx, %rdi
callq 0x24475
movq %rax, %r14
movsd 0x22ca3(%rip), %xmm0    # 0x301f8
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x48(%rsp), %xmm3
mulsd %xmm3, %xmm1
movsd 0x40(%rsp), %xmm2
mulsd %xmm3, %xmm2
subsd %xmm2, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm2
movapd %xmm2, %xmm3
movsd 0x18(%rsp), %xmm1
subsd %xmm1, %xmm3
movsd 0x22eeb(%rip), %xmm0    # 0x30488
mulsd %xmm0, %xmm3
movsd %xmm3, 0x40(%rsp)
movapd %xmm2, %xmm0
mulsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x24424
movsd 0x40(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
addsd 0x18(%rsp), %xmm2
mulsd 0x22eb7(%rip), %xmm2    # 0x30488
movsd %xmm2, 0x8(%rsp)
addq %r12, %r12
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0xd4c0
movsd 0x48(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24555
cvtsi2sd %r14, %xmm1
mulsd 0x22e84(%rip), %xmm1    # 0x30490
cvtsi2sd %r12, %xmm2
addsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm2, %xmm0
divsd %xmm0, %xmm1
testb %bpl, %bpl
je 0xd630
xorpd 0x22b80(%rip), %xmm1    # 0x301b0
movsd 0x38(%rsp), %xmm2
cvtsi2sd %r15, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq