#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) {
        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 < 5000);
  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    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec2(%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    1213 <main+0xe3>
movss  0xe43(%rip),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  0xe32(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    11f2 <main+0xc2>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x1,-0x15(%rbp)
jmp    12f0 <main+0x1c0>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1213 <main+0xe3>
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  0xdb9(%rip),%xmm1
subss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1277 <main+0x147>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
jmp    1281 <main+0x151>
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    0xe0e(%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  0xd45(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jbe    12e5 <main+0x1b5>
cmpl   $0x1388,-0x8(%rbp)
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1180 <main+0x50>
cmpb   $0x0,-0x15(%rbp)
jne    1311 <main+0x1e1>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdbb(%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,%xmm0
subss  %xmm1,%xmm0
andps  0xe66(%rip),%xmm0
test   %ebx,%ebx
movss  %xmm2,0xc(%rsp)
movaps %xmm0,0x10(%rsp)
je     11c0 <main+0x90>
movaps %xmm0,%xmm2
jmp    11ee <main+0xbe>
xchg   %ax,%ax
addss  %xmm1,%xmm1
ucomiss 0xe39(%rip),%xmm1
ja     1269 <main+0x139>
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  0xdf8(%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 0xde4(%rip),%xmm0
jbe    1252 <main+0x122>
lea    0x1(%rbx),%eax
movaps %xmm2,%xmm1
cmp    $0x1387,%ebx
mov    %eax,%ebx
jb     1190 <main+0x60>
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
lea    0xe54(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1275 <main+0x145>
lea    0xe5f(%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 = %59, %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 %29
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 %23, label %25
23: ; preds = %19
%24 = 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 %61
25: ; preds = %19
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %25
br label %29
29: ; preds = %28, %9
%30 = load i32, i32* %2
%31 = load float, float* %3
%32 = fpext float %31 to double
%33 = load float, float* %3
%34 = load float, float* %3
%35 = load float, float* %3
%36 = fneg float %35
%37 = call float @llvm.fmuladd.f32(float %33, float %34, float %36)
%38 = fsub float %37, 6.000000e+00
%39 = fpext float %38 to double
%40 = load i32, i32* %2
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %29
br label %45
43: ; preds = %29
%44 = load float, float* %5
br label %45
45: ; preds = %43, %42
%46 = phi float [ 0.000000e+00, %42 ], [ %44, %43 ]
%47 = fpext float %46 to double
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %30, double %32, double %39, double %47)
%49 = load float, float* %4
store float %49, float* %3
%50 = load i32, i32* %2
%51 = add nsw i32 %50, 1
store i32 %51, i32* %2
br label %52
52: ; preds = %45
%53 = load float, float* %5
%54 = fpext float %53 to double
%55 = fcmp ogt double %54, 5.000000e-04
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = load i32, i32* %2
%58 = icmp slt i32 %57, 5000
br label %59
59: ; preds = %56, %52
%60 = phi i1 [ false, %52 ], [ %58, %56 ]
br i1 %60, label %9, label %61
61: ; preds = %59, %23
%62 = load i8, i8* %6
%63 = icmp ne i8 %62, 0
br i1 %63, label %68, label %64
64: ; preds = %61
%65 = load float, float* %3
%66 = fpext float %65 to double
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), double %66)
br label %68
68: ; preds = %64, %61
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 = %22, %0
%7 = phi float [ %5, %0 ], [ %9, %22 ]
%8 = phi i32 [ 0, %0 ], [ %32, %22 ]
%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 %22
13: ; preds = %6
%14 = fmul float %7, 2.000000e+00
%15 = fcmp ogt float %14, 1.000000e+00
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %40
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%21 = load float, float* %1
br label %22
22: ; preds = %18, %6
%23 = phi float [ %21, %18 ], [ %7, %6 ]
%24 = phi float [ 0.000000e+00, %18 ], [ %11, %6 ]
%25 = fpext float %23 to double
%26 = fneg float %23
%27 = call float @llvm.fmuladd.f32(float %23, float %23, float %26)
%28 = fadd float %27, -6.000000e+00
%29 = fpext float %28 to double
%30 = fpext float %24 to double
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %8, double %25, double %29, double %30)
store float %9, float* %1
%32 = add nuw nsw i32 %8, 1
%33 = fpext float %11 to double
%34 = fcmp ogt double %33, 5.000000e-04
%35 = icmp ult i32 %8, 4999
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %6, label %37
37: ; preds = %22
%38 = fpext float %9 to double
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), double %38)
br label %40
40: ; preds = %16, %37
ret i32 0
}