#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 fabs(double);
double sqrt(double x) {
  double y0, y1, e;
  if (x < 0.0) {
    return (0.0 / 0.0);
  }
  y0 = x;
  y1 = 0.0;
  e = 1.0;
  while (fabs(y0 - y1) > e) {
    y0 = y1;
    y1 = y1 - (y1 * y1 - x) / (2.0 * y1);
    e = 2.2204460492503131e-16 * 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    1129 <sqrt+0x29>
movsd  0xef9(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e0 <sqrt+0xe0>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xebd(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movaps 0xec7(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11d6 <sqrt+0xd6>
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  0xe63(%rip),%xmm2
mulsd  -0x20(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe41(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1148 <sqrt+0x48>
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    1113 <sqrt+0x13>
movsd  0xeee(%rip),%xmm0
ret
movapd 0xf05(%rip),%xmm2
andpd  %xmm0,%xmm2
ucomisd 0xee1(%rip),%xmm2
jbe    1186 <sqrt+0x86>
xorpd  0xeff(%rip),%xmm0
xorpd  %xmm3,%xmm3
movsd  0xed3(%rip),%xmm2
movapd 0xedb(%rip),%xmm4
xorpd  %xmm1,%xmm1
nopl   0x0(%rax)
movapd %xmm3,%xmm5
mulsd  %xmm3,%xmm5
addsd  %xmm0,%xmm5
movapd %xmm3,%xmm6
addsd  %xmm3,%xmm6
divsd  %xmm6,%xmm5
subsd  %xmm5,%xmm1
movapd %xmm1,%xmm5
mulsd  %xmm2,%xmm5
subsd  %xmm1,%xmm3
andpd  %xmm4,%xmm3
ucomisd %xmm5,%xmm3
movapd %xmm1,%xmm3
ja     1150 <sqrt+0x50>
movapd %xmm1,%xmm0
ret

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

LLVM IR (-O2):
define double @sqrt(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
br i1 %2, label %18, 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 %18
6: ; preds = %3
%7 = fneg double %0
br label %8
8: ; preds = %6, %8
%9 = phi double [ 0.000000e+00, %6 ], [ %13, %8 ]
%10 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %7)
%11 = fmul double %9, 2.000000e+00
%12 = fdiv double %10, %11
%13 = fsub double %9, %12
%14 = fmul double %13, 0x3CB0000000000000
%15 = fsub double %9, %13
%16 = tail call double @llvm.fabs.f64(double %15)
%17 = fcmp ogt double %16, %14
br i1 %17, label %8, label %18
18: ; preds = %8, %3, %1
%19 = phi double [ 0x7FF8000000000000, %1 ], [ 0.000000e+00, %3 ], [ %13, %8 ]
ret double %19
}