#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 const abs_v(double);
double sqrt_v(double x) {
  const double epsilon = 0.00001;
  double guess = 1.0;
  while (abs_v(guess * guess - x) >= epsilon) {
    guess = (x / guess + guess) / 2.0;
  }
  return guess;
}


x86 assembly (clang, -O0):
<sqrt_v>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xee3(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xece(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <abs_v@plt>
movsd  0xe96(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11a1 <sqrt_v+0x91>
movsd  -0x8(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe7d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1137 <sqrt_v+0x27>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrt_v>:
sub    $0x38,%rsp
movapd %xmm0,%xmm1
movsd  0xef0(%rip),%xmm0
movapd %xmm0,(%rsp)
movapd %xmm1,0x10(%rsp)
subsd  %xmm1,%xmm0
call   1030 <abs_v@plt>
ucomisd 0xedc(%rip),%xmm0
jb     119d <sqrt_v+0x8d>
movaps 0xebb(%rip),%xmm0
xorps  0x10(%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
movsd  0xeb9(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movapd 0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
mulsd  0xeaa(%rip),%xmm1
movapd %xmm1,(%rsp)
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  0x20(%rsp),%xmm0
call   1030 <abs_v@plt>
ucomisd 0xe82(%rip),%xmm0
movapd (%rsp),%xmm0
jae    1160 <sqrt_v+0x50>
movaps (%rsp),%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @sqrt_v(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %2
store double 1.000000e-05, double* %3
store double 1.000000e+00, double* %4
br label %5
5: ; preds = %13, %1
%6 = load double, double* %4
%7 = load double, double* %4
%8 = load double, double* %2
%9 = fneg double %8
%10 = call double @llvm.fmuladd.f64(double %6, double %7, double %9)
%11 = call double @abs_v(double %10)
%12 = fcmp oge double %11, 1.000000e-05
br i1 %12, label %13, label %20
13: ; preds = %5
%14 = load double, double* %2
%15 = load double, double* %4
%16 = fdiv double %14, %15
%17 = load double, double* %4
%18 = fadd double %16, %17
%19 = fdiv double %18, 2.000000e+00
store double %19, double* %4
br label %5
20: ; preds = %5
%21 = load double, double* %4
ret double %21
}

LLVM IR (-O2):
define double @sqrt_v(double %0) {
%2 = fneg double %0
%3 = fsub double 1.000000e+00, %0
%4 = tail call double @abs_v(double %3)
%5 = fcmp ult double %4, 1.000000e-05
br i1 %5, label %14, label %6
6: ; preds = %1, %6
%7 = phi double [ %10, %6 ], [ 1.000000e+00, %1 ]
%8 = fdiv double %0, %7
%9 = fadd double %7, %8
%10 = fmul double %9, 5.000000e-01
%11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %2)
%12 = tail call double @abs_v(double %11)
%13 = fcmp ult double %12, 1.000000e-05
br i1 %13, label %14, label %6
14: ; preds = %6, %1
%15 = phi double [ 1.000000e+00, %1 ], [ %10, %6 ]
ret double %15
}