#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(int);
double fabs(double);
int /*<<< orphan*/ printf(char *, double);
double sqrt(double);
double sqrt_c(double x) {
  if (x < 0.0) {
    printf("\n\tTried to take sqrt(%2.4e)\n", x);
    exit(1);
  }
  if (fabs(x) < 1.0e-200)
    return 0.0;
  else
    return sqrt(x);
}


x86 assembly (clang, -O0):
<sqrt_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1166 <sqrt_c+0x36>
movsd  -0x10(%rbp),%xmm0
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movsd  -0x10(%rbp),%xmm1
movaps 0xe9e(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe82(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1195 <sqrt_c+0x65>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a4 <sqrt_c+0x74>
movsd  -0x10(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrt_c>:
push   %rax
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1172 <sqrt_c+0x42>
movapd 0xebd(%rip),%xmm2
andpd  %xmm0,%xmm2
movsd  0xec1(%rip),%xmm3
ucomisd %xmm2,%xmm3
ja     1166 <sqrt_c+0x36>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     116c <sqrt_c+0x3c>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret
pop    %rax
jmp    1040 <sqrt@plt>
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"\0A\09Tried to take sqrt(%2.4e)\0A\00"
define double @sqrt_c(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %3
%4 = load double, double* %3
%5 = fcmp olt double %4, 0.000000e+00
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load double, double* %3
%8 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), double %7)
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = load double, double* %3
%12 = call double @llvm.fabs.f64(double %11)
%13 = fcmp olt double %12, 0x16687E92154EF7AC
br i1 %13, label %14, label %15
14: ; preds = %10
store double 0.000000e+00, double* %2
br label %18
15: ; preds = %10
%16 = load double, double* %3
%17 = call double @sqrt(double %16)
store double %17, double* %2
br label %18
18: ; preds = %15, %14
%19 = load double, double* %2
ret double %19
}

LLVM IR (-O2):
@.str = [29 x i8] c"\0A\09Tried to take sqrt(%2.4e)\0A\00"
define double @sqrt_c(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), double %0)
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %1
%7 = tail call double @llvm.fabs.f64(double %0)
%8 = fcmp olt double %7, 0x16687E92154EF7AC
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call double @sqrt(double %0)
br label %11
11: ; preds = %6, %9
%12 = phi double [ %10, %9 ], [ 0.000000e+00, %6 ]
ret double %12
}