#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 n, x, y, avg;
  printf("Enter a positive number: ");
  scanf("%lf", &n);
  y = 1;
  x = n;
  avg = (y + (x / y)) / 2;
  while (fabs(avg - y) > 0.000001) {
    y = avg;
    avg = (y + (x / y)) / 2;
  }
  printf("Square root: %lf\n", y);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xefa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf06(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movsd  0xeb3(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe81(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movaps 0xe87(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe6b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e2 <main+0xc2>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe2c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1188 <main+0x68>
movsd  -0x20(%rbp),%xmm0
lea    0xe60(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xf08(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf14(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
movsd  (%rsp),%xmm1
movsd  0xeb5(%rip),%xmm0
movapd %xmm1,%xmm2
addsd  %xmm0,%xmm2
mulsd  0xead(%rip),%xmm2
movsd  0xead(%rip),%xmm3
addsd  %xmm2,%xmm3
andpd  0xeb1(%rip),%xmm3
ucomisd 0xea1(%rip),%xmm3
jbe    11c6 <main+0xa6>
movsd  0xe87(%rip),%xmm3
movapd 0xe97(%rip),%xmm4
movsd  0xe87(%rip),%xmm5
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movapd %xmm2,%xmm0
movapd %xmm1,%xmm2
divsd  %xmm0,%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm3,%xmm2
movapd %xmm2,%xmm6
subsd  %xmm0,%xmm6
andpd  %xmm4,%xmm6
ucomisd %xmm5,%xmm6
ja     11a0 <main+0x80>
lea    0xe81(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [26 x i8] c"Enter a positive number: \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 double
%2 = bitcast double* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 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 = fadd double %5, 1.000000e+00
%7 = fmul double %6, 5.000000e-01
%8 = fadd double %7, -1.000000e+00
%9 = call double @llvm.fabs.f64(double %8)
%10 = fcmp ogt double %9, 0x3EB0C6F7A0B5ED8D
br i1 %10, label %11, label %19
11: ; preds = %0, %11
%12 = phi double [ %15, %11 ], [ %7, %0 ]
%13 = fdiv double %5, %12
%14 = fadd double %12, %13
%15 = fmul double %14, 5.000000e-01
%16 = fsub double %15, %12
%17 = call double @llvm.fabs.f64(double %16)
%18 = fcmp ogt double %17, 0x3EB0C6F7A0B5ED8D
br i1 %18, label %11, label %19
19: ; preds = %11, %0
%20 = phi double [ 1.000000e+00, %0 ], [ %12, %11 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), double %20)
ret i32 0
}