#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 abs_v(float);
int /*<<< orphan*/ printf(char *, float);
float sqrt_v(float x) {
  float guess = 1.0;
  do {
    printf("Guess: %.5f\n", guess);
    guess = (x / guess + guess) / 2;
  } while (abs_v(x) / abs_v((guess * guess)) < 1.00);
  return guess;
}


x86 assembly (clang, -O0):
<sqrt_v>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
movss  0xecb(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
movss  -0x4(%rbp),%xmm0
divss  -0x8(%rbp),%xmm0
addss  -0x8(%rbp),%xmm0
movss  0xea2(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
call   1040 <abs_v@plt>
movsd  %xmm0,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
call   1040 <abs_v@plt>
movsd  -0x10(%rbp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe6e(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     113a <sqrt_v+0x1a>
movss  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrt_v>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm0,0x4(%rsp)
movss  0xecd(%rip),%xmm0
movss  %xmm0,(%rsp)
lea    0xed1(%rip),%rbx
nop
mov    %rbx,%rdi
movss  (%rsp),%xmm0
call   1030 <printf@plt>
movss  0x4(%rsp),%xmm0
movaps %xmm0,%xmm1
movss  (%rsp),%xmm2
divss  %xmm2,%xmm1
addss  %xmm1,%xmm2
mulss  0xe99(%rip),%xmm2
movss  %xmm2,(%rsp)
call   1040 <abs_v@plt>
movsd  %xmm0,0x8(%rsp)
movss  (%rsp),%xmm0
mulss  %xmm0,%xmm0
call   1040 <abs_v@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe6d(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1140 <sqrt_v+0x20>
movss  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Guess: %.5f\0A\00"
define float @sqrt_v(float %0) {
%2 = alloca float
%3 = alloca float
store float %0, float* %2
store float 1.000000e+00, float* %3
br label %4
4: ; preds = %13, %1
%5 = load float, float* %3
%6 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), float %5)
%7 = load float, float* %2
%8 = load float, float* %3
%9 = fdiv float %7, %8
%10 = load float, float* %3
%11 = fadd float %9, %10
%12 = fdiv float %11, 2.000000e+00
store float %12, float* %3
br label %13
13: ; preds = %4
%14 = load float, float* %2
%15 = call double @abs_v(float %14)
%16 = load float, float* %3
%17 = load float, float* %3
%18 = fmul float %16, %17
%19 = call double @abs_v(float %18)
%20 = fdiv double %15, %19
%21 = fcmp olt double %20, 1.000000e+00
br i1 %21, label %4, label %22
22: ; preds = %13
%23 = load float, float* %3
ret float %23
}

LLVM IR (-O2):
@.str = [13 x i8] c"Guess: %.5f\0A\00"
define float @sqrt_v(float %0) {
br label %2
2: ; preds = %2, %1
%3 = phi float [ 1.000000e+00, %1 ], [ %7, %2 ]
%4 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), float %3)
%5 = fdiv float %0, %3
%6 = fadd float %3, %5
%7 = fmul float %6, 5.000000e-01
%8 = tail call double @abs_v(float %0)
%9 = fmul float %7, %7
%10 = tail call double @abs_v(float %9)
%11 = fdiv double %8, %10
%12 = fcmp olt double %11, 1.000000e+00
br i1 %12, label %2, label %13
13: ; preds = %2
ret float %7
}