#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 M_SQRT2;
int /*<<< orphan*/ dotest(char *, double, double, double);
int /*<<< orphan*/ printf(char *);
testsqrt() {
  double x, val;
  extern double sqrt();
  printf("testing sqrt ... \n");
  dotest("sqrt(%.1f)", 2.0, sqrt(2.0), M_SQRT2);
  dotest("sqrt(%.1f)", 10.0, sqrt(10.0), 3.16227766016837933199889354443271853);
  for (x = 0.1; x < 0.1e20; x += x) {
    val = sqrt(x);
    dotest("sqrt(%.1f)^2", x, val * val, x);
  }
}


x86 assembly (clang, -O0):
<testsqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xee9(%rip),%rdi
call   1040 <printf@plt>
movsd  0xecc(%rip),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
mov    0x2e85(%rip),%rax
movsd  (%rax),%xmm2
lea    0xed5(%rip),%rdi
movsd  0xeaa(%rip),%xmm0
call   1030 <dotest@plt>
movsd  0xe8d(%rip),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
lea    0xeb1(%rip),%rdi
movsd  0xe76(%rip),%xmm0
movsd  0xe76(%rip),%xmm2
call   1030 <dotest@plt>
movsd  0xe59(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe6c(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1202 <testsqrt+0xd2>
movsd  -0x10(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
lea    0xe5d(%rip),%rdi
call   1030 <dotest@plt>
movsd  -0x10(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11ac <testsqrt+0x7c>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testsqrt>:
push   %rbx
sub    $0x10,%rsp
lea    0xf14(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e98(%rip),%rax
movsd  (%rax),%xmm2
lea    0xee5(%rip),%rbx
movsd  0xea5(%rip),%xmm0
movsd  0xea5(%rip),%xmm1
mov    %rbx,%rdi
call   1040 <dotest@plt>
movsd  0xe9d(%rip),%xmm0
movsd  0xe9d(%rip),%xmm1
mov    %rbx,%rdi
movapd %xmm1,%xmm2
call   1040 <dotest@plt>
movsd  0xe91(%rip),%xmm0
lea    0xead(%rip),%rbx
jmp    11df <testsqrt+0xaf>
nopl   0x0(%rax,%rax,1)
movsd  0x8(%rsp),%xmm0
call   1050 <sqrt@plt>
movapd %xmm0,%xmm1
mulsd  %xmm1,%xmm1
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x8(%rsp),%xmm2
call   1040 <dotest@plt>
movsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe4f(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11f8 <testsqrt+0xc8>
ucomisd 0xe49(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
jb     11a0 <testsqrt+0x70>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    11af <testsqrt+0x7f>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"testing sqrt ... \0A\00"
@.str.1 = [11 x i8] c"sqrt(%.1f)\00"
@M_SQRT2 = global double 0.000000e+00
@.str.2 = [13 x i8] c"sqrt(%.1f)^2\00"
define i32 @testsqrt() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = call double @sqrt(double 2.000000e+00)
%6 = load double, double* @M_SQRT2
%7 = call i32 @dotest(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double 2.000000e+00, double %5, double %6)
%8 = call double @sqrt(double 1.000000e+01)
%9 = call i32 @dotest(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double 1.000000e+01, double %8, double 0x40094C583ADA5B53)
store double 1.000000e-01, double* %2
br label %10
10: ; preds = %22, %0
%11 = load double, double* %2
%12 = fcmp olt double %11, 1.000000e+19
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load double, double* %2
%15 = call double @sqrt(double %14)
store double %15, double* %3
%16 = load double, double* %2
%17 = load double, double* %3
%18 = load double, double* %3
%19 = fmul double %17, %18
%20 = load double, double* %2
%21 = call i32 @dotest(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %16, double %19, double %20)
br label %22
22: ; preds = %13
%23 = load double, double* %2
%24 = load double, double* %2
%25 = fadd double %24, %23
store double %25, double* %2
br label %10
26: ; preds = %10
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"sqrt(%.1f)\00"
@M_SQRT2 = global double 0.000000e+00
@.str.2 = [13 x i8] c"sqrt(%.1f)^2\00"
@str = [18 x i8] c"testing sqrt ... \00"
define i32 @testsqrt() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%2 = load double, double* @M_SQRT2
%3 = tail call i32 @dotest(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double 2.000000e+00, double 0x3FF6A09E667F3BCD, double %2)
%4 = tail call i32 @dotest(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double 1.000000e+01, double 0x40094C583ADA5B53, double 0x40094C583ADA5B53)
br label %5
5: ; preds = %0, %5
%6 = phi double [ 1.000000e-01, %0 ], [ %10, %5 ]
%7 = tail call double @sqrt(double %6)
%8 = fmul double %7, %7
%9 = tail call i32 @dotest(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %6, double %8, double %6)
%10 = fadd double %6, %6
%11 = fcmp olt double %10, 1.000000e+19
br i1 %11, label %5, label %12
12: ; preds = %5
ret i32 undef
}