#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*/ Error(char *, double);
double TSqrt(double);
double Sqrt(double x) {
  double result, correction;
  if (x == 0)
    return (0);
  if (x < 0)
    Error("Sqrt called with negative argument %g", x);
  correction = 1;
  while (x >= 2) {
    x /= 4;
    correction *= 2;
  }
  return (TSqrt(x) * correction);
}


x86 assembly (clang, -O0):
<Sqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1152 <Sqrt+0x32>
jp     1152 <Sqrt+0x32>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d6 <Sqrt+0xb6>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1171 <Sqrt+0x51>
movsd  -0x10(%rbp),%xmm0
lea    0xeac(%rip),%rdi
call   1030 <Error@plt>
movsd  0xe87(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe7d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11c2 <Sqrt+0xa2>
movsd  -0x10(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe55(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    117e <Sqrt+0x5e>
movsd  -0x10(%rbp),%xmm0
call   1040 <TSqrt@plt>
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sqrt>:
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    1131 <Sqrt+0x11>
jp     1131 <Sqrt+0x11>
ret
push   %rax
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jbe    1156 <Sqrt+0x36>
lea    0xed5(%rip),%rdi
movapd %xmm2,%xmm0
movsd  %xmm2,(%rsp)
call   1030 <Error@plt>
movsd  (%rsp),%xmm2
movsd  0xea2(%rip),%xmm3
ucomisd 0xea2(%rip),%xmm2
jb     118e <Sqrt+0x6e>
movsd  0xea0(%rip),%xmm0
movsd  0xe90(%rip),%xmm1
nopl   0x0(%rax,%rax,1)
mulsd  %xmm0,%xmm2
addsd  %xmm3,%xmm3
ucomisd %xmm1,%xmm2
jae    1180 <Sqrt+0x60>
movsd  %xmm3,(%rsp)
movapd %xmm2,%xmm0
call   1040 <TSqrt@plt>
mulsd  (%rsp),%xmm0
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Sqrt called with negative argument %g\00"
define double @Sqrt(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 oeq double %6, 0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %1
store double 0.000000e+00, double* %2
br label %29
9: ; preds = %1
%10 = load double, double* %3
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load double, double* %3
%14 = call i32 @Error(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), double %13)
br label %15
15: ; preds = %12, %9
store double 1.000000e+00, double* %5
br label %16
16: ; preds = %19, %15
%17 = load double, double* %3
%18 = fcmp oge double %17, 2.000000e+00
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load double, double* %3
%21 = fdiv double %20, 4.000000e+00
store double %21, double* %3
%22 = load double, double* %5
%23 = fmul double %22, 2.000000e+00
store double %23, double* %5
br label %16
24: ; preds = %16
%25 = load double, double* %3
%26 = call double @TSqrt(double %25)
%27 = load double, double* %5
%28 = fmul double %26, %27
store double %28, double* %2
br label %29
29: ; preds = %24, %8
%30 = load double, double* %2
ret double %30
}

LLVM IR (-O2):
@.str = [38 x i8] c"Sqrt called with negative argument %g\00"
define double @Sqrt(double %0) {
%2 = fcmp oeq double %0, 0.000000e+00
br i1 %2, label %20, label %3
3: ; preds = %1
%4 = fcmp olt double %0, 0.000000e+00
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @Error(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), double %0)
br label %7
7: ; preds = %5, %3
%8 = fcmp ult double %0, 2.000000e+00
br i1 %8, label %15, label %9
9: ; preds = %7, %9
%10 = phi double [ %13, %9 ], [ 1.000000e+00, %7 ]
%11 = phi double [ %12, %9 ], [ %0, %7 ]
%12 = fmul double %11, 2.500000e-01
%13 = fmul double %10, 2.000000e+00
%14 = fcmp ult double %12, 2.000000e+00
br i1 %14, label %15, label %9
15: ; preds = %9, %7
%16 = phi double [ %0, %7 ], [ %12, %9 ]
%17 = phi double [ 1.000000e+00, %7 ], [ %13, %9 ]
%18 = tail call double @TSqrt(double %16)
%19 = fmul double %17, %18
br label %20
20: ; preds = %1, %15
%21 = phi double [ %19, %15 ], [ 0.000000e+00, %1 ]
ret double %21
}