#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 agm(double, double);
double atan(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double const sqrt(double);
int /*<<< orphan*/ stderr;
double ellipticK(const double rk) {
  double x, y;
  if (rk < 0.0) {
    fprintf(stderr, "Argument rk in ellipticK out of range\n");
    return 1.0;
  }
  x = 1.0 + rk / sqrt(1.0 + rk * rk);
  y = 1.0 / (x * (1.0 + rk * rk));
  return (2.0 * atan(1.0)) / agm(x, y);
}


x86 assembly (clang, -O0):
<ellipticK>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1182 <ellipticK+0x42>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
call   1030 <fprintf@plt>
movsd  0xe90(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    123a <ellipticK+0xfa>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe66(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  -0x30(%rbp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe4c(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm0
movsd  0xe28(%rip),%xmm2
addsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe18(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe07(%rip),%xmm0
call   1040 <atan@plt>
movaps %xmm0,%xmm1
movsd  0xdef(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1050 <agm@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ellipticK>:
sub    $0x18,%rsp
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1174 <ellipticK+0x34>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
call   1030 <fprintf@plt>
movsd  0xe91(%rip),%xmm0
add    $0x18,%rsp
ret
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe7c(%rip),%xmm2
ucomisd %xmm0,%xmm2
jb     1193 <ellipticK+0x53>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
jmp    11b4 <ellipticK+0x74>
movapd %xmm2,%xmm0
movsd  %xmm1,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
call   1060 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe40(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mulsd  %xmm1,%xmm2
movapd %xmm0,%xmm3
divsd  %xmm2,%xmm3
movsd  %xmm3,0x8(%rsp)
call   1040 <atan@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1050 <agm@plt>
movapd %xmm0,%xmm1
movsd  0xe0a(%rip),%xmm0
divsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Argument rk in ellipticK out of range\0A\00"
define double @ellipticK(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
%6 = load double, double* %3
%7 = fcmp olt double %6, 0.000000e+00
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store double 1.000000e+00, double* %2
br label %31
11: ; preds = %1
%12 = load double, double* %3
%13 = load double, double* %3
%14 = load double, double* %3
%15 = call double @llvm.fmuladd.f64(double %13, double %14, double 1.000000e+00)
%16 = call double @sqrt(double %15)
%17 = fdiv double %12, %16
%18 = fadd double 1.000000e+00, %17
store double %18, double* %4
%19 = load double, double* %4
%20 = load double, double* %3
%21 = load double, double* %3
%22 = call double @llvm.fmuladd.f64(double %20, double %21, double 1.000000e+00)
%23 = fmul double %19, %22
%24 = fdiv double 1.000000e+00, %23
store double %24, double* %5
%25 = call double @atan(double 1.000000e+00)
%26 = fmul double 2.000000e+00, %25
%27 = load double, double* %4
%28 = load double, double* %5
%29 = call double @agm(double %27, double %28)
%30 = fdiv double %26, %29
store double %30, double* %2
br label %31
31: ; preds = %11, %8
%32 = load double, double* %2
ret double %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Argument rk in ellipticK out of range\0A\00"
define double @ellipticK(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %16
6: ; preds = %1
%7 = tail call double @llvm.fmuladd.f64(double %0, double %0, double 1.000000e+00)
%8 = tail call double @sqrt(double %7)
%9 = fdiv double %0, %8
%10 = fadd double %9, 1.000000e+00
%11 = fmul double %7, %10
%12 = fdiv double 1.000000e+00, %11
%13 = tail call double @atan(double 1.000000e+00)
%14 = tail call double @agm(double %10, double %12)
%15 = fdiv double 0x3FF921FB54442D18, %14
br label %16
16: ; preds = %6, %3
%17 = phi double [ 1.000000e+00, %3 ], [ %15, %6 ]
ret double %17
}