#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 DBL_EPSILON;
double NAN;
double fabs(double);
double sqrt(double x) {
  double y0, y1, e;
  if (x < 0.0) {
    return NAN;
  }
  y0 = x;
  y1 = 0.0;
  e = 1.0;
  while (fabs(y0 - y1) > e) {
    y0 = y1;
    y1 = y1 - (y1 * y1 - x) / (2.0 * y1);
    e = DBL_EPSILON * y1;
  }
  return y1;
}


x86 assembly (clang, -O0):
<sqrt>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    112c <sqrt+0x2c>
mov    0x2eda(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e6 <sqrt+0xe6>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xeba(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movaps 0xeb4(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11dc <sqrt+0xdc>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
movsd  0xe58(%rip),%xmm2
mulsd  -0x20(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    0x2e17(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    114b <sqrt+0x4b>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrt>:
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1116 <sqrt+0x16>
mov    0x2ee7(%rip),%rax
movsd  (%rax),%xmm0
ret
movapd 0xee2(%rip),%xmm2
andpd  %xmm0,%xmm2
ucomisd 0xef6(%rip),%xmm2
jbe    1186 <sqrt+0x86>
xorpd  0xedc(%rip),%xmm0
mov    0x2ea5(%rip),%rax
movsd  (%rax),%xmm2
xorpd  %xmm4,%xmm4
movapd 0xeb5(%rip),%xmm3
xorpd  %xmm1,%xmm1
nop
movapd %xmm4,%xmm5
mulsd  %xmm4,%xmm5
addsd  %xmm0,%xmm5
movapd %xmm4,%xmm6
addsd  %xmm4,%xmm6
divsd  %xmm6,%xmm5
subsd  %xmm5,%xmm1
movapd %xmm1,%xmm5
mulsd  %xmm2,%xmm5
subsd  %xmm1,%xmm4
andpd  %xmm3,%xmm4
ucomisd %xmm5,%xmm4
movapd %xmm1,%xmm4
ja     1150 <sqrt+0x50>
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
@NAN = global double 0.000000e+00
@DBL_EPSILON = global double 0.000000e+00
define double @sqrt(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %3
%7 = load double, double* %3
%8 = fcmp olt double %7, 0.000000e+00
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load double, double* @NAN
store double %10, double* %2
br label %37
11: ; preds = %1
%12 = load double, double* %3
store double %12, double* %4
store double 0.000000e+00, double* %5
store double 1.000000e+00, double* %6
br label %13
13: ; preds = %20, %11
%14 = load double, double* %4
%15 = load double, double* %5
%16 = fsub double %14, %15
%17 = call double @llvm.fabs.f64(double %16)
%18 = load double, double* %6
%19 = fcmp ogt double %17, %18
br i1 %19, label %20, label %35
20: ; preds = %13
%21 = load double, double* %5
store double %21, double* %4
%22 = load double, double* %5
%23 = load double, double* %5
%24 = load double, double* %5
%25 = load double, double* %3
%26 = fneg double %25
%27 = call double @llvm.fmuladd.f64(double %23, double %24, double %26)
%28 = load double, double* %5
%29 = fmul double 2.000000e+00, %28
%30 = fdiv double %27, %29
%31 = fsub double %22, %30
store double %31, double* %5
%32 = load double, double* @DBL_EPSILON
%33 = load double, double* %5
%34 = fmul double %32, %33
store double %34, double* %6
br label %13
35: ; preds = %13
%36 = load double, double* %5
store double %36, double* %2
br label %37
37: ; preds = %35, %9
%38 = load double, double* %2
ret double %38
}

LLVM IR (-O2):
@NAN = global double 0.000000e+00
@DBL_EPSILON = global double 0.000000e+00
define double @sqrt(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = tail call double @llvm.fabs.f64(double %0)
%5 = fcmp ogt double %4, 1.000000e+00
br i1 %5, label %6, label %21
6: ; preds = %3
%7 = fneg double %0
%8 = load double, double* @DBL_EPSILON
br label %11
9: ; preds = %1
%10 = load double, double* @NAN
br label %21
11: ; preds = %6, %11
%12 = phi double [ 0.000000e+00, %6 ], [ %16, %11 ]
%13 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %7)
%14 = fmul double %12, 2.000000e+00
%15 = fdiv double %13, %14
%16 = fsub double %12, %15
%17 = fmul double %16, %8
%18 = fsub double %12, %16
%19 = tail call double @llvm.fabs.f64(double %18)
%20 = fcmp ogt double %19, %17
br i1 %20, label %11, label %21
21: ; preds = %11, %3, %9
%22 = phi double [ %10, %9 ], [ 0.000000e+00, %3 ], [ %16, %11 ]
ret double %22
}