#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(float);
float sqrt(float n) {
  float square, x, old;
  x = 10.0;
  old = 0.0;
  while (fabs(old - x) > 0.000001) {
    old = x;
    x -= (x * x - n) / (2 * x);
  }
  return x;
}


x86 assembly (clang, -O0):
<sqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
movss  0xedb(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
call   1030 <fabs@plt>
movsd  0xebf(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a5 <sqrt+0x95>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
movss  -0x4(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  0xe7b(%rip),%xmm0
mulss  -0xc(%rbp),%xmm0
divss  %xmm0,%xmm1
movss  -0xc(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1132 <sqrt+0x22>
movss  -0xc(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrt>:
sub    $0x28,%rsp
movaps %xmm0,0x10(%rsp)
movss  0xedf(%rip),%xmm0
call   1030 <fabs@plt>
ucomisd 0xeda(%rip),%xmm0
jbe    1190 <sqrt+0x80>
movaps 0x10(%rsp),%xmm0
xorps  0xed4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movss  0xebb(%rip),%xmm0
movaps %xmm0,%xmm3
nopl   0x0(%rax)
movaps %xmm0,%xmm1
mulss  %xmm0,%xmm1
addss  0x10(%rsp),%xmm1
movaps %xmm0,%xmm2
addss  %xmm0,%xmm2
divss  %xmm2,%xmm1
subss  %xmm1,%xmm3
movss  %xmm3,0xc(%rsp)
subss  %xmm3,%xmm0
call   1030 <fabs@plt>
movss  0xc(%rsp),%xmm3
ucomisd 0xe7f(%rip),%xmm0
movaps %xmm3,%xmm0
ja     1150 <sqrt+0x40>
jmp    1198 <sqrt+0x88>
movss  0xe6c(%rip),%xmm3
movaps %xmm3,%xmm0
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
define float @sqrt(float %0) {
%2 = tail call double @fabs(float -1.000000e+01)
%3 = fcmp ogt double %2, 0x3EB0C6F7A0B5ED8D
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = fneg float %0
br label %6
6: ; preds = %4, %6
%7 = phi float [ 1.000000e+01, %4 ], [ %11, %6 ]
%8 = tail call float @llvm.fmuladd.f32(float %7, float %7, float %5)
%9 = fmul float %7, 2.000000e+00
%10 = fdiv float %8, %9
%11 = fsub float %7, %10
%12 = fsub float %7, %11
%13 = tail call double @fabs(float %12)
%14 = fcmp ogt double %13, 0x3EB0C6F7A0B5ED8D
br i1 %14, label %6, label %15
15: ; preds = %6, %1
%16 = phi float [ 1.000000e+01, %1 ], [ %11, %6 ]
ret float %16
}