#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 the_middle_of(double, double);
double square_root(double x) {
  double l = 0, r = x;
  double check, m;
  while (1) {
    m = the_middle_of(l, r);
    check = m * m;
    if (check > x + 0.0000000001)
      r = m;
    else if (check < x - 0.0000000001)
      l = m;
    else
      return m;
  }
}


x86 assembly (clang, -O0):
<square_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1030 <the_middle_of@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xea1(%rip),%xmm1
addsd  -0x8(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    117d <square_root+0x6d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11bc <square_root+0xac>
movsd  -0x20(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
movsd  0xe71(%rip),%xmm2
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    11ac <square_root+0x9c>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11b7 <square_root+0xa7>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret
jmp    11bc <square_root+0xac>
jmp    112f <square_root+0x1f>

x86 assembly (clang, -O2):
<square_root>:
sub    $0x28,%rsp
movsd  0xee4(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0xeda(%rip),%xmm1
movsd  %xmm0,0x8(%rsp)
addsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm1,0x18(%rsp)
movapd %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <the_middle_of@plt>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
ucomisd 0x20(%rsp),%xmm1
ja     1187 <square_root+0x77>
movsd  0x10(%rsp),%xmm2
ucomisd %xmm1,%xmm2
movapd %xmm0,%xmm1
ja     1150 <square_root+0x40>
jmp    1195 <square_root+0x85>
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm1
jmp    1150 <square_root+0x40>
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
define double @square_root(double %0) {
%2 = fadd double %0, -1.000000e-10
%3 = fadd double %0, 1.000000e-10
br label %4
4: ; preds = %7, %1
%5 = phi double [ %0, %1 ], [ %9, %7 ]
%6 = phi double [ 0.000000e+00, %1 ], [ %8, %7 ]
br label %7
7: ; preds = %4, %12
%8 = phi double [ %9, %12 ], [ %6, %4 ]
%9 = tail call double @the_middle_of(double %8, double %5)
%10 = fmul double %9, %9
%11 = fcmp ogt double %10, %3
br i1 %11, label %4, label %12
12: ; preds = %7
%13 = fcmp olt double %10, %2
br i1 %13, label %7, label %14
14: ; preds = %12
ret double %9
}