#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 = ((-1) * 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    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebe(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
movss  0xe88(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe53(%rip),%xmm0
mulsd  %xmm1,%xmm0
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    1243 <main+0x103>
movss  0xe40(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe1b(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  0xe07(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1222 <main+0xe2>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x1,-0x15(%rbp)
jmp    1320 <main+0x1e0>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1243 <main+0x103>
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  0xd9d(%rip),%xmm1
subss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    12a7 <main+0x167>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
jmp    12b1 <main+0x171>
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    0xde9(%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  0xd1d(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jbe    1315 <main+0x1d5>
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    1341 <main+0x201>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd96(%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    $0x38,%rsp
movl   $0x0,0xc(%rsp)
lea    0xefe(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf11(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
movss  0xc(%rsp),%xmm1
movss  0xe90(%rip),%xmm0
lea    0xf15(%rip),%r14
lea    0xf30(%rip),%r15
lea    0xf56(%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
xorps  0xe66(%rip),%xmm1
movss  0xc(%rsp),%xmm0
movaps %xmm1,0x20(%rsp)
subss  %xmm0,%xmm1
andps  0xe60(%rip),%xmm1
test   %ebx,%ebx
movaps %xmm1,0x10(%rsp)
je     11d0 <main+0xa0>
movaps %xmm1,%xmm2
jmp    1214 <main+0xe4>
xchg   %ax,%ax
addss  0xe28(%rip),%xmm0
call   1050 <sqrt@plt>
movsd  0xe4b(%rip),%xmm1
divsd  %xmm0,%xmm1
ucomisd 0xe47(%rip),%xmm1
ja     1293 <main+0x163>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xorps  %xmm2,%xmm2
movss  0xc(%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>
movaps 0x20(%rsp),%xmm1
movss  %xmm1,0xc(%rsp)
movaps 0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
ucomisd 0xddf(%rip),%xmm0
movss  0xd97(%rip),%xmm0
jbe    127c <main+0x14c>
lea    0x1(%rbx),%eax
cmp    $0x3e7,%ebx
mov    %eax,%ebx
jb     1190 <main+0x60>
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe6a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12a1 <main+0x171>
lea    0xdd2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%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 = %63, %0
%10 = load float, float* %3
%11 = fadd float %10, 6.000000e+00
%12 = call double @sqrt(float %11)
%13 = fmul double -1.000000e+00, %12
%14 = fptrunc double %13 to float
store float %14, float* %4
%15 = load float, float* %4
%16 = load float, float* %3
%17 = fsub float %15, %16
%18 = call float @fabs(float %17)
store float %18, float* %5
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %9
%22 = load float, float* %3
%23 = fadd float %22, 6.000000e+00
%24 = call double @sqrt(float %23)
%25 = fdiv double -5.000000e-01, %24
%26 = fcmp ogt double %25, 1.000000e+00
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = 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 %65
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %29
br label %33
33: ; preds = %32, %9
%34 = load i32, i32* %2
%35 = load float, float* %3
%36 = fpext float %35 to double
%37 = load float, float* %3
%38 = load float, float* %3
%39 = load float, float* %3
%40 = fneg float %39
%41 = call float @llvm.fmuladd.f32(float %37, float %38, float %40)
%42 = fsub float %41, 6.000000e+00
%43 = fpext float %42 to double
%44 = load i32, i32* %2
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %33
br label %49
47: ; preds = %33
%48 = load float, float* %5
br label %49
49: ; preds = %47, %46
%50 = phi float [ 0.000000e+00, %46 ], [ %48, %47 ]
%51 = fpext float %50 to double
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %34, double %36, double %43, double %51)
%53 = load float, float* %4
store float %53, float* %3
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
br label %56
56: ; preds = %49
%57 = load float, float* %5
%58 = fpext float %57 to double
%59 = fcmp ogt double %58, 0x3EB0C6F7A0B5ED8D
br i1 %59, label %60, label %63
60: ; preds = %56
%61 = load i32, i32* %2
%62 = icmp slt i32 %61, 1000
br label %63
63: ; preds = %60, %56
%64 = phi i1 [ false, %56 ], [ %62, %60 ]
br i1 %64, label %9, label %65
65: ; preds = %63, %27
%66 = load i8, i8* %6
%67 = icmp ne i8 %66, 0
br i1 %67, label %72, label %68
68: ; preds = %65
%69 = load float, float* %3
%70 = fpext float %69 to double
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), double %70)
br label %72
72: ; preds = %68, %65
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 = %28, %0
%7 = phi float [ %5, %0 ], [ %12, %28 ]
%8 = phi i32 [ 0, %0 ], [ %38, %28 ]
%9 = fadd float %7, 6.000000e+00
%10 = call double @sqrt(float %9)
%11 = fptrunc double %10 to float
%12 = fneg float %11
%13 = load float, float* %1
%14 = fsub float %12, %13
%15 = call float @llvm.fabs.f32(float %14)
%16 = icmp eq i32 %8, 0
br i1 %16, label %17, label %28
17: ; preds = %6
%18 = fadd float %13, 6.000000e+00
%19 = call double @sqrt(float %18)
%20 = fdiv double -5.000000e-01, %19
%21 = fcmp ogt double %20, 1.000000e+00
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %46
24: ; preds = %17
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%27 = load float, float* %1
br label %28
28: ; preds = %24, %6
%29 = phi float [ %27, %24 ], [ %13, %6 ]
%30 = phi float [ 0.000000e+00, %24 ], [ %15, %6 ]
%31 = fpext float %29 to double
%32 = fneg float %29
%33 = call float @llvm.fmuladd.f32(float %29, float %29, float %32)
%34 = fadd float %33, -6.000000e+00
%35 = fpext float %34 to double
%36 = fpext float %30 to double
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %8, double %31, double %35, double %36)
store float %12, float* %1
%38 = add nuw nsw i32 %8, 1
%39 = fpext float %15 to double
%40 = fcmp ogt double %39, 0x3EB0C6F7A0B5ED8D
%41 = icmp ult i32 %8, 999
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %6, label %43
43: ; preds = %28
%44 = fpext float %12 to double
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), double %44)
br label %46
46: ; preds = %22, %43
ret i32 0
}