#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 *, float *);
int main(void) {
  float new_guess;
  float last_guess;
  float number;
  printf("Enter a number: ");
  scanf("%f", &number);
  if (number < 0) {
    printf("Cannot computete the square root of a negative number\n\n");
    return 1;
  }
  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 0;
}


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    1174 <main+0x54>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1202 <main+0xe2>
movss  0xe84(%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  0xe5e(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe95(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  -0x8(%rbp),%xmm0
ucomiss -0xc(%rbp),%xmm0
jne    1181 <main+0x61>
jp     1181 <main+0x61>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x8(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe67(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x0,-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    1178 <main+0x48>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1235 <main+0x105>
addss  0xe80(%rip),%xmm1
mulss  0xe7c(%rip),%xmm1
movss  %xmm1,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe80(%rip),%rdi
movsd  %xmm0,0x18(%rsp)
mov    $0x1,%al
call   1040 <printf@plt>
movss  0xc(%rsp),%xmm1
ucomiss 0xe4a(%rip),%xmm1
jne    11ba <main+0x8a>
jnp    1215 <main+0xe5>
lea    0xe5b(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
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>
xor    %eax,%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 = [56 x i8] c"Cannot computete the square root of a negative number\0A\0A\00"
@.str.3 = [7 x i8] c"%.15e\0A\00"
@.str.4 = [25 x i8] c"Square root of %g is %g\0A\00"
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 %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %33
11: ; preds = %0
store float 1.000000e+00, float* %2
br label %12
12: ; preds = %23, %11
%13 = load float, float* %2
store float %13, float* %3
%14 = load float, float* %3
%15 = load float, float* %4
%16 = load float, float* %3
%17 = fdiv float %15, %16
%18 = fadd float %14, %17
%19 = fdiv float %18, 2.000000e+00
store float %19, float* %2
%20 = load float, float* %2
%21 = fpext float %20 to double
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %21)
br label %23
23: ; preds = %12
%24 = load float, float* %2
%25 = load float, float* %3
%26 = fcmp une float %24, %25
br i1 %26, label %12, label %27
27: ; preds = %23
%28 = load float, float* %4
%29 = fpext float %28 to double
%30 = load float, float* %2
%31 = fpext float %30 to double
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %29, double %31)
store i32 0, i32* %1
br label %33
33: ; preds = %27, %9
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.3 = [7 x i8] c"%.15e\0A\00"
@.str.4 = [25 x i8] c"Square root of %g is %g\0A\00"
@str = [55 x i8] c"Cannot computete the square root of a negative number\0A\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 ([55 x i8], [55 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 [ 1, %13 ], [ 0, %24 ]
ret i32 %30
}