#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 f(double);
double fabs(double);
double log(double);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  printf("Solution of e^x = 2x +1 using secants method\n");
  printf("Initial guess: 1\n");
  double veryOldRoot = 1, oldRoot = 3, newRoot;
  double oldError = 2;
  double newError;
  int i = 0;
  printf("i\tRoot\t\tf(Root)\t\tError\t\torder of convergence\n", i++, newRoot,
         f(newRoot), newError, log(newError) / log(oldError));
  do {
    newRoot = ((veryOldRoot * f(oldRoot) - oldRoot * f(veryOldRoot)) /
               (f(oldRoot) - f(veryOldRoot)));
    newError = fabs(newRoot - oldRoot);
    printf("%d\t%f\t%f\t%f\t%f\n", i++, newRoot, f(newRoot), newError,
           log(newError) / log(oldError));
    veryOldRoot = oldRoot;
    oldRoot = newRoot;
    oldError = newError;
  } while ((f(newRoot) != 0) || (fabs(newRoot - oldRoot) > 0.000001));
  printf("\n\nFinal Answer:%f\n", newRoot);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xee7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  0xeaa(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe95(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe80(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x54(%rbp)
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x60(%rbp),%xmm3
mov    -0x54(%rbp),%esi
movsd  -0x50(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
movaps %xmm0,%xmm4
movsd  -0x40(%rbp),%xmm0
divsd  %xmm4,%xmm3
lea    0xe77(%rip),%rdi
mov    $0x4,%al
call   1040 <printf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x18(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x10(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0xb0(%rbp),%xmm1
ff
movsd  -0xa8(%rbp),%xmm2
ff
movaps %xmm0,%xmm3
movsd  -0xa0(%rbp),%xmm0
ff
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x18(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x10(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x98(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0x90(%rbp),%xmm0
ff
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xd57(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x7c(%rbp)
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x88(%rbp),%xmm3
ff
mov    -0x7c(%rbp),%esi
movsd  -0x78(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm2
movaps %xmm0,%xmm4
movsd  -0x68(%rbp),%xmm0
divsd  %xmm4,%xmm3
lea    0xd59(%rip),%rdi
mov    $0x4,%al
call   1040 <printf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <f@plt>
mov    $0x1,%al
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0xb1(%rbp)
jne    13b9 <main+0x289>
jp     13b9 <main+0x289>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xc80(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xc6c(%rip),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0xb1(%rbp)
mov    -0xb1(%rbp),%al
test   $0x1,%al
jne    1200 <main+0xd0>
movsd  -0x20(%rbp),%xmm0
lea    0xcdb(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xf15(%rip),%rdi
call   1030 <puts@plt>
lea    0xf36(%rip),%rdi
call   1030 <puts@plt>
call   1040 <f@plt>
lea    0xf36(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
movsd  0xe83(%rip),%xmm0
movsd  %xmm0,0x38(%rsp)
movsd  0xe7d(%rip),%xmm0
movsd  0xe7d(%rip),%xmm1
movsd  %xmm1,0x10(%rsp)
lea    0xea0(%rip),%r14
jmp    11ce <main+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebx
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movapd %xmm1,%xmm0
movaps 0x20(%rsp),%xmm1
movsd  %xmm1,0x38(%rsp)
movsd  %xmm0,0x18(%rsp)
call   1040 <f@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x18(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm2
mulsd  0x10(%rsp),%xmm2
subsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
movapd %xmm1,%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x20(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm0,%xmm1
subsd  0x18(%rsp),%xmm1
andpd  0xde0(%rip),%xmm1
movapd %xmm1,0x20(%rsp)
call   1040 <f@plt>
movsd  %xmm0,0x10(%rsp)
movaps 0x20(%rsp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x40(%rsp)
movsd  0x38(%rsp),%xmm0
call   1060 <log@plt>
movsd  0x40(%rsp),%xmm3
divsd  %xmm0,%xmm3
mov    %r14,%rdi
mov    %ebx,%esi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movaps 0x20(%rsp),%xmm2
mov    $0x4,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x8(%rsp),%xmm1
ucomisd 0xd64(%rip),%xmm0
jne    11b0 <main+0x70>
jp     11b0 <main+0x70>
movapd %xmm1,%xmm0
subsd  %xmm1,%xmm0
andpd  0xd58(%rip),%xmm0
ucomisd 0xd38(%rip),%xmm0
ja     11b0 <main+0x70>
lea    0xd63(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Solution of e^x = 2x +1 using secants method\0A\00"
@.str.1 = [18 x i8] c"Initial guess: 1\0A\00"
@.str.2 = [46 x i8] c"i\09Root\09\09f(Root)\09\09Error\09\09order of convergence\0A\00"
@.str.3 = [16 x i8] c"%d\09%f\09%f\09%f\09%f\0A\00"
@.str.4 = [19 x i8] c"\0A\0AFinal 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
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store double 1.000000e+00, double* %2
store double 3.000000e+00, double* %3
store double 2.000000e+00, double* %5
store i32 0, i32* %7
%10 = load i32, i32* %7
%11 = add nsw i32 %10, 1
store i32 %11, i32* %7
%12 = load double, double* %4
%13 = load double, double* %4
%14 = call double @f(double %13)
%15 = load double, double* %6
%16 = load double, double* %6
%17 = call double @log(double %16)
%18 = load double, double* %5
%19 = call double @log(double %18)
%20 = fdiv double %17, %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %10, double %12, double %14, double %15, double %20)
br label %22
22: ; preds = %67, %0
%23 = load double, double* %2
%24 = load double, double* %3
%25 = call double @f(double %24)
%26 = load double, double* %3
%27 = load double, double* %2
%28 = call double @f(double %27)
%29 = fmul double %26, %28
%30 = fneg double %29
%31 = call double @llvm.fmuladd.f64(double %23, double %25, double %30)
%32 = load double, double* %3
%33 = call double @f(double %32)
%34 = load double, double* %2
%35 = call double @f(double %34)
%36 = fsub double %33, %35
%37 = fdiv double %31, %36
store double %37, double* %4
%38 = load double, double* %4
%39 = load double, double* %3
%40 = fsub double %38, %39
%41 = call double @llvm.fabs.f64(double %40)
store double %41, double* %6
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
%44 = load double, double* %4
%45 = load double, double* %4
%46 = call double @f(double %45)
%47 = load double, double* %6
%48 = load double, double* %6
%49 = call double @log(double %48)
%50 = load double, double* %5
%51 = call double @log(double %50)
%52 = fdiv double %49, %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %42, double %44, double %46, double %47, double %52)
%54 = load double, double* %3
store double %54, double* %2
%55 = load double, double* %4
store double %55, double* %3
%56 = load double, double* %6
store double %56, double* %5
br label %57
57: ; preds = %22
%58 = load double, double* %4
%59 = call double @f(double %58)
%60 = fcmp une double %59, 0.000000e+00
br i1 %60, label %67, label %61
61: ; preds = %57
%62 = load double, double* %4
%63 = load double, double* %3
%64 = fsub double %62, %63
%65 = call double @llvm.fabs.f64(double %64)
%66 = fcmp ogt double %65, 0x3EB0C6F7A0B5ED8D
br label %67
67: ; preds = %61, %57
%68 = phi i1 [ true, %57 ], [ %66, %61 ]
br i1 %68, label %22, label %69
69: ; preds = %67
%70 = load double, double* %4
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), double %70)
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [16 x i8] c"%d\09%f\09%f\09%f\09%f\0A\00"
@.str.4 = [19 x i8] c"\0A\0AFinal Answer:%f\0A\00"
@str = [45 x i8] c"Solution of e^x = 2x +1 using secants method\00"
@str.5 = [17 x i8] c"Initial guess: 1\00"
@str.6 = [45 x i8] c"i\09Root\09\09f(Root)\09\09Error\09\09order of convergence\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%3 = tail call double @f(double undef)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.6, i64 0, i64 0))
br label %5
5: ; preds = %33, %0
%6 = phi double [ 1.000000e+00, %0 ], [ %7, %33 ]
%7 = phi double [ 3.000000e+00, %0 ], [ %18, %33 ]
%8 = phi double [ 2.000000e+00, %0 ], [ %20, %33 ]
%9 = phi i32 [ 1, %0 ], [ %21, %33 ]
%10 = tail call double @f(double %7)
%11 = tail call double @f(double %6)
%12 = fneg double %7
%13 = fmul double %11, %12
%14 = tail call double @llvm.fmuladd.f64(double %6, double %10, double %13)
%15 = tail call double @f(double %7)
%16 = tail call double @f(double %6)
%17 = fsub double %15, %16
%18 = fdiv double %14, %17
%19 = fsub double %18, %7
%20 = tail call double @llvm.fabs.f64(double %19)
%21 = add nuw nsw i32 %9, 1
%22 = tail call double @f(double %18)
%23 = tail call double @log(double %20)
%24 = tail call double @log(double %8)
%25 = fdiv double %23, %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %9, double %18, double %22, double %20, double %25)
%27 = tail call double @f(double %18)
%28 = fcmp une double %27, 0.000000e+00
br i1 %28, label %33, label %29
29: ; preds = %5
%30 = fsub double %18, %18
%31 = tail call double @llvm.fabs.f64(double %30)
%32 = fcmp ogt double %31, 0x3EB0C6F7A0B5ED8D
br i1 %32, label %33, label %34
33: ; preds = %29, %5
br label %5
34: ; preds = %29
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), double %18)
ret i32 0
}