#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 */
int /*<<< orphan*/ printf(char *);
float squareRoot(float x) {
  const float episolon = .00001;
  float guess = 1.0;
  float absoluteValue(float x);
  if (x < 0) {
    printf("Negative argument to squareRoot.\n");
    return -1.0;
  }
  while (absoluteValue(guess * guess - x) >= episolon)
    guess = (x / guess + guess) / 2.0;
  return guess;
}


x86 assembly (clang, -O0):
<squareRoot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
movss  0xecf(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xebe(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    1172 <squareRoot+0x52>
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
movss  0xea0(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11e8 <squareRoot+0xc8>
jmp    1177 <squareRoot+0x57>
movss  -0x10(%rbp),%xmm0
movss  -0x10(%rbp),%xmm2
movss  -0x8(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <absoluteValue@plt>
movss  0xe5c(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     11de <squareRoot+0xbe>
movss  -0x8(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe44(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    1177 <squareRoot+0x57>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<squareRoot>:
sub    $0x38,%rsp
xorps  %xmm1,%xmm1
movaps %xmm0,(%rsp)
ucomiss %xmm0,%xmm1
jbe    1149 <squareRoot+0x29>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
movss  0xed8(%rip),%xmm1
jmp    11cc <squareRoot+0xac>
movss  0xebf(%rip),%xmm0
subss  (%rsp),%xmm0
call   1040 <absoluteValue@plt>
movss  0xead(%rip),%xmm1
ucomiss 0xeaa(%rip),%xmm0
jb     11cc <squareRoot+0xac>
movaps 0xe8d(%rip),%xmm0
xorps  (%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
movss  0xe8c(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movaps (%rsp),%xmm1
divss  %xmm0,%xmm1
addss  %xmm0,%xmm1
mulss  0xe74(%rip),%xmm1
movaps %xmm1,0x20(%rsp)
movaps %xmm1,%xmm0
mulss  %xmm1,%xmm0
addss  0x10(%rsp),%xmm0
call   1040 <absoluteValue@plt>
movaps 0x20(%rsp),%xmm1
ucomiss 0xe4d(%rip),%xmm0
movaps %xmm1,%xmm0
jae    1190 <squareRoot+0x70>
movaps %xmm1,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Negative argument to squareRoot.\0A\00"
define float @squareRoot(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
store float %0, float* %3
store float 0x3EE4F8B580000000, float* %4
store float 1.000000e+00, float* %5
%6 = load float, float* %3
%7 = fcmp olt float %6, 0.000000e+00
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store float -1.000000e+00, float* %2
br label %30
10: ; preds = %1
br label %11
11: ; preds = %19, %10
%12 = load float, float* %5
%13 = load float, float* %5
%14 = load float, float* %3
%15 = fneg float %14
%16 = call float @llvm.fmuladd.f32(float %12, float %13, float %15)
%17 = call float @absoluteValue(float %16)
%18 = fcmp oge float %17, 0x3EE4F8B580000000
br i1 %18, label %19, label %28
19: ; preds = %11
%20 = load float, float* %3
%21 = load float, float* %5
%22 = fdiv float %20, %21
%23 = load float, float* %5
%24 = fadd float %22, %23
%25 = fpext float %24 to double
%26 = fdiv double %25, 2.000000e+00
%27 = fptrunc double %26 to float
store float %27, float* %5
br label %11
28: ; preds = %11
%29 = load float, float* %5
store float %29, float* %2
br label %30
30: ; preds = %28, %8
%31 = load float, float* %2
ret float %31
}

LLVM IR (-O2):
@str = [33 x i8] c"Negative argument to squareRoot.\00"
define float @squareRoot(float %0) {
%2 = fcmp olt float %0, 0.000000e+00
br i1 %2, label %8, label %3
3: ; preds = %1
%4 = fneg float %0
%5 = fsub float 1.000000e+00, %0
%6 = tail call float @absoluteValue(float %5)
%7 = fcmp ult float %6, 0x3EE4F8B580000000
br i1 %7, label %18, label %10
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %18
10: ; preds = %3, %10
%11 = phi float [ %14, %10 ], [ 1.000000e+00, %3 ]
%12 = fdiv float %0, %11
%13 = fadd float %11, %12
%14 = fmul float %13, 5.000000e-01
%15 = tail call float @llvm.fmuladd.f32(float %14, float %14, float %4)
%16 = tail call float @absoluteValue(float %15)
%17 = fcmp ult float %16, 0x3EE4F8B580000000
br i1 %17, label %18, label %10
18: ; preds = %10, %3, %8
%19 = phi float [ -1.000000e+00, %8 ], [ 1.000000e+00, %3 ], [ %14, %10 ]
ret float %19
}