#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 M_PI;
int fabs(double);
double sqrt(double);
double ell_int(double k) {
  double K, a0, b0, c, a1, b1;
  a0 = 1;
  b0 = sqrt(1 - k * k);
  c = 1;
  while (fabs(c) > 1e-15) {
    a1 = (a0 + b0) / 2;
    b1 = sqrt(a0 * b0);
    c = (a1 - b1) / (a1 + b1);
    a0 = a1;
    b0 = b1;
  }
  K = M_PI / (b1 + a1);
  return K;
}


x86 assembly (clang, -O0):
<ell_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xecb(%rip),%xmm0
movsd  %xmm0,-0x18(%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  0xe99(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xe83(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe70(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1207 <ell_int+0xe7>
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
addsd  -0x38(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1182 <ell_int+0x62>
mov    0x2dda(%rip),%rax
movsd  (%rax),%xmm0
movsd  -0x38(%rbp),%xmm1
addsd  -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ell_int>:
sub    $0x18,%rsp
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0xecc(%rip),%xmm0
subsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1148 <ell_int+0x28>
sqrtsd %xmm0,%xmm0
jmp    114d <ell_int+0x2d>
call   1040 <sqrt@plt>
movsd  %xmm0,(%rsp)
movsd  0xea6(%rip),%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jle    11f7 <ell_int+0xd7>
movsd  0xe91(%rip),%xmm1
movsd  (%rsp),%xmm2
jmp    11c2 <ell_int+0xa2>
cs nopw 0x0(%rax,%rax,1)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
movsd  %xmm2,(%rsp)
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
movapd %xmm1,%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,0x10(%rsp)
divsd  %xmm3,%xmm0
call   1030 <fabs@plt>
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
test   %eax,%eax
jle    11ef <ell_int+0xcf>
movapd %xmm1,%xmm0
addsd  %xmm2,%xmm1
mulsd  0xe36(%rip),%xmm1
mulsd  %xmm2,%xmm0
ucomisd 0xe32(%rip),%xmm0
movsd  %xmm1,0x8(%rsp)
jb     1180 <ell_int+0x60>
xorps  %xmm2,%xmm2
sqrtsd %xmm0,%xmm2
jmp    118f <ell_int+0x6f>
movsd  0x10(%rsp),%xmm1
jmp    11f7 <ell_int+0xd7>
mov    0x2dea(%rip),%rax
movsd  (%rax),%xmm0
divsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @ell_int(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %2
store double 1.000000e+00, double* %4
%9 = load double, double* %2
%10 = load double, double* %2
%11 = fneg double %9
%12 = call double @llvm.fmuladd.f64(double %11, double %10, double 1.000000e+00)
%13 = call double @sqrt(double %12)
store double %13, double* %5
store double 1.000000e+00, double* %6
br label %14
14: ; preds = %19, %1
%15 = load double, double* %6
%16 = call i32 @fabs(double %15)
%17 = sitofp i32 %16 to double
%18 = fcmp ogt double %17, 1.000000e-15
br i1 %18, label %19, label %37
19: ; preds = %14
%20 = load double, double* %4
%21 = load double, double* %5
%22 = fadd double %20, %21
%23 = fdiv double %22, 2.000000e+00
store double %23, double* %7
%24 = load double, double* %4
%25 = load double, double* %5
%26 = fmul double %24, %25
%27 = call double @sqrt(double %26)
store double %27, double* %8
%28 = load double, double* %7
%29 = load double, double* %8
%30 = fsub double %28, %29
%31 = load double, double* %7
%32 = load double, double* %8
%33 = fadd double %31, %32
%34 = fdiv double %30, %33
store double %34, double* %6
%35 = load double, double* %7
store double %35, double* %4
%36 = load double, double* %8
store double %36, double* %5
br label %14
37: ; preds = %14
%38 = load double, double* @M_PI
%39 = load double, double* %8
%40 = load double, double* %7
%41 = fadd double %39, %40
%42 = fdiv double %38, %41
store double %42, double* %3
%43 = load double, double* %3
ret double %43
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @ell_int(double %0) {
%2 = fneg double %0
%3 = tail call double @llvm.fmuladd.f64(double %2, double %0, double 1.000000e+00)
%4 = tail call double @sqrt(double %3)
%5 = tail call i32 @fabs(double 1.000000e+00)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %1, %7
%8 = phi double [ %13, %7 ], [ %4, %1 ]
%9 = phi double [ %11, %7 ], [ 1.000000e+00, %1 ]
%10 = fadd double %9, %8
%11 = fmul double %10, 5.000000e-01
%12 = fmul double %9, %8
%13 = tail call double @sqrt(double %12)
%14 = fsub double %11, %13
%15 = fadd double %11, %13
%16 = fdiv double %14, %15
%17 = tail call i32 @fabs(double %16)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %7, label %19
19: ; preds = %7
%20 = fadd double %11, %13
br label %21
21: ; preds = %1, %19
%22 = phi double [ %20, %19 ], [ undef, %1 ]
%23 = load double, double* @M_PI
%24 = fdiv double %23, %22
ret double %24
}