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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  0xe95(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe80(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <diff@plt>
movsd  -0x68(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xe38(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x58(%rbp),%xmm3
mov    -0x4c(%rbp),%esi
movsd  -0x48(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movaps %xmm0,%xmm4
movsd  -0x38(%rbp),%xmm0
divsd  %xmm4,%xmm3
lea    0xe4e(%rip),%rdi
mov    $0x4,%al
call   1040 <printf@plt>
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movaps 0xdaa(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xd8e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1291 <main+0x151>
jmp    12aa <main+0x16a>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    119a <main+0x5a>
movsd  -0x10(%rbp),%xmm0
lea    0xe06(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xef5(%rip),%rdi
call   1030 <puts@plt>
lea    0xf1d(%rip),%rdi
call   1030 <puts@plt>
lea    0xf29(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
movsd  0xe7b(%rip),%xmm0
movsd  0xe7b(%rip),%xmm1
lea    0xe9c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm1,0x40(%rsp)
movsd  %xmm0,0x8(%rsp)
movapd %xmm0,0x20(%rsp)
call   1040 <f@plt>
movsd  %xmm0,0x10(%rsp)
movapd 0x20(%rsp),%xmm0
call   1070 <diff@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm2
movapd 0x20(%rsp),%xmm1
subsd  %xmm1,%xmm2
movapd 0xe26(%rip),%xmm0
andpd  %xmm0,%xmm2
movapd %xmm2,0x10(%rsp)
movapd %xmm1,%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x38(%rsp)
movaps 0x10(%rsp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x40(%rsp),%xmm0
call   1060 <log@plt>
movsd  0x30(%rsp),%xmm3
divsd  %xmm0,%xmm3
mov    %r14,%rdi
mov    %ebx,%esi
movaps 0x20(%rsp),%xmm0
movsd  0x38(%rsp),%xmm1
movaps 0x10(%rsp),%xmm2
mov    $0x4,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
movapd 0x20(%rsp),%xmm1
subsd  %xmm0,%xmm1
andpd  0xdb4(%rip),%xmm1
movapd %xmm1,%xmm2
add    $0x1,%ebx
movsd  0xd95(%rip),%xmm1
ucomisd %xmm2,%xmm1
movaps 0x10(%rsp),%xmm1
jbe    11a0 <main+0x50>
lea    0xdaf(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [53 x i8] c"Solution for e^x = 2x+1 using newton raphson method\0A\00"
@.str.1 = [25 x i8] c"Initial approximation: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 i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store double 1.000000e+00, double* %3
store double 2.000000e+00, double* %4
store i32 0, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %0, %40
%11 = load double, double* %3
%12 = load double, double* %3
%13 = call double @f(double %12)
%14 = load double, double* %3
%15 = call double @diff(double %14)
%16 = fdiv double %13, %15
%17 = fsub double %11, %16
store double %17, double* %2
%18 = load double, double* %2
%19 = load double, double* %3
%20 = fsub double %18, %19
%21 = call double @llvm.fabs.f64(double %20)
store double %21, double* %5
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
%24 = load double, double* %3
%25 = load double, double* %3
%26 = call double @f(double %25)
%27 = load double, double* %5
%28 = load double, double* %5
%29 = call double @log(double %28)
%30 = load double, double* %4
%31 = call double @log(double %30)
%32 = fdiv double %29, %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %22, double %24, double %26, double %27, double %32)
%34 = load double, double* %3
%35 = load double, double* %2
%36 = fsub double %34, %35
%37 = call double @llvm.fabs.f64(double %36)
%38 = fcmp olt double %37, 0x3EB0C6F7A0B5ED8D
br i1 %38, label %39, label %40
39: ; preds = %10
br label %43
40: ; preds = %10
%41 = load double, double* %2
store double %41, double* %3
%42 = load double, double* %5
store double %42, double* %4
br label %10
43: ; preds = %39
%44 = load double, double* %2
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), double %44)
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 = [52 x i8] c"Solution for e^x = 2x+1 using newton raphson method\00"
@str.5 = [24 x i8] c"Initial approximation: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 ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.6, i64 0, i64 0))
br label %4
4: ; preds = %4, %0
%5 = phi double [ 2.000000e+00, %0 ], [ %13, %4 ]
%6 = phi double [ 1.000000e+00, %0 ], [ %11, %4 ]
%7 = phi i32 [ 0, %0 ], [ %22, %4 ]
%8 = tail call double @f(double %6)
%9 = tail call double @diff(double %6)
%10 = fdiv double %8, %9
%11 = fsub double %6, %10
%12 = fsub double %11, %6
%13 = tail call double @llvm.fabs.f64(double %12)
%14 = tail call double @f(double %6)
%15 = tail call double @log(double %13)
%16 = tail call double @log(double %5)
%17 = fdiv double %15, %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %7, double %6, double %14, double %13, double %17)
%19 = fsub double %6, %11
%20 = tail call double @llvm.fabs.f64(double %19)
%21 = fcmp olt double %20, 0x3EB0C6F7A0B5ED8D
%22 = add nuw nsw i32 %7, 1
br i1 %21, label %23, label %4
23: ; preds = %4
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), double %11)
ret i32 0
}