#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 a) {
  double cx = 1;
  double px = cx;
  double eps = 1e-8;
  while (1) {
    px = cx;
    cx = cx - cx / 2 + a / 2 / cx;
    if (fabs(cx - px) <= eps)
      break;
  }
  return cx;
}


x86 assembly (clang, -O0):
<sqrt>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  0xef7(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xed8(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xec7(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  -0x8(%rbp),%xmm1
movsd  0xeb2(%rip),%xmm2
divsd  %xmm2,%xmm1
divsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movaps 0xe9f(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1199 <sqrt+0x99>
jmp    119e <sqrt+0x9e>
jmp    112d <sqrt+0x2d>
movsd  -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrt>:
mulsd  0xef8(%rip),%xmm0
movsd  0xef8(%rip),%xmm1
movsd  0xef8(%rip),%xmm2
movapd 0xf00(%rip),%xmm3
movsd  0xef0(%rip),%xmm4
nopl   0x0(%rax,%rax,1)
movapd %xmm1,%xmm5
movapd %xmm1,%xmm6
mulsd  %xmm2,%xmm6
addsd  %xmm1,%xmm6
movapd %xmm0,%xmm1
divsd  %xmm5,%xmm1
addsd  %xmm6,%xmm1
movapd %xmm1,%xmm6
subsd  %xmm5,%xmm6
andpd  %xmm3,%xmm6
ucomisd %xmm6,%xmm4
jb     1130 <sqrt+0x30>
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @sqrt(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %2
store double 1.000000e+00, double* %3
%6 = load double, double* %3
store double %6, double* %4
store double 1.000000e-08, double* %5
br label %7
7: ; preds = %1, %25
%8 = load double, double* %3
store double %8, double* %4
%9 = load double, double* %3
%10 = load double, double* %3
%11 = fdiv double %10, 2.000000e+00
%12 = fsub double %9, %11
%13 = load double, double* %2
%14 = fdiv double %13, 2.000000e+00
%15 = load double, double* %3
%16 = fdiv double %14, %15
%17 = fadd double %12, %16
store double %17, double* %3
%18 = load double, double* %3
%19 = load double, double* %4
%20 = fsub double %18, %19
%21 = call double @llvm.fabs.f64(double %20)
%22 = load double, double* %5
%23 = fcmp ole double %21, %22
br i1 %23, label %24, label %25
24: ; preds = %7
br label %26
25: ; preds = %7
br label %7
26: ; preds = %24
%27 = load double, double* %3
ret double %27
}

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