#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 *, int *);
int main(void) {
  int x;
  double y = 1;
  double new_y;
  double z;
  printf("Enter  a positive number: ");
  scanf("%d", &x);
  for (;;) {
    z = x / y;
    new_y = (y + z) / 2;
    if (fabs(new_y - y) < (y * 0.00001)) {
      y = new_y;
      break;
    } else {
      y = new_y;
    }
  }
  printf("Square root: %f\n", y);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
lea    0xeed(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cvtsi2sdl -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe95(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movaps 0xe8b(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe67(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11bf <main+0x9f>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11ce <main+0xae>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    115a <main+0x3a>
movsd  -0x10(%rbp),%xmm0
lea    0xe74(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xf08(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf15(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
cvtsi2sdl 0x4(%rsp),%xmm1
movsd  0xeb2(%rip),%xmm0
movsd  0xeb2(%rip),%xmm2
movapd 0xec2(%rip),%xmm3
movsd  0xeaa(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
movapd %xmm0,%xmm5
movapd %xmm1,%xmm0
divsd  %xmm5,%xmm0
addsd  %xmm5,%xmm0
mulsd  %xmm2,%xmm0
movapd %xmm0,%xmm6
subsd  %xmm5,%xmm6
andpd  %xmm3,%xmm6
mulsd  %xmm4,%xmm5
ucomisd %xmm6,%xmm5
jbe    1170 <main+0x50>
lea    0xead(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [27 x i8] c"Enter a positive number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"Square root: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 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), i32* %1)
%5 = load i32, i32* %1
%6 = sitofp i32 %5 to double
br label %7
7: ; preds = %7, %0
%8 = phi double [ 1.000000e+00, %0 ], [ %11, %7 ]
%9 = fdiv double %6, %8
%10 = fadd double %8, %9
%11 = fmul double %10, 5.000000e-01
%12 = fsub double %11, %8
%13 = call double @llvm.fabs.f64(double %12)
%14 = fmul double %8, 1.000000e-05
%15 = fcmp olt double %13, %14
br i1 %15, label %16, label %7
16: ; preds = %7
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), double %11)
ret i32 0
}