// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movq %rdi, -0x20(%rbp)
movsd 0x43887(%rip), %xmm0    # 0x566e8
movsd %xmm0, -0x50(%rbp)
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c3d0
testb $0x1, %al
jne 0x12e79
jmp 0x12e98
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x1334a
movsd 0x42168(%rip), %xmm0    # 0x55008
subsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c3d0
testb $0x1, %al
jne 0x12ebd
jmp 0x12eff
movsd -0x50(%rbp), %xmm1
addsd -0x10(%rbp), %xmm1
movsd 0x42581(%rip), %xmm0    # 0x55450
mulsd %xmm1, %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cbf0
movq -0x20(%rbp), %rdi
callq 0x3cd70
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x1334a
movsd -0x10(%rbp), %xmm0
divsd -0x50(%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 0x12f36
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
je 0x12f8e
movsd 0x420c3(%rip), %xmm0    # 0x55008
subsd -0x28(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x12870
movsd %xmm0, -0x60(%rbp)
movsd -0x10(%rbp), %xmm1
cvtsi2sdq -0x80(%rbp), %xmm0
movsd -0x50(%rbp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0x12f96
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x12fa9
jmp 0x12fd4
movsd -0x10(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x10(%rbp)
movq $-0x1, -0x78(%rbp)
jmp 0x12fdc
movq $0x0, -0x78(%rbp)
movsd -0x28(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c890
movsd %xmm0, -0x30(%rbp)
movsd -0x10(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cbf0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd 0x42510(%rip), %xmm1    # 0x55528
callq 0x3c4c0
testb $0x1, %al
jne 0x13026
jmp 0x1312a
movsd -0x30(%rbp), %xmm1
mulsd -0x58(%rbp), %xmm1
movsd 0x41fd0(%rip), %xmm0    # 0x55008
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd 0x424d1(%rip), %xmm1    # 0x55528
callq 0x3c440
testb $0x1, %al
jne 0x13065
jmp 0x13128
movsd -0x40(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd10
movsd %xmm0, -0x40(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x1309a
movsd 0x41f81(%rip), %xmm0    # 0x55008
subsd -0x28(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x12870
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x40(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
movq -0x20(%rbp), %rdi
callq 0x12e40
movaps %xmm0, %xmm1
movsd -0x90(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
cmpq $0x0, -0x78(%rbp)
jge 0x130f6
movsd -0x48(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm1
cvtsi2sdq -0x80(%rbp), %xmm0
movsd -0x60(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x1334a
jmp 0x1312a
movsd 0x41ed6(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x28(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c890
movsd %xmm0, -0x38(%rbp)
movq $0x1, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movsd -0x38(%rbp), %xmm0
divsd -0x28(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd 0x427a3(%rip), %xmm1    # 0x55918
callq 0x3c4c0
testb $0x1, %al
jne 0x13183
jmp 0x132ba
movsd -0x30(%rbp), %xmm0
divsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x58(%rbp), %xmm0
mulsd -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd10
movsd -0x98(%rbp), %xmm1
addsd %xmm0, %xmm1
cvtsi2sdq -0x70(%rbp), %xmm0
movsd 0x4228c(%rip), %xmm2    # 0x55458
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
addsd -0x50(%rbp), %xmm0
movsd 0x4226d(%rip), %xmm1    # 0x55458
divsd %xmm1, %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c970
movq %rax, -0x70(%rbp)
movsd -0x58(%rbp), %xmm0
movsd 0x41dff(%rip), %xmm1    # 0x55008
addsd -0x48(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd -0x48(%rbp), %xmm1
mulsd -0x58(%rbp), %xmm1
movsd -0x58(%rbp), %xmm2
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm1
movsd 0x41dc4(%rip), %xmm2    # 0x55008
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x28(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
movsd 0x421ed(%rip), %xmm0    # 0x55450
mulsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x28(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c890
movsd %xmm0, -0x48(%rbp)
movsd -0x28(%rbp), %xmm1
addsd -0x30(%rbp), %xmm1
movsd 0x421ba(%rip), %xmm0    # 0x55450
mulsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x68(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x1315a
movsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd10
movaps %xmm0, %xmm1
cvtsi2sdq -0x70(%rbp), %xmm0
movsd 0x4217f(%rip), %xmm2    # 0x55458
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsi2sdq -0x68(%rbp), %xmm1
mulsd -0x28(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
cmpq $0x0, -0x78(%rbp)
jge 0x1331d
movsd -0x48(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm1
cvtsi2sdq -0x80(%rbp), %xmm0
movsd -0x60(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)