#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;
  double y;
  double average;
  printf("Enter a number to find it's square root: ");
  scanf("%lf", &x);
  printf("Enter a starting point for calculating the square: ");
  scanf("%lf", &y);
  printf("x\ty\tx/y\tAvg. of x/y\n");
  ;
  while (fabs(y * y - x) >= 0.00001 * y) {
    average = (y + (x / y)) / 2;
    printf("%.5lf ", x);
    printf("%.5lf ", y);
    printf("%.5lf ", x / y);
    printf("%.5lf \n", average);
    y = average;
  }
  printf("The approximate square root of your number is: %.05lf\n", y);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf06(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xefa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xf10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movaps 0xe62(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe46(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     124d <main+0x12d>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
divsd  -0x18(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe24(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xe9e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe8b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
lea    0xe73(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
lea    0xe67(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1179 <main+0x59>
movsd  -0x18(%rbp),%xmm0
lea    0xe4d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xee2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xefe(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xeee(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xf4f(%rip),%rdi
call   1030 <puts@plt>
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm0,%xmm2
andpd  0xe63(%rip),%xmm2
movsd  0xe6b(%rip),%xmm3
mulsd  %xmm1,%xmm3
ucomisd %xmm3,%xmm2
jae    11b8 <main+0x88>
movapd %xmm1,%xmm2
jmp    126b <main+0x13b>
lea    0xec3(%rip),%rbx
lea    0xec3(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm1,%xmm2
mulsd  0xe34(%rip),%xmm2
movsd  %xmm2,0x10(%rsp)
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  (%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
divsd  (%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r14,%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm3
movsd  %xmm3,(%rsp)
movsd  0x8(%rsp),%xmm0
movapd %xmm3,%xmm1
mulsd  %xmm3,%xmm1
subsd  %xmm0,%xmm1
andpd  0xdb3(%rip),%xmm1
movapd %xmm3,%xmm2
mulsd  0xdb7(%rip),%xmm2
ucomisd %xmm2,%xmm1
movapd %xmm3,%xmm2
movapd %xmm3,%xmm1
jae    11d0 <main+0xa0>
lea    0xe1f(%rip),%rdi
movapd %xmm2,%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Enter a number to find it's square root: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [52 x i8] c"Enter a starting point for calculating the square: \00"
@.str.3 = [21 x i8] c"x\09y\09x/y\09Avg. of x/y\0A\00"
@.str.4 = [7 x i8] c"%.5lf \00"
@.str.5 = [8 x i8] c"%.5lf \0A\00"
@.str.6 = [55 x i8] c"The approximate square root of your number is: %.05lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 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)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %10
10: ; preds = %20, %0
%11 = load double, double* %3
%12 = load double, double* %3
%13 = load double, double* %2
%14 = fneg double %13
%15 = call double @llvm.fmuladd.f64(double %11, double %12, double %14)
%16 = call double @llvm.fabs.f64(double %15)
%17 = load double, double* %3
%18 = fmul double 1.000000e-05, %17
%19 = fcmp oge double %16, %18
br i1 %19, label %20, label %38
20: ; preds = %10
%21 = load double, double* %3
%22 = load double, double* %2
%23 = load double, double* %3
%24 = fdiv double %22, %23
%25 = fadd double %21, %24
%26 = fdiv double %25, 2.000000e+00
store double %26, double* %4
%27 = load double, double* %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %27)
%29 = load double, double* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %29)
%31 = load double, double* %2
%32 = load double, double* %3
%33 = fdiv double %31, %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %33)
%35 = load double, double* %4
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %35)
%37 = load double, double* %4
store double %37, double* %3
br label %10
38: ; preds = %10
%39 = load double, double* %3
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), double %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [42 x i8] c"Enter a number to find it's square root: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [52 x i8] c"Enter a starting point for calculating the square: \00"
@.str.4 = [7 x i8] c"%.5lf \00"
@.str.5 = [8 x i8] c"%.5lf \0A\00"
@.str.6 = [55 x i8] c"The approximate square root of your number is: %.05lf\0A\00"
@str = [20 x i8] c"x\09y\09x/y\09Avg. of x/y\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = bitcast double* %1 to i8*
%4 = bitcast double* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 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* %1)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%10 = load double, double* %2
%11 = load double, double* %1
%12 = fneg double %11
%13 = call double @llvm.fmuladd.f64(double %10, double %10, double %12)
%14 = call double @llvm.fabs.f64(double %13)
%15 = fmul double %10, 1.000000e-05
%16 = fcmp ult double %14, %15
br i1 %16, label %37, label %17
17: ; preds = %0, %17
%18 = phi double [ %31, %17 ], [ %11, %0 ]
%19 = phi double [ %22, %17 ], [ %10, %0 ]
%20 = fdiv double %18, %19
%21 = fadd double %19, %20
%22 = fmul double %21, 5.000000e-01
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %18)
%24 = load double, double* %2
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %24)
%26 = load double, double* %1
%27 = load double, double* %2
%28 = fdiv double %26, %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %28)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %22)
store double %22, double* %2
%31 = load double, double* %1
%32 = fneg double %31
%33 = call double @llvm.fmuladd.f64(double %22, double %22, double %32)
%34 = call double @llvm.fabs.f64(double %33)
%35 = fmul double %22, 1.000000e-05
%36 = fcmp ult double %34, %35
br i1 %36, label %37, label %17
37: ; preds = %17, %0
%38 = phi double [ %10, %0 ], [ %22, %17 ]
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), double %38)
ret i32 0
}