#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
int main() {
  double root;
  printf("To find the square root, please input a float: ");
  scanf("%lf", &root);
  double sqrt = root / 4.0;
  double temp = root / sqrt;
  double store;
  int cntr = 0;
  while (sqrt != temp) {
    if (store == temp) {
      ++cntr;
    }
    store = temp;
    temp = root / sqrt;
    sqrt = (temp + sqrt) / 2.0;
    if (cntr == 5) {
      break;
    }
  }
  printf("\nThe square root is (possibly approx.): %.200g\n\n", sqrt);
  printf("That answer squared is: %.200g\n\n", sqrt * sqrt);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefc(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0xea6(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    1194 <main+0x74>
jp     1194 <main+0x74>
jmp    11fb <main+0xdb>
movsd  -0x28(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    11b3 <main+0x93>
jp     11b3 <main+0x93>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe2a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x5,-0x2c(%rbp)
jne    11f6 <main+0xd6>
jmp    11fb <main+0xdb>
jmp    1179 <main+0x59>
movsd  -0x18(%rbp),%xmm0
lea    0xe3d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
lea    0xe56(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xee4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf04(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
movsd  0x8(%rsp),%xmm5
movsd  0xeac(%rip),%xmm0
mulsd  %xmm5,%xmm0
movapd %xmm5,%xmm2
divsd  %xmm0,%xmm2
movsd  0xea0(%rip),%xmm1
nopl   0x0(%rax,%rax,1)
ucomisd %xmm2,%xmm0
jne    1178 <main+0x58>
jnp    11a1 <main+0x81>
movapd %xmm2,%xmm3
cmpeqsd %xmm2,%xmm4
movq   %xmm4,%rax
sub    %eax,%ebx
movapd %xmm5,%xmm2
divsd  %xmm0,%xmm2
addsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
movapd %xmm3,%xmm4
cmp    $0x5,%ebx
jne    1170 <main+0x50>
movsd  %xmm0,(%rsp)
lea    0xe97(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
mulsd  %xmm0,%xmm0
lea    0xeb1(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [48 x i8] c"To find the square root, please input a float: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [49 x i8] c"\0AThe square root is (possibly approx.): %.200g\0A\0A\00"
@.str.3 = [33 x i8] c"That answer squared is: %.200g\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, 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 = load double, double* %2
%10 = fdiv double %9, 4.000000e+00
store double %10, double* %3
%11 = load double, double* %2
%12 = load double, double* %3
%13 = fdiv double %11, %12
store double %13, double* %4
store i32 0, i32* %6
br label %14
14: ; preds = %37, %0
%15 = load double, double* %3
%16 = load double, double* %4
%17 = fcmp une double %15, %16
br i1 %17, label %18, label %38
18: ; preds = %14
%19 = load double, double* %5
%20 = load double, double* %4
%21 = fcmp oeq double %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %25
25: ; preds = %22, %18
%26 = load double, double* %4
store double %26, double* %5
%27 = load double, double* %2
%28 = load double, double* %3
%29 = fdiv double %27, %28
store double %29, double* %4
%30 = load double, double* %4
%31 = load double, double* %3
%32 = fadd double %30, %31
%33 = fdiv double %32, 2.000000e+00
store double %33, double* %3
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 5
br i1 %35, label %36, label %37
36: ; preds = %25
br label %38
37: ; preds = %25
br label %14
38: ; preds = %36, %14
%39 = load double, double* %3
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), double %39)
%41 = load double, double* %3
%42 = load double, double* %3
%43 = fmul double %41, %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), double %43)
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str = [48 x i8] c"To find the square root, please input a float: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [49 x i8] c"\0AThe square root is (possibly approx.): %.200g\0A\0A\00"
@.str.3 = [33 x i8] c"That answer squared is: %.200g\0A\0A\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 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
%6 = fmul double %5, 2.500000e-01
%7 = fdiv double %5, %6
br label %8
8: ; preds = %14, %0
%9 = phi double [ %6, %0 ], [ %20, %14 ]
%10 = phi double [ %7, %0 ], [ %18, %14 ]
%11 = phi double [ undef, %0 ], [ %10, %14 ]
%12 = phi i32 [ 0, %0 ], [ %17, %14 ]
%13 = fcmp une double %9, %10
br i1 %13, label %14, label %22
14: ; preds = %8
%15 = fcmp oeq double %11, %10
%16 = zext i1 %15 to i32
%17 = add nuw nsw i32 %12, %16
%18 = fdiv double %5, %9
%19 = fadd double %9, %18
%20 = fmul double %19, 5.000000e-01
%21 = icmp eq i32 %17, 5
br i1 %21, label %22, label %8
22: ; preds = %14, %8
%23 = phi double [ %20, %14 ], [ %9, %8 ]
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), double %23)
%25 = fmul double %23, %23
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), double %25)
ret i32 0
}