#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 */
float fabs(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
double sqrt(float);
int main() {
  int count = 0;
  float x0 = 0, x1 = 0, error = 0;
  char iffound = 0;
  printf("Please enter the initial value: ");
  scanf("%f", &x0);
  do {
    x1 = sqrt(x0 + 6);
    error = fabs(x1 - x0);
    if (count == 0) {
      if ((0.5 / sqrt(x0 + 6)) > 1) {
        printf("\nThe equation is not convergent");
        iffound = 1;
        break;
      } else {
        printf("\n   i	  xi	  f(xi)	         error");
        printf("\n-------------------------------------------");
      }
    }
    printf("\n %3d	%3.5f	 %3.5f	%3.5f", count, x0, (x0 * x0 - x0 - 6),
           count == 0 ? 0 : error);
    x0 = x1;
    count++;
  } while (error > 0.000001 && count < 1000);
  if (!iffound)
    printf("\nThe required root is: %f\n", x0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeba(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
movss  0xe68(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
call   1060 <sqrt@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
call   1040 <fabs@plt>
movss  %xmm0,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1234 <main+0xf4>
movss  0xe2f(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe2a(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  0xe16(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1213 <main+0xd3>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x1,-0x15(%rbp)
jmp    1311 <main+0x1d1>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1234 <main+0xf4>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  0xd8c(%rip),%xmm1
subss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1298 <main+0x158>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
jmp    12a2 <main+0x162>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
mov    -0x2c(%rbp),%esi
movss  -0x30(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xdf4(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xor    %eax,%eax
movsd  0xd2c(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jbe    1306 <main+0x1c6>
cmpl   $0x3e8,-0x8(%rbp)
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1190 <main+0x50>
cmpb   $0x0,-0x15(%rbp)
jne    1332 <main+0x1f2>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xda1(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
movl   $0x0,0x8(%rsp)
lea    0xeee(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf01(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
movss  0x8(%rsp),%xmm1
movss  0xe90(%rip),%xmm0
lea    0xf05(%rip),%r14
lea    0xf20(%rip),%r15
lea    0xf46(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
addss  %xmm0,%xmm1
movaps %xmm1,%xmm0
call   1050 <sqrt@plt>
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
movss  0x8(%rsp),%xmm0
movss  %xmm1,0xc(%rsp)
subss  %xmm0,%xmm1
andps  0xe56(%rip),%xmm1
test   %ebx,%ebx
movaps %xmm1,0x10(%rsp)
je     11d0 <main+0xa0>
movaps %xmm1,%xmm2
jmp    1214 <main+0xe4>
nopl   0x0(%rax,%rax,1)
addss  0xe28(%rip),%xmm0
call   1050 <sqrt@plt>
movsd  0xe3b(%rip),%xmm1
divsd  %xmm0,%xmm1
ucomisd 0xe37(%rip),%xmm1
ja     1294 <main+0x164>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xorps  %xmm2,%xmm2
movss  0x8(%rsp),%xmm0
xorps  %xmm3,%xmm3
cvtss2sd %xmm0,%xmm3
movaps %xmm0,%xmm1
mulss  %xmm0,%xmm1
subss  %xmm0,%xmm1
addss  0xdd6(%rip),%xmm1
cvtss2sd %xmm1,%xmm1
cvtss2sd %xmm2,%xmm2
mov    %r12,%rdi
mov    %ebx,%esi
movaps %xmm3,%xmm0
mov    $0x3,%al
call   1030 <printf@plt>
movss  0xc(%rsp),%xmm1
movss  %xmm1,0x8(%rsp)
movaps 0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
ucomisd 0xdce(%rip),%xmm0
movss  0xd96(%rip),%xmm0
jbe    127d <main+0x14d>
lea    0x1(%rbx),%eax
cmp    $0x3e7,%ebx
mov    %eax,%ebx
jb     1190 <main+0x60>
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe59(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12a2 <main+0x172>
lea    0xdc1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Please enter the initial value: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [32 x i8] c"\0AThe equation is not convergent\00"
@.str.3 = [34 x i8] c"\0A i\09 xi\09 f(xi)\09 error\00"
@.str.4 = [45 x i8] c"\0A-------------------------------------------\00"
@.str.5 = [25 x i8] c"\0A %3d\09%3.5f\09 %3.5f\09%3.5f\00"
@.str.6 = [27 x i8] c"\0AThe required root is: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
store float 0.000000e+00, float* %3
store float 0.000000e+00, float* %4
store float 0.000000e+00, float* %5
store i8 0, i8* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %3)
br label %9
9: ; preds = %62, %0
%10 = load float, float* %3
%11 = fadd float %10, 6.000000e+00
%12 = call double @sqrt(float %11)
%13 = fptrunc double %12 to float
store float %13, float* %4
%14 = load float, float* %4
%15 = load float, float* %3
%16 = fsub float %14, %15
%17 = call float @fabs(float %16)
store float %17, float* %5
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %9
%21 = load float, float* %3
%22 = fadd float %21, 6.000000e+00
%23 = call double @sqrt(float %22)
%24 = fdiv double 5.000000e-01, %23
%25 = fcmp ogt double %24, 1.000000e+00
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i8 1, i8* %6
br label %64
28: ; preds = %20
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %28
br label %32
32: ; preds = %31, %9
%33 = load i32, i32* %2
%34 = load float, float* %3
%35 = fpext float %34 to double
%36 = load float, float* %3
%37 = load float, float* %3
%38 = load float, float* %3
%39 = fneg float %38
%40 = call float @llvm.fmuladd.f32(float %36, float %37, float %39)
%41 = fsub float %40, 6.000000e+00
%42 = fpext float %41 to double
%43 = load i32, i32* %2
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %32
br label %48
46: ; preds = %32
%47 = load float, float* %5
br label %48
48: ; preds = %46, %45
%49 = phi float [ 0.000000e+00, %45 ], [ %47, %46 ]
%50 = fpext float %49 to double
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %33, double %35, double %42, double %50)
%52 = load float, float* %4
store float %52, float* %3
%53 = load i32, i32* %2
%54 = add nsw i32 %53, 1
store i32 %54, i32* %2
br label %55
55: ; preds = %48
%56 = load float, float* %5
%57 = fpext float %56 to double
%58 = fcmp ogt double %57, 0x3EB0C6F7A0B5ED8D
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = load i32, i32* %2
%61 = icmp slt i32 %60, 1000
br label %62
62: ; preds = %59, %55
%63 = phi i1 [ false, %55 ], [ %61, %59 ]
br i1 %63, label %9, label %64
64: ; preds = %62, %26
%65 = load i8, i8* %6
%66 = icmp ne i8 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %64
%68 = load float, float* %3
%69 = fpext float %68 to double
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), double %69)
br label %71
71: ; preds = %67, %64
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"Please enter the initial value: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [32 x i8] c"\0AThe equation is not convergent\00"
@.str.3 = [34 x i8] c"\0A i\09 xi\09 f(xi)\09 error\00"
@.str.4 = [45 x i8] c"\0A-------------------------------------------\00"
@.str.5 = [25 x i8] c"\0A %3d\09%3.5f\09 %3.5f\09%3.5f\00"
@.str.6 = [27 x i8] c"\0AThe required root is: %f\0A\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
store float 0.000000e+00, float* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 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
br label %6
6: ; preds = %27, %0
%7 = phi float [ %5, %0 ], [ %11, %27 ]
%8 = phi i32 [ 0, %0 ], [ %37, %27 ]
%9 = fadd float %7, 6.000000e+00
%10 = call double @sqrt(float %9)
%11 = fptrunc double %10 to float
%12 = load float, float* %1
%13 = fsub float %11, %12
%14 = call float @llvm.fabs.f32(float %13)
%15 = icmp eq i32 %8, 0
br i1 %15, label %16, label %27
16: ; preds = %6
%17 = fadd float %12, 6.000000e+00
%18 = call double @sqrt(float %17)
%19 = fdiv double 5.000000e-01, %18
%20 = fcmp ogt double %19, 1.000000e+00
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %45
23: ; preds = %16
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%26 = load float, float* %1
br label %27
27: ; preds = %23, %6
%28 = phi float [ %26, %23 ], [ %12, %6 ]
%29 = phi float [ 0.000000e+00, %23 ], [ %14, %6 ]
%30 = fpext float %28 to double
%31 = fneg float %28
%32 = call float @llvm.fmuladd.f32(float %28, float %28, float %31)
%33 = fadd float %32, -6.000000e+00
%34 = fpext float %33 to double
%35 = fpext float %29 to double
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %8, double %30, double %34, double %35)
store float %11, float* %1
%37 = add nuw nsw i32 %8, 1
%38 = fpext float %14 to double
%39 = fcmp ogt double %38, 0x3EB0C6F7A0B5ED8D
%40 = icmp ult i32 %8, 999
%41 = select i1 %39, i1 %40, i1 false
br i1 %41, label %6, label %42
42: ; preds = %27
%43 = fpext float %11 to double
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), double %43)
br label %45
45: ; preds = %21, %42
ret i32 0
}