#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 fabs(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int main() {
  float number = 0;
  float answer = 1;
  int i = 0;
  printf("Please enter a number and I will try my best to figure out the "
         "ridical sign of the number\n");
  while (!scanf("%f", &number)) {
    printf("The number that you have entered is not right,Please enter the "
           "number in your mind again!\n");
  }
  if (number < 0) {
    printf("Cannot compute the square root of a negative number!\n");
    return 0;
  }
  for (i = 0; fabs(answer * answer - number) > 1e-6; i++) {
    answer = (answer + (number / answer)) / 2;
    printf("The answer is %f\n", answer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  0xeb1(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118e <main+0x5e>
jmp    11a1 <main+0x71>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1169 <main+0x39>
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    11c8 <main+0x98>
lea    0xf14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125e <main+0x12e>
movl   $0x0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
movss  -0x8(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe04(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1257 <main+0x127>
movss  -0xc(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
divss  -0xc(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  0xddb(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xebd(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11cf <main+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x8(%rsp)
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
lea    0xea4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
test   %eax,%eax
jne    11a7 <main+0x67>
lea    0xf33(%rip),%r14
lea    0xe88(%rip),%r15
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
test   %eax,%eax
je     1190 <main+0x50>
movss  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
jbe    11c3 <main+0x83>
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
jmp    123c <main+0xfc>
movss  0xe35(%rip),%xmm0
subss  %xmm1,%xmm0
call   1050 <fabs@plt>
movss  0xe24(%rip),%xmm0
test   %eax,%eax
jle    123c <main+0xfc>
lea    0xe24(%rip),%rbx
nopw   0x0(%rax,%rax,1)
movss  0x8(%rsp),%xmm1
divss  %xmm0,%xmm1
addss  %xmm0,%xmm1
mulss  0xdfe(%rip),%xmm1
movss  %xmm1,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0xc(%rsp),%xmm0
mulss  %xmm0,%xmm0
subss  0x8(%rsp),%xmm0
call   1050 <fabs@plt>
movss  0xc(%rsp),%xmm0
test   %eax,%eax
jg     11f0 <main+0xb0>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [91 x i8] c"Please enter a number and I will try my best to figure out the ridical sign of the number\0A\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [91 x i8] c"The number that you have entered is not right,Please enter the number in your mind again!\0A\00"
@.str.3 = [54 x i8] c"Cannot compute the square root of a negative number!\0A\00"
@.str.4 = [18 x i8] c"The answer is %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca i32
store i32 0, i32* %1
store float 0.000000e+00, float* %2
store float 1.000000e+00, float* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %10, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0))
br label %6
12: ; preds = %6
%13 = load float, float* %2
%14 = fcmp olt float %13, 0.000000e+00
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %41
17: ; preds = %12
store i32 0, i32* %4
br label %18
18: ; preds = %37, %17
%19 = load float, float* %3
%20 = load float, float* %3
%21 = load float, float* %2
%22 = fneg float %21
%23 = call float @llvm.fmuladd.f32(float %19, float %20, float %22)
%24 = call i32 @fabs(float %23)
%25 = sitofp i32 %24 to double
%26 = fcmp ogt double %25, 0x3EB0C6F7A0B5ED8D
br i1 %26, label %27, label %40
27: ; preds = %18
%28 = load float, float* %3
%29 = load float, float* %2
%30 = load float, float* %3
%31 = fdiv float %29, %30
%32 = fadd float %28, %31
%33 = fdiv float %32, 2.000000e+00
store float %33, float* %3
%34 = load float, float* %3
%35 = fpext float %34 to double
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), double %35)
br label %37
37: ; preds = %27
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %18
40: ; preds = %18
store i32 0, i32* %1
br label %41
41: ; preds = %40, %15
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%f\00"
@.str.4 = [18 x i8] c"The answer is %f\0A\00"
@str = [90 x i8] c"Please enter a number and I will try my best to figure out the ridical sign of the number\00"
@str.5 = [53 x i8] c"Cannot compute the square root of a negative number!\00"
@str.6 = [90 x i8] c"The number that you have entered is not right,Please enter the number in your mind again!\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
store float 0.000000e+00, float* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 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 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0, %6
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str.6, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %6, label %10
10: ; preds = %6, %0
%11 = load float, float* %1
%12 = fcmp olt float %11, 0.000000e+00
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = fsub float 1.000000e+00, %11
%15 = call i32 @fabs(float %14)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %19, label %32
17: ; preds = %10
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.5, i64 0, i64 0))
br label %32
19: ; preds = %13, %19
%20 = phi float [ %24, %19 ], [ 1.000000e+00, %13 ]
%21 = load float, float* %1
%22 = fdiv float %21, %20
%23 = fadd float %20, %22
%24 = fmul float %23, 5.000000e-01
%25 = fpext float %24 to double
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), double %25)
%27 = load float, float* %1
%28 = fneg float %27
%29 = call float @llvm.fmuladd.f32(float %24, float %24, float %28)
%30 = call i32 @fabs(float %29)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %19, label %32
32: ; preds = %19, %13, %17
ret i32 0
}