#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 iAbs(float);
float iSqrt(float a) {
  float hi, lo, mid;
  lo = 1;
  hi = a;
  while (iAbs(hi - lo) >= 0.00001) {
    mid = (hi + lo) / 2.0;
    if (mid * mid > a)
      hi = mid;
    else
      lo = mid;
  }
  return mid;
}


x86 assembly (clang, -O0):
<iSqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
movss  0xedb(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
call   1030 <iAbs@plt>
movsd  0xebd(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11aa <iSqrt+0x9a>
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea5(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    119b <iSqrt+0x8b>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11a5 <iSqrt+0x95>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1134 <iSqrt+0x24>
movss  -0x10(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iSqrt>:
sub    $0x38,%rsp
movaps %xmm0,%xmm1
movss  0xee1(%rip),%xmm0
movss  %xmm1,0x8(%rsp)
addss  %xmm1,%xmm0
call   1030 <iAbs@plt>
ucomisd 0xeda(%rip),%xmm0
jae    1142 <iSqrt+0x32>
movaps 0x10(%rsp),%xmm0
add    $0x38,%rsp
ret
movss  0xeba(%rip),%xmm3
movss  0x8(%rsp),%xmm0
jmp    11a2 <iSqrt+0x92>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  %xmm3,0xc(%rsp)
cmpltss %xmm1,%xmm2
movaps %xmm2,%xmm1
movaps %xmm4,0x10(%rsp)
andps  %xmm4,%xmm1
andnps %xmm0,%xmm2
orps   %xmm1,%xmm2
movaps %xmm2,0x20(%rsp)
movaps %xmm2,%xmm0
subss  %xmm3,%xmm0
call   1030 <iAbs@plt>
movss  0xc(%rsp),%xmm3
ucomisd 0xe75(%rip),%xmm0
movaps 0x20(%rsp),%xmm0
jb     1138 <iSqrt+0x28>
movaps %xmm0,%xmm4
addss  %xmm3,%xmm4
mulss  0xe57(%rip),%xmm4
movaps %xmm4,%xmm1
mulss  %xmm4,%xmm1
movss  0x8(%rsp),%xmm2
ucomiss %xmm2,%xmm1
ja     1160 <iSqrt+0x50>
movaps %xmm4,%xmm3
jmp    1160 <iSqrt+0x50>

LLVM IR (-O0):
define float @iSqrt(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
store float %0, float* %2
store float 1.000000e+00, float* %4
%6 = load float, float* %2
store float %6, float* %3
br label %7
7: ; preds = %29, %1
%8 = load float, float* %3
%9 = load float, float* %4
%10 = fsub float %8, %9
%11 = call double @iAbs(float %10)
%12 = fcmp oge double %11, 1.000000e-05
br i1 %12, label %13, label %30
13: ; preds = %7
%14 = load float, float* %3
%15 = load float, float* %4
%16 = fadd float %14, %15
%17 = fpext float %16 to double
%18 = fdiv double %17, 2.000000e+00
%19 = fptrunc double %18 to float
store float %19, float* %5
%20 = load float, float* %5
%21 = load float, float* %5
%22 = fmul float %20, %21
%23 = load float, float* %2
%24 = fcmp ogt float %22, %23
br i1 %24, label %25, label %27
25: ; preds = %13
%26 = load float, float* %5
store float %26, float* %3
br label %29
27: ; preds = %13
%28 = load float, float* %5
store float %28, float* %4
br label %29
29: ; preds = %27, %25
br label %7
30: ; preds = %7
%31 = load float, float* %5
ret float %31
}

LLVM IR (-O2):
define float @iSqrt(float %0) {
%2 = fadd float %0, -1.000000e+00
%3 = tail call double @iAbs(float %2)
%4 = fcmp ult double %3, 1.000000e-05
br i1 %4, label %17, label %5
5: ; preds = %1, %5
%6 = phi float [ %13, %5 ], [ 1.000000e+00, %1 ]
%7 = phi float [ %12, %5 ], [ %0, %1 ]
%8 = fadd float %7, %6
%9 = fmul float %8, 5.000000e-01
%10 = fmul float %9, %9
%11 = fcmp ogt float %10, %0
%12 = select i1 %11, float %9, float %7
%13 = select i1 %11, float %6, float %9
%14 = fsub float %12, %13
%15 = tail call double @iAbs(float %14)
%16 = fcmp ult double %15, 1.000000e-05
br i1 %16, label %17, label %5
17: ; preds = %5, %1
%18 = phi float [ undef, %1 ], [ %9, %5 ]
ret float %18
}