#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double DBL_EPSILON;
int /*<<< orphan*/ memset(double *, int /*<<< orphan*/, int);
double sqrt(double);
int dspl_ellip_landen(double k, double *K) {
  int n = 0;
  memset(K, 0, 48 * sizeof(double));
  while (k > DBL_EPSILON && n < 48) {
    k = k / (1.0 + sqrt(1.0 - k * k));
    k *= k;
    K[n] = k;
    n++;
  }
  if (n >= 48)
    n = -1;
  return n;
}


x86 assembly (clang, -O0):
<dspl_ellip_landen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x180,%edx
call   1030 <memset@plt>
movsd  -0x8(%rbp),%xmm0
xor    %eax,%eax
mov    0x2e92(%rip),%rcx
ucomisd (%rcx),%xmm0
mov    %al,-0x15(%rbp)
jbe    116d <dspl_ellip_landen+0x4d>
cmpl   $0x30,-0x14(%rbp)
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    117d <dspl_ellip_landen+0x5d>
jmp    1209 <dspl_ellip_landen+0xe9>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe4c(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm2
movsd  -0x20(%rbp),%xmm0
movsd  0xe33(%rip),%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <dspl_ellip_landen+0x28>
cmpl   $0x30,-0x14(%rbp)
jl     121a <dspl_ellip_landen+0xfa>
movl   $0xffffffff,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dspl_ellip_landen>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movsd  %xmm0,(%rsp)
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x180,%edx
call   1030 <memset@plt>
movsd  (%rsp),%xmm2
mov    0x2e9e(%rip),%r15
ucomisd (%r15),%xmm2
jbe    11cd <dspl_ellip_landen+0xad>
xor    %ebp,%ebp
movsd  0xea5(%rip),%xmm3
xorpd  %xmm4,%xmm4
nop
movapd %xmm2,%xmm1
mulsd  %xmm2,%xmm1
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
ucomisd %xmm4,%xmm0
jb     1180 <dspl_ellip_landen+0x60>
sqrtsd %xmm0,%xmm0
jmp    119b <dspl_ellip_landen+0x7b>
nopl   0x0(%rax)
movsd  %xmm2,(%rsp)
call   1040 <sqrt@plt>
xorpd  %xmm4,%xmm4
movsd  0xe6a(%rip),%xmm3
movsd  (%rsp),%xmm2
addsd  %xmm3,%xmm0
divsd  %xmm0,%xmm2
mulsd  %xmm2,%xmm2
movsd  %xmm2,(%rbx,%rbp,8)
lea    0x1(%rbp),%rax
ucomisd (%r15),%xmm2
jbe    11c0 <dspl_ellip_landen+0xa0>
cmp    $0x2f,%rbp
mov    %rax,%rbp
jb     1160 <dspl_ellip_landen+0x40>
cmp    $0x30,%eax
mov    $0xffffffff,%r14d
cmovb  %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@DBL_EPSILON = global double 0.000000e+00
define i32 @dspl_ellip_landen(double %0, double* %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca i32
store double %0, double* %3
store double* %1, double** %4
store i32 0, i32* %5
%6 = load double*, double** %4
%7 = call i32 @memset(double* %6, i32 0, i32 384)
br label %8
8: ; preds = %17, %2
%9 = load double, double* %3
%10 = load double, double* @DBL_EPSILON
%11 = fcmp ogt double %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 48
br label %15
15: ; preds = %12, %8
%16 = phi i1 [ false, %8 ], [ %14, %12 ]
br i1 %16, label %17, label %36
17: ; preds = %15
%18 = load double, double* %3
%19 = load double, double* %3
%20 = load double, double* %3
%21 = fneg double %19
%22 = call double @llvm.fmuladd.f64(double %21, double %20, double 1.000000e+00)
%23 = call double @sqrt(double %22)
%24 = fadd double 1.000000e+00, %23
%25 = fdiv double %18, %24
store double %25, double* %3
%26 = load double, double* %3
%27 = load double, double* %3
%28 = fmul double %27, %26
store double %28, double* %3
%29 = load double, double* %3
%30 = load double*, double** %4
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
store double %29, double* %33
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %8
36: ; preds = %15
%37 = load i32, i32* %5
%38 = icmp sge i32 %37, 48
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 -1, i32* %5
br label %40
40: ; preds = %39, %36
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@DBL_EPSILON = global double 0.000000e+00
define i32 @dspl_ellip_landen(double %0, double* %1) {
%3 = tail call i32 @memset(double* %1, i32 0, i32 384)
%4 = load double, double* @DBL_EPSILON
%5 = fcmp olt double %4, %0
br i1 %5, label %6, label %25
6: ; preds = %2, %6
%7 = phi i64 [ %16, %6 ], [ 0, %2 ]
%8 = phi double [ %14, %6 ], [ %0, %2 ]
%9 = fneg double %8
%10 = tail call double @llvm.fmuladd.f64(double %9, double %8, double 1.000000e+00)
%11 = tail call double @sqrt(double %10)
%12 = fadd double %11, 1.000000e+00
%13 = fdiv double %8, %12
%14 = fmul double %13, %13
%15 = getelementptr inbounds double, double* %1, i64 %7
store double %14, double* %15
%16 = add nuw nsw i64 %7, 1
%17 = load double, double* @DBL_EPSILON
%18 = fcmp ogt double %14, %17
%19 = icmp ult i64 %7, 47
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %6, label %21
21: ; preds = %6
%22 = trunc i64 %16 to i32
%23 = icmp ugt i32 %22, 47
%24 = select i1 %23, i32 -1, i32 %22
br label %25
25: ; preds = %21, %2
%26 = phi i32 [ 0, %2 ], [ %24, %21 ]
ret i32 %26
}