#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 *);
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 = (x0 * x0 - 6);
    error = fabs(x1 - x0);
    if (count == 0) {
      if ((2 * x0) > 1 || (2 * x0) < -1 || (2 * x0) == 0) {
        printf("\nThe equation is not convergent\n");
        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.0005 && 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    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
movss  -0xc(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  0xe6a(%rip),%xmm1
addss  %xmm1,%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    1250 <main+0x120>
movss  0xe43(%rip),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  0xe32(%rip),%xmm1
ucomiss %xmm1,%xmm0
ja     1218 <main+0xe8>
movss  0xe25(%rip),%xmm1
mulss  -0xc(%rbp),%xmm1
movss  0xe1c(%rip),%xmm0
ucomiss %xmm1,%xmm0
ja     1218 <main+0xe8>
movss  0xe07(%rip),%xmm0
mulss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    122f <main+0xff>
jp     122f <main+0xff>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x1,-0x15(%rbp)
jmp    132d <main+0x1fd>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1250 <main+0x120>
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  0xd80(%rip),%xmm1
subss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    12b4 <main+0x184>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
jmp    12be <main+0x18e>
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    0xdd9(%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  0xd10(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jbe    1322 <main+0x1f2>
cmpl   $0x3e8,-0x8(%rbp)
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1180 <main+0x50>
cmpb   $0x0,-0x15(%rbp)
jne    134e <main+0x21e>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd86(%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    0xede(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef1(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
movss  0x8(%rsp),%xmm1
lea    0xedd(%rip),%r14
lea    0xef8(%rip),%r15
lea    0xf1e(%rip),%r12
xor    %ebx,%ebx
movaps %xmm1,%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mulss  %xmm2,%xmm2
addss  0xe64(%rip),%xmm2
movaps %xmm2,%xmm3
subss  %xmm1,%xmm3
andps  0xe66(%rip),%xmm3
test   %ebx,%ebx
movss  %xmm2,0xc(%rsp)
movaps %xmm3,0x10(%rsp)
je     11c0 <main+0x90>
movaps %xmm3,%xmm2
jmp    120e <main+0xde>
xchg   %ax,%ax
addss  %xmm1,%xmm1
ucomiss 0xe41(%rip),%xmm1
jne    11d3 <main+0xa3>
jnp    1289 <main+0x159>
ucomiss 0xe2a(%rip),%xmm1
ja     1289 <main+0x159>
movss  0xe20(%rip),%xmm0
ucomiss %xmm1,%xmm0
ja     1289 <main+0x159>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xorps  %xmm2,%xmm2
movss  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
movaps %xmm1,%xmm3
mulss  %xmm1,%xmm3
subss  %xmm1,%xmm3
addss  0xdd8(%rip),%xmm3
xorps  %xmm1,%xmm1
cvtss2sd %xmm3,%xmm1
cvtss2sd %xmm2,%xmm2
mov    %r12,%rdi
mov    %ebx,%esi
mov    $0x3,%al
call   1040 <printf@plt>
movss  0xc(%rsp),%xmm2
movss  %xmm2,0x8(%rsp)
movaps 0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
ucomisd 0xdc4(%rip),%xmm0
jbe    1272 <main+0x142>
lea    0x1(%rbx),%eax
movaps %xmm2,%xmm1
cmp    $0x3e7,%ebx
mov    %eax,%ebx
jb     1190 <main+0x60>
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
lea    0xe34(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1295 <main+0x165>
lea    0xe3f(%rip),%rdi
call   1030 <puts@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 = [33 x i8] c"\0AThe equation is not convergent\0A\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 = %67, %0
%10 = load float, float* %3
%11 = load float, float* %3
%12 = call float @llvm.fmuladd.f32(float %10, float %11, float -6.000000e+00)
store float %12, float* %4
%13 = load float, float* %4
%14 = load float, float* %3
%15 = fsub float %13, %14
%16 = call float @fabs(float %15)
store float %16, float* %5
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %9
%20 = load float, float* %3
%21 = fmul float 2.000000e+00, %20
%22 = fcmp ogt float %21, 1.000000e+00
br i1 %22, label %31, label %23
23: ; preds = %19
%24 = load float, float* %3
%25 = fmul float 2.000000e+00, %24
%26 = fcmp olt float %25, -1.000000e+00
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load float, float* %3
%29 = fmul float 2.000000e+00, %28
%30 = fcmp oeq float %29, 0.000000e+00
br i1 %30, label %31, label %33
31: ; preds = %27, %23, %19
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i8 1, i8* %6
br label %69
33: ; preds = %27
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %33
br label %37
37: ; preds = %36, %9
%38 = load i32, i32* %2
%39 = load float, float* %3
%40 = fpext float %39 to double
%41 = load float, float* %3
%42 = load float, float* %3
%43 = load float, float* %3
%44 = fneg float %43
%45 = call float @llvm.fmuladd.f32(float %41, float %42, float %44)
%46 = fsub float %45, 6.000000e+00
%47 = fpext float %46 to double
%48 = load i32, i32* %2
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %37
br label %53
51: ; preds = %37
%52 = load float, float* %5
br label %53
53: ; preds = %51, %50
%54 = phi float [ 0.000000e+00, %50 ], [ %52, %51 ]
%55 = fpext float %54 to double
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %38, double %40, double %47, double %55)
%57 = load float, float* %4
store float %57, float* %3
%58 = load i32, i32* %2
%59 = add nsw i32 %58, 1
store i32 %59, i32* %2
br label %60
60: ; preds = %53
%61 = load float, float* %5
%62 = fpext float %61 to double
%63 = fcmp ogt double %62, 5.000000e-04
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i32, i32* %2
%66 = icmp slt i32 %65, 1000
br label %67
67: ; preds = %64, %60
%68 = phi i1 [ false, %60 ], [ %66, %64 ]
br i1 %68, label %9, label %69
69: ; preds = %67, %31
%70 = load i8, i8* %6
%71 = icmp ne i8 %70, 0
br i1 %71, label %76, label %72
72: ; preds = %69
%73 = load float, float* %3
%74 = fpext float %73 to double
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), double %74)
br label %76
76: ; preds = %72, %69
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.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"
@str = [32 x i8] c"\0AThe equation is not convergent\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 = %26, %0
%7 = phi float [ %5, %0 ], [ %9, %26 ]
%8 = phi i32 [ 0, %0 ], [ %36, %26 ]
%9 = call float @llvm.fmuladd.f32(float %7, float %7, float -6.000000e+00)
%10 = fsub float %9, %7
%11 = call float @llvm.fabs.f32(float %10)
%12 = icmp eq i32 %8, 0
br i1 %12, label %13, label %26
13: ; preds = %6
%14 = fmul float %7, 2.000000e+00
%15 = fcmp ogt float %14, 1.000000e+00
%16 = fcmp olt float %14, -1.000000e+00
%17 = or i1 %15, %16
%18 = fcmp oeq float %14, 0.000000e+00
%19 = or i1 %18, %17
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %44
22: ; preds = %13
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%25 = load float, float* %1
br label %26
26: ; preds = %22, %6
%27 = phi float [ %25, %22 ], [ %7, %6 ]
%28 = phi float [ 0.000000e+00, %22 ], [ %11, %6 ]
%29 = fpext float %27 to double
%30 = fneg float %27
%31 = call float @llvm.fmuladd.f32(float %27, float %27, float %30)
%32 = fadd float %31, -6.000000e+00
%33 = fpext float %32 to double
%34 = fpext float %28 to double
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %8, double %29, double %33, double %34)
store float %9, float* %1
%36 = add nuw nsw i32 %8, 1
%37 = fpext float %11 to double
%38 = fcmp ogt double %37, 5.000000e-04
%39 = icmp ult i32 %8, 999
%40 = select i1 %38, i1 %39, i1 false
br i1 %40, label %6, label %41
41: ; preds = %26
%42 = fpext float %9 to double
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), double %42)
br label %44
44: ; preds = %20, %41
ret i32 0
}