#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int main() {
  float new_guess;
  float last_guess;
  float number;
  printf("Enter a number: ");
  scanf("%f", &number);
  if (number < 0) {
    printf("Cannot compute the square root of a "
           "negative number!\n");
    return EXIT_FAILURE;
  }
  new_guess = 1;
  do {
    last_guess = new_guess;
    new_guess = (last_guess + number / last_guess) / 2;
    printf("%.15e\n", new_guess);
  } while (new_guess != last_guess);
  printf("Square root of %g is %g\n", number, new_guess);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
xorps  %xmm0,%xmm0
ucomiss -0x10(%rbp),%xmm0
jbe    1179 <main+0x59>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120c <main+0xec>
movss  0xe7f(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
divss  -0xc(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  0xe59(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe8e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  -0x8(%rbp),%xmm0
ucomiss -0xc(%rbp),%xmm0
jne    1186 <main+0x66>
jp     1186 <main+0x66>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x8(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe60(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
movss  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
jbe    117a <main+0x4a>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e6b(%rip),%rax
jmp    123a <main+0x10a>
addss  0xe7e(%rip),%xmm1
mulss  0xe7a(%rip),%xmm1
movss  %xmm1,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe7e(%rip),%rdi
movsd  %xmm0,0x18(%rsp)
mov    $0x1,%al
call   1040 <printf@plt>
movss  0xc(%rsp),%xmm1
ucomiss 0xe48(%rip),%xmm1
jne    11bc <main+0x8c>
jnp    1215 <main+0xe5>
lea    0xe59(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movss  %xmm1,0xc(%rsp)
movss  0x10(%rsp),%xmm0
divss  %xmm1,%xmm0
addss  %xmm1,%xmm0
mulss  0xe18(%rip),%xmm0
movss  %xmm0,0x14(%rsp)
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
movsd  %xmm0,0x18(%rsp)
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x14(%rsp),%xmm1
ucomiss 0xc(%rsp),%xmm1
jne    11d0 <main+0xa0>
jp     11d0 <main+0xa0>
movss  0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdfd(%rip),%rdi
movsd  0x18(%rsp),%xmm1
mov    $0x2,%al
call   1040 <printf@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [54 x i8] c"Cannot compute the square root of a negative number!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [7 x i8] c"%.15e\0A\00"
@.str.4 = [25 x i8] c"Square root of %g is %g\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %4)
%7 = load float, float* %4
%8 = fcmp olt float %7, 0.000000e+00
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
store i32 %11, i32* %1
br label %35
12: ; preds = %0
store float 1.000000e+00, float* %2
br label %13
13: ; preds = %24, %12
%14 = load float, float* %2
store float %14, float* %3
%15 = load float, float* %3
%16 = load float, float* %4
%17 = load float, float* %3
%18 = fdiv float %16, %17
%19 = fadd float %15, %18
%20 = fdiv float %19, 2.000000e+00
store float %20, float* %2
%21 = load float, float* %2
%22 = fpext float %21 to double
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %22)
br label %24
24: ; preds = %13
%25 = load float, float* %2
%26 = load float, float* %3
%27 = fcmp une float %25, %26
br i1 %27, label %13, label %28
28: ; preds = %24
%29 = load float, float* %4
%30 = fpext float %29 to double
%31 = load float, float* %2
%32 = fpext float %31 to double
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %30, double %32)
%34 = load i32, i32* @EXIT_SUCCESS
store i32 %34, i32* %1
br label %35
35: ; preds = %28, %9
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%f\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [7 x i8] c"%.15e\0A\00"
@.str.4 = [25 x i8] c"Square root of %g is %g\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [53 x i8] c"Cannot compute the square root of a negative number!\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 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), float* %1)
%5 = load float, float* %1
%6 = fcmp olt float %5, 0.000000e+00
br i1 %6, label %13, label %7
7: ; preds = %0
%8 = fadd float %5, 1.000000e+00
%9 = fmul float %8, 5.000000e-01
%10 = fpext float %9 to double
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %10)
%12 = fcmp une float %9, 1.000000e+00
br i1 %12, label %15, label %24
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
br label %29
15: ; preds = %7, %15
%16 = phi float [ %20, %15 ], [ %9, %7 ]
%17 = load float, float* %1
%18 = fdiv float %17, %16
%19 = fadd float %16, %18
%20 = fmul float %19, 5.000000e-01
%21 = fpext float %20 to double
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %21)
%23 = fcmp une float %20, %16
br i1 %23, label %15, label %24
24: ; preds = %15, %7
%25 = phi double [ %10, %7 ], [ %21, %15 ]
%26 = load float, float* %1
%27 = fpext float %26 to double
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %27, double %25)
br label %29
29: ; preds = %24, %13
%30 = phi i32* [ @EXIT_FAILURE, %13 ], [ @EXIT_SUCCESS, %24 ]
%31 = load i32, i32* %30
ret i32 %31
}