#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 */
float sqrt() {
  float x = 2;
  float l = 0, r = x + 1, m;
  while (r - l > 0.00001) {
    m = (l + r) / 2;
    if (m * m < x)
      l = m;
    else
      r = m;
  }
  return (l + r) / 2;
}


x86 assembly (clang, -O0):
<sqrt>:
push   %rbp
mov    %rsp,%rbp
movss  0xef8(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  0xedf(%rip),%xmm0
addss  -0x4(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xec7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119c <sqrt+0x9c>
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  0xea7(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm1
mulss  -0x10(%rbp),%xmm1
movss  -0x4(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    118d <sqrt+0x8d>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    1197 <sqrt+0x97>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    112b <sqrt+0x2b>
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  0xe56(%rip),%xmm1
divss  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrt>:
movss  0xef8(%rip),%xmm4
xorps  %xmm6,%xmm6
movss  0xef1(%rip),%xmm1
movss  0xeed(%rip),%xmm2
movsd  0xeed(%rip),%xmm3
jmp    1158 <sqrt+0x58>
cs nopw 0x0(%rax,%rax,1)
nop
cmpltss %xmm2,%xmm5
movaps %xmm5,%xmm6
andnps %xmm7,%xmm6
andps  %xmm4,%xmm5
orps   %xmm6,%xmm5
movaps %xmm5,%xmm4
subss  %xmm0,%xmm4
cvtss2sd %xmm4,%xmm4
ucomisd %xmm3,%xmm4
movaps %xmm0,%xmm6
movaps %xmm5,%xmm4
jbe    1177 <sqrt+0x77>
movaps %xmm4,%xmm7
addss  %xmm6,%xmm7
mulss  %xmm1,%xmm7
movaps %xmm7,%xmm5
mulss  %xmm7,%xmm5
ucomiss %xmm5,%xmm2
movaps %xmm7,%xmm0
ja     1130 <sqrt+0x30>
movaps %xmm6,%xmm0
jmp    1130 <sqrt+0x30>
addss  %xmm5,%xmm0
mulss  0xe81(%rip),%xmm0
ret

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

LLVM IR (-O2):
define float @sqrt() {
br label %1
1: ; preds = %0, %1
%2 = phi float [ 0.000000e+00, %0 ], [ %9, %1 ]
%3 = phi float [ 3.000000e+00, %0 ], [ %8, %1 ]
%4 = fadd float %3, %2
%5 = fmul float %4, 5.000000e-01
%6 = fmul float %5, %5
%7 = fcmp olt float %6, 2.000000e+00
%8 = select i1 %7, float %3, float %5
%9 = select i1 %7, float %5, float %2
%10 = fsub float %8, %9
%11 = fpext float %10 to double
%12 = fcmp ogt double %11, 1.000000e-05
br i1 %12, label %1, label %13
13: ; preds = %1
%14 = fadd float %8, %9
%15 = fmul float %14, 5.000000e-01
ret float %15
}