#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 */
double FunctionalValue(double);
double G(double);
double fabs(double);
double log(double);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  double oldR = 1;
  double newR;
  double diff;
  double oldAbsError, newAbsError;
  int i = 0;
  printf("Solution of e^x - 4x^2 = 0 using fixed point iteration\n");
  printf("Initial Approximation: 1\n");
  printf("i\tRoot\t\tG'(Root)\tF(Root)\t\tAbsoluteError\torderOfConvergence\n",
         newAbsError, log(newAbsError) / log(oldAbsError));
  do {
    newR = G(oldR);
    diff = newR / 2;
    newAbsError = fabs(newR - oldR);
    printf("%d\t%f\t%f\t%f\t%f\t%f\n", i, oldR, diff, FunctionalValue(oldR),
           newAbsError, log(newAbsError) / log(oldAbsError));
    oldAbsError = newAbsError;
    i++;
    oldR = newR;
  } while (newAbsError > 0.000001);
  printf("Final Answer: %f\n", oldR);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xea6(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeed(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1060 <log@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
divsd  %xmm2,%xmm1
lea    0xec5(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x10(%rbp),%xmm0
call   1050 <G@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe28(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movaps 0xe26(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x6c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <FunctionalValue@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1060 <log@plt>
movsd  -0x78(%rbp),%xmm4
mov    -0x6c(%rbp),%esi
movsd  -0x68(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm3
movaps %xmm0,%xmm5
movsd  -0x50(%rbp),%xmm0
divsd  %xmm5,%xmm4
lea    0xe45(%rip),%rdi
mov    $0x5,%al
call   1040 <printf@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xd66(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     11c4 <main+0x84>
movsd  -0x10(%rbp),%xmm0
lea    0xe11(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xef7(%rip),%rdi
call   1030 <puts@plt>
lea    0xf22(%rip),%rdi
call   1030 <puts@plt>
lea    0xf2f(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
movsd  0xe7b(%rip),%xmm0
lea    0xea4(%rip),%r14
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
call   1060 <G@plt>
movsd  %xmm0,0x38(%rsp)
movapd %xmm0,%xmm1
mulsd  0xe5b(%rip),%xmm1
movsd  %xmm1,0x30(%rsp)
movapd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm0,%xmm1
andpd  0xe57(%rip),%xmm1
movapd %xmm1,0x10(%rsp)
call   1040 <FunctionalValue@plt>
movsd  %xmm0,0x28(%rsp)
movaps 0x10(%rsp),%xmm0
call   1070 <log@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x40(%rsp),%xmm0
call   1070 <log@plt>
movsd  0x20(%rsp),%xmm4
divsd  %xmm0,%xmm4
mov    %r14,%rdi
mov    %ebx,%esi
movsd  0x8(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
movsd  0x28(%rsp),%xmm2
movaps 0x10(%rsp),%xmm3
mov    $0x5,%al
call   1050 <printf@plt>
movsd  0x38(%rsp),%xmm0
add    $0x1,%ebx
movapd 0x10(%rsp),%xmm1
ucomisd 0xdd7(%rip),%xmm1
movsd  %xmm1,0x40(%rsp)
ja     1190 <main+0x40>
lea    0xdf7(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [56 x i8] c"Solution of e^x - 4x^2 = 0 using fixed point iteration\0A\00"
@.str.1 = [26 x i8] c"Initial Approximation: 1\0A\00"
@.str.2 = [60 x i8] c"i\09Root\09\09G'(Root)\09F(Root)\09\09AbsoluteError\09orderOfConvergence\0A\00"
@.str.3 = [19 x i8] c"%d\09%f\09%f\09%f\09%f\09%f\0A\00"
@.str.4 = [18 x i8] c"Final Answer: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store i32 0, i32* %1
store double 1.000000e+00, double* %2
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%10 = load double, double* %6
%11 = load double, double* %6
%12 = call double @log(double %11)
%13 = load double, double* %5
%14 = call double @log(double %13)
%15 = fdiv double %12, %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), double %10, double %15)
br label %17
17: ; preds = %42, %0
%18 = load double, double* %2
%19 = call double @G(double %18)
store double %19, double* %3
%20 = load double, double* %3
%21 = fdiv double %20, 2.000000e+00
store double %21, double* %4
%22 = load double, double* %3
%23 = load double, double* %2
%24 = fsub double %22, %23
%25 = call double @llvm.fabs.f64(double %24)
store double %25, double* %6
%26 = load i32, i32* %7
%27 = load double, double* %2
%28 = load double, double* %4
%29 = load double, double* %2
%30 = call double @FunctionalValue(double %29)
%31 = load double, double* %6
%32 = load double, double* %6
%33 = call double @log(double %32)
%34 = load double, double* %5
%35 = call double @log(double %34)
%36 = fdiv double %33, %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %26, double %27, double %28, double %30, double %31, double %36)
%38 = load double, double* %6
store double %38, double* %5
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
%41 = load double, double* %3
store double %41, double* %2
br label %42
42: ; preds = %17
%43 = load double, double* %6
%44 = fcmp ogt double %43, 0x3EB0C6F7A0B5ED8D
br i1 %44, label %17, label %45
45: ; preds = %42
%46 = load double, double* %2
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), double %46)
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [19 x i8] c"%d\09%f\09%f\09%f\09%f\09%f\0A\00"
@.str.4 = [18 x i8] c"Final Answer: %f\0A\00"
@str = [55 x i8] c"Solution of e^x - 4x^2 = 0 using fixed point iteration\00"
@str.5 = [25 x i8] c"Initial Approximation: 1\00"
@str.6 = [59 x i8] c"i\09Root\09\09G'(Root)\09F(Root)\09\09AbsoluteError\09orderOfConvergence\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.6, i64 0, i64 0))
br label %4
4: ; preds = %4, %0
%5 = phi double [ 1.000000e+00, %0 ], [ %8, %4 ]
%6 = phi double [ undef, %0 ], [ %11, %4 ]
%7 = phi i32 [ 0, %0 ], [ %17, %4 ]
%8 = tail call double @G(double %5)
%9 = fmul double %8, 5.000000e-01
%10 = fsub double %8, %5
%11 = tail call double @llvm.fabs.f64(double %10)
%12 = tail call double @FunctionalValue(double %5)
%13 = tail call double @log(double %11)
%14 = tail call double @log(double %6)
%15 = fdiv double %13, %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %7, double %5, double %9, double %12, double %11, double %15)
%17 = add nuw nsw i32 %7, 1
%18 = fcmp ogt double %11, 0x3EB0C6F7A0B5ED8D
br i1 %18, label %4, label %19
19: ; preds = %4
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), double %8)
ret i32 0
}