#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
double sqrt(scalar_t__);
scalar_t__ square(double);
int /*<<< orphan*/ stderr;
double x_intercept(double);
double f1(double x, double r) {
  if (x < -1.0) {
    fprintf(stderr, "f1(x) is undefined for x < -1\n");
    exit(EXIT_FAILURE);
  } else if (x < 0.0) {
    return (r / 2.0);
  } else if (x < x_intercept(r)) {
    return (sqrt(square(r) - square(x)) - (r / 2.0));
  } else {
    fprintf(stderr, "f1(x) is undefined for x > %lf\n", x_intercept(r));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<f1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  0xe96(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    119a <f1+0x4a>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11c3 <f1+0x73>
movsd  -0x18(%rbp),%xmm0
movsd  0xe53(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    125e <f1+0x10e>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <x_intercept@plt>
movsd  -0x20(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1229 <f1+0xd9>
movsd  -0x18(%rbp),%xmm0
call   1030 <square@plt>
mov    %rax,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <square@plt>
mov    -0x28(%rbp),%rdi
sub    %rax,%rdi
call   1060 <sqrt@plt>
movsd  -0x18(%rbp),%xmm1
movsd  0xdf1(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    125e <f1+0x10e>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <x_intercept@plt>
mov    -0x2c(%rbp),%edi
lea    0xde6(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f1>:
push   %rbx
sub    $0x10,%rsp
movapd %xmm0,%xmm2
movsd  0xe9f(%rip),%xmm0
ucomisd %xmm2,%xmm0
ja     11d5 <f1+0x85>
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jbe    117b <f1+0x2b>
mulsd  0xe97(%rip),%xmm1
jmp    11cb <f1+0x7b>
movapd %xmm1,%xmm0
movsd  %xmm1,(%rsp)
movsd  %xmm2,0x8(%rsp)
call   1040 <x_intercept@plt>
ucomisd 0x8(%rsp),%xmm0
jbe    11ee <f1+0x9e>
movsd  (%rsp),%xmm0
call   1030 <square@plt>
mov    %rax,%rbx
movsd  0x8(%rsp),%xmm0
call   1030 <square@plt>
sub    %rax,%rbx
mov    %rbx,%rdi
call   1060 <sqrt@plt>
movsd  (%rsp),%xmm1
mulsd  0xe41(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1211 <f1+0xc1>
mov    0x2deb(%rip),%rax
mov    (%rax),%ebx
movsd  (%rsp),%xmm0
call   1040 <x_intercept@plt>
lea    0xe2f(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"f1(x) is undefined for x < -1\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c"f1(x) is undefined for x > %lf\0A\00"
define double @f1(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = fcmp olt double %6, -1.000000e+00
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load double, double* %4
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load double, double* %5
%18 = fdiv double %17, 2.000000e+00
store double %18, double* %3
br label %41
19: ; preds = %13
%20 = load double, double* %4
%21 = load double, double* %5
%22 = call double @x_intercept(double %21)
%23 = fcmp olt double %20, %22
br i1 %23, label %24, label %34
24: ; preds = %19
%25 = load double, double* %5
%26 = call i64 @square(double %25)
%27 = load double, double* %4
%28 = call i64 @square(double %27)
%29 = sub nsw i64 %26, %28
%30 = call double @sqrt(i64 %29)
%31 = load double, double* %5
%32 = fdiv double %31, 2.000000e+00
%33 = fsub double %30, %32
store double %33, double* %3
br label %41
34: ; preds = %19
%35 = load i32, i32* @stderr
%36 = load double, double* %5
%37 = call double @x_intercept(double %36)
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), double %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %24, %16
%42 = load double, double* %3
ret double %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"f1(x) is undefined for x < -1\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c"f1(x) is undefined for x > %lf\0A\00"
define double @f1(double %0, double %1) {
%3 = fcmp olt double %0, -1.000000e+00
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = fcmp olt double %0, 0.000000e+00
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = fmul double %1, 5.000000e-01
br label %29
13: ; preds = %9
%14 = tail call double @x_intercept(double %1)
%15 = fcmp ogt double %14, %0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = tail call i64 @square(double %1)
%18 = tail call i64 @square(double %0)
%19 = sub nsw i64 %17, %18
%20 = tail call double @sqrt(i64 %19)
%21 = fmul double %1, 5.000000e-01
%22 = fsub double %20, %21
br label %29
23: ; preds = %13
%24 = load i32, i32* @stderr
%25 = tail call double @x_intercept(double %1)
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), double %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %16, %11
%30 = phi double [ %12, %11 ], [ %22, %16 ]
ret double %30
}