#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 */
scalar_t__ DBL_EPSILON;
double M_PI;
double cos(double);
scalar_t__ fabs(double);
double sin(double);
double sqrt(double);
double EllipticK(double x) {
  if (0 == x) {
    return 0.5 * M_PI;
  }
  double a = 1;
  double b = cos(x);
  double c = sin(x);
  while (fabs(c) > DBL_EPSILON) {
    double an = 0.5 * a + 0.5 * b;
    double bn = sqrt(a * b);
    c = 0.5 * a - 0.5 * b;
  }
  return 0.5 * M_PI / a;
}


x86 assembly (clang, -O0):
<EllipticK>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    117e <EllipticK+0x3e>
jp     117e <EllipticK+0x3e>
movsd  0xe9f(%rip),%xmm0
mov    0x2e78(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    125e <EllipticK+0x11e>
movsd  0xe7a(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fabs@plt>
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
jle    1241 <EllipticK+0x101>
movsd  -0x18(%rbp),%xmm0
movsd  0xe38(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
movsd  0xe2b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xdfd(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xdd9(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11a9 <EllipticK+0x69>
movsd  0xdbf(%rip),%xmm0
mov    0x2d98(%rip),%rax
mulsd  (%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EllipticK>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1155 <EllipticK+0x15>
jnp    11d8 <EllipticK+0x98>
movsd  %xmm0,0x8(%rsp)
call   1050 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
call   1030 <fabs@plt>
mov    0x2e64(%rip),%rbx
cmp    (%rbx),%rax
jle    11d8 <EllipticK+0x98>
movsd  0xe77(%rip),%xmm1
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
nopl   0x0(%rax)
xorpd  %xmm0,%xmm0
ucomisd (%rsp),%xmm0
ja     11bd <EllipticK+0x7d>
movsd  0x8(%rsp),%xmm0
call   1030 <fabs@plt>
cmp    (%rbx),%rax
jg     11a0 <EllipticK+0x60>
jmp    11d8 <EllipticK+0x98>
movsd  (%rsp),%xmm0
ucomisd 0xe3e(%rip),%xmm0
jae    11ab <EllipticK+0x6b>
movsd  (%rsp),%xmm0
call   1060 <sqrt@plt>
jmp    11ab <EllipticK+0x6b>
mov    0x2e09(%rip),%rax
movsd  (%rax),%xmm0
mulsd  0xe15(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
@DBL_EPSILON = global i64 0
define double @EllipticK(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* %3
%9 = load double, double* %3
%10 = fcmp oeq double 0.000000e+00, %9
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load double, double* @M_PI
%13 = fmul double 5.000000e-01, %12
store double %13, double* %2
br label %43
14: ; preds = %1
store double 1.000000e+00, double* %4
%15 = load double, double* %3
%16 = call double @cos(double %15)
store double %16, double* %5
%17 = load double, double* %3
%18 = call double @sin(double %17)
store double %18, double* %6
br label %19
19: ; preds = %24, %14
%20 = load double, double* %6
%21 = call i64 @fabs(double %20)
%22 = load i64, i64* @DBL_EPSILON
%23 = icmp sgt i64 %21, %22
br i1 %23, label %24, label %38
24: ; preds = %19
%25 = load double, double* %4
%26 = load double, double* %5
%27 = fmul double 5.000000e-01, %26
%28 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %25, double %27)
store double %28, double* %7
%29 = load double, double* %4
%30 = load double, double* %5
%31 = fmul double %29, %30
%32 = call double @sqrt(double %31)
store double %32, double* %8
%33 = load double, double* %4
%34 = load double, double* %5
%35 = fmul double 5.000000e-01, %34
%36 = fneg double %35
%37 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %33, double %36)
store double %37, double* %6
br label %19
38: ; preds = %19
%39 = load double, double* @M_PI
%40 = fmul double 5.000000e-01, %39
%41 = load double, double* %4
%42 = fdiv double %40, %41
store double %42, double* %2
br label %43
43: ; preds = %38, %11
%44 = load double, double* %2
ret double %44
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
@DBL_EPSILON = global i64 0
define double @EllipticK(double %0) {
%2 = fcmp oeq double %0, 0.000000e+00
br i1 %2, label %20, label %3
3: ; preds = %1
%4 = tail call double @cos(double %0)
%5 = tail call double @sin(double %0)
%6 = tail call i64 @fabs(double %5)
%7 = load i64, i64* @DBL_EPSILON
%8 = icmp sgt i64 %6, %7
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = fcmp olt double %4, 0.000000e+00
%11 = fmul double %4, 5.000000e-01
%12 = fsub double 5.000000e-01, %11
br label %13
13: ; preds = %9, %16
br i1 %10, label %14, label %16
14: ; preds = %13
%15 = tail call double @sqrt(double %4)
br label %16
16: ; preds = %13, %14
%17 = tail call i64 @fabs(double %12)
%18 = load i64, i64* @DBL_EPSILON
%19 = icmp sgt i64 %17, %18
br i1 %19, label %13, label %20
20: ; preds = %16, %3, %1
%21 = load double, double* @M_PI
%22 = fmul double %21, 5.000000e-01
ret double %22
}