#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 fabs(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int main() {
  float a, x0, x1;
  printf("enter a positive number:");
  scanf("%f", &a);
  x0 = a / 2;
  x1 = (x0 + a / x0) / 2;
  do {
    x0 = x1;
    x1 = (x0 + a / x0) / 2;
  } while (fabs(x0 - x1) >= 1e-5);
  printf("The square root of %5.2f  is %8.5f\n", a, x1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movss  -0x8(%rbp),%xmm0
movss  0xe96(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
divss  -0xc(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  0xe72(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
divss  -0xc(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  0xe44(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe28(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1197 <main+0x67>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe29(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
movss  0x4(%rsp),%xmm3
movss  0xea2(%rip),%xmm2
movaps %xmm3,%xmm1
mulss  %xmm2,%xmm1
movaps %xmm3,%xmm0
divss  %xmm1,%xmm0
addss  %xmm1,%xmm0
mulss  %xmm2,%xmm0
divss  %xmm0,%xmm3
addss  %xmm0,%xmm3
mulss  %xmm2,%xmm3
movss  %xmm3,(%rsp)
subss  %xmm3,%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jle    11d2 <main+0xa2>
movss  (%rsp),%xmm0
nopw   0x0(%rax,%rax,1)
movss  0x4(%rsp),%xmm1
divss  %xmm0,%xmm1
addss  %xmm0,%xmm1
mulss  0xe4a(%rip),%xmm1
movss  %xmm1,(%rsp)
subss  %xmm1,%xmm0
call   1040 <fabs@plt>
movss  (%rsp),%xmm1
movaps %xmm1,%xmm0
test   %eax,%eax
jg     11a0 <main+0x70>
jmp    11d7 <main+0xa7>
movss  (%rsp),%xmm1
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
cvtss2sd %xmm1,%xmm1
lea    0xe34(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"enter a positive number:\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [36 x i8] c"The square root of %5.2f is %8.5f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%7 = load float, float* %2
%8 = fdiv float %7, 2.000000e+00
store float %8, float* %3
%9 = load float, float* %3
%10 = load float, float* %2
%11 = load float, float* %3
%12 = fdiv float %10, %11
%13 = fadd float %9, %12
%14 = fdiv float %13, 2.000000e+00
store float %14, float* %4
br label %15
15: ; preds = %23, %0
%16 = load float, float* %4
store float %16, float* %3
%17 = load float, float* %3
%18 = load float, float* %2
%19 = load float, float* %3
%20 = fdiv float %18, %19
%21 = fadd float %17, %20
%22 = fdiv float %21, 2.000000e+00
store float %22, float* %4
br label %23
23: ; preds = %15
%24 = load float, float* %3
%25 = load float, float* %4
%26 = fsub float %24, %25
%27 = call i32 @fabs(float %26)
%28 = sitofp i32 %27 to double
%29 = fcmp oge double %28, 1.000000e-05
br i1 %29, label %15, label %30
30: ; preds = %23
%31 = load float, float* %2
%32 = fpext float %31 to double
%33 = load float, float* %4
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %32, double %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"enter a positive number:\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [36 x i8] c"The square root of %5.2f is %8.5f\0A\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%5 = load float, float* %1
%6 = fmul float %5, 5.000000e-01
%7 = fdiv float %5, %6
%8 = fadd float %6, %7
%9 = fmul float %8, 5.000000e-01
%10 = fdiv float %5, %9
%11 = fadd float %9, %10
%12 = fmul float %11, 5.000000e-01
%13 = fsub float %9, %12
%14 = call i32 @fabs(float %13)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %0, %16
%17 = phi float [ %21, %16 ], [ %12, %0 ]
%18 = load float, float* %1
%19 = fdiv float %18, %17
%20 = fadd float %17, %19
%21 = fmul float %20, 5.000000e-01
%22 = fsub float %17, %21
%23 = call i32 @fabs(float %22)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %16, label %25
25: ; preds = %16, %0
%26 = phi float [ %12, %0 ], [ %21, %16 ]
%27 = load float, float* %1
%28 = fpext float %27 to double
%29 = fpext float %26 to double
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %28, double %29)
ret i32 0
}