#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*/ ApproximatelyEqual(double, double);
double Sqrt(double);
int /*<<< orphan*/ printf(char *, ...);
double sqrt(double);
void TestSqrt(double x) {
  double computed, actual;
  computed = Sqrt(x);
  actual = sqrt(x);
  printf("Sqrt(%g) = %g  sqrt(%g) = %g\n", x, computed, x, actual);
  if (!ApproximatelyEqual(computed, actual)) {
    printf("Warning! Computed value does not match actual!\n");
  }
}


x86 assembly (clang, -O0):
<TestSqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <Sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm3
lea    0xe7a(%rip),%rdi
mov    $0x4,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1040 <ApproximatelyEqual@plt>
cmp    $0x0,%eax
jne    11b3 <TestSqrt+0x73>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TestSqrt>:
sub    $0x18,%rsp
movsd  %xmm0,(%rsp)
call   1060 <Sqrt@plt>
movsd  (%rsp),%xmm2
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
movsd  %xmm1,0x8(%rsp)
jb     117d <TestSqrt+0x2d>
sqrtsd %xmm2,%xmm3
jmp    1195 <TestSqrt+0x45>
movapd %xmm2,%xmm0
call   1070 <sqrt@plt>
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm3
lea    0xe64(%rip),%rdi
movapd %xmm2,%xmm0
movsd  %xmm3,0x10(%rsp)
mov    $0x4,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1050 <ApproximatelyEqual@plt>
test   %eax,%eax
je     11c7 <TestSqrt+0x77>
add    $0x18,%rsp
ret
lea    0xe50(%rip),%rdi
add    $0x18,%rsp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Sqrt(%g) = %g sqrt(%g) = %g\0A\00"
@.str.1 = [48 x i8] c"Warning! Computed value does not match actual!\0A\00"
define void @TestSqrt(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %2
%5 = load double, double* %2
%6 = call double @Sqrt(double %5)
store double %6, double* %3
%7 = load double, double* %2
%8 = call double @sqrt(double %7)
store double %8, double* %4
%9 = load double, double* %2
%10 = load double, double* %3
%11 = load double, double* %2
%12 = load double, double* %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), double %9, double %10, double %11, double %12)
%14 = load double, double* %3
%15 = load double, double* %4
%16 = call i32 @ApproximatelyEqual(double %14, double %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %1
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %1
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"Sqrt(%g) = %g sqrt(%g) = %g\0A\00"
@str = [47 x i8] c"Warning! Computed value does not match actual!\00"
define void @TestSqrt(double %0) {
%2 = tail call double @Sqrt(double %0)
%3 = tail call double @sqrt(double %0)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), double %0, double %2, double %0, double %3)
%5 = tail call i32 @ApproximatelyEqual(double %2, double %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
ret void
}