#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 fabs(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
int main(void) {
  double x, y = 1.0, FABS = 1.0;
  printf("enter a positive number:\n");
  scanf("%lf", &x);
  while (1) {
    FABS = y - (y + x / y) / 2;
    y = (y + x / y) / 2;
    if (fabs(FABS) < 0.00001 * y) {
      printf("square root: %lf\n", y);
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeec(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
divsd  -0x18(%rbp),%xmm2
addsd  %xmm2,%xmm1
movsd  0xe89(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
divsd  -0x18(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe61(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm1
movaps 0xe5c(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe38(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11fa <main+0xda>
movsd  -0x18(%rbp),%xmm0
lea    0xe63(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    1167 <main+0x47>

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xf0e(%rip),%rdi
call   1030 <puts@plt>
lea    0xeec(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
movsd  0xeac(%rip),%xmm0
movsd  (%rsp),%xmm1
movsd  0xea7(%rip),%xmm2
movapd 0xeb7(%rip),%xmm3
movsd  0xe9f(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movapd %xmm0,%xmm5
movapd %xmm1,%xmm0
divsd  %xmm5,%xmm0
addsd  %xmm5,%xmm0
mulsd  %xmm2,%xmm0
subsd  %xmm0,%xmm5
andpd  %xmm3,%xmm5
movapd %xmm0,%xmm6
mulsd  %xmm4,%xmm6
ucomisd %xmm5,%xmm6
jbe    1180 <main+0x50>
lea    0xe83(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [18 x i8] c"square root: %lf\0A\00"
@str = [25 x i8] c"enter a positive number:\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%5 = load double, double* %1
br label %6
6: ; preds = %6, %0
%7 = phi double [ 1.000000e+00, %0 ], [ %10, %6 ]
%8 = fdiv double %5, %7
%9 = fadd double %7, %8
%10 = fmul double %9, 5.000000e-01
%11 = fsub double %7, %10
%12 = call double @llvm.fabs.f64(double %11)
%13 = fmul double %10, 1.000000e-05
%14 = fcmp olt double %12, %13
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), double %10)
ret i32 0
}