#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 of x^3 - 2x^2- 4x + 8 = 0 using newton Raphson\n");
  printf("Initial guess = 1.2\n");
  double newRoot, oldRoot = 1.2;
  double oldError = 2, newError;
  int i = 0;
  printf("i\troot\t\tf(root)\t\tError\t\torder of convergence\n");
  do {
    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));
    oldRoot = newRoot;
    oldError = newError;
  } while (newError > 0.0000001);
  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    0xf05(%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  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xd8a(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     119a <main+0x5a>
movsd  -0x10(%rbp),%xmm0
lea    0xe20(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xef4(%rip),%rdi
call   1030 <puts@plt>
lea    0xf20(%rip),%rdi
call   1030 <puts@plt>
lea    0xf28(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
movsd  0xe7a(%rip),%xmm0
movsd  %xmm0,(%rsp)
movsd  0xe75(%rip),%xmm0
lea    0xe96(%rip),%r14
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x38(%rsp)
movsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <f@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1070 <diff@plt>
movsd  0x10(%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  (%rsp),%xmm1
subsd  %xmm2,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm0
subsd  %xmm0,%xmm1
andpd  0xe2f(%rip),%xmm1
movapd %xmm1,0x10(%rsp)
lea    0x1(%rbx),%ebp
call   1040 <f@plt>
movsd  %xmm0,0x30(%rsp)
movaps 0x10(%rsp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0x38(%rsp),%xmm0
call   1060 <log@plt>
movsd  0x28(%rsp),%xmm3
divsd  %xmm0,%xmm3
mov    %r14,%rdi
mov    %ebx,%esi
movsd  0x8(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
movaps 0x10(%rsp),%xmm2
mov    $0x4,%al
call   1050 <printf@plt>
movapd 0x10(%rsp),%xmm0
ucomisd 0xdbb(%rip),%xmm0
mov    %ebp,%ebx
ja     11a0 <main+0x50>
lea    0xddc(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [57 x i8] c"Solution of x^3 - 2x^2- 4x + 8 = 0 using newton Raphson\0A\00"
@.str.1 = [21 x i8] c"Initial guess = 1.2\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 ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store double 1.200000e+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 = %36, %0
%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* %2
store double %34, double* %3
%35 = load double, double* %5
store double %35, double* %4
br label %36
36: ; preds = %10
%37 = load double, double* %5
%38 = fcmp ogt double %37, 0x3E7AD7F29ABCAF48
br i1 %38, label %10, label %39
39: ; preds = %36
%40 = load double, double* %2
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), double %40)
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 = [56 x i8] c"Solution of x^3 - 2x^2- 4x + 8 = 0 using newton Raphson\00"
@str.5 = [20 x i8] c"Initial guess = 1.2\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 ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 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.200000e+00, %0 ], [ %11, %4 ]
%7 = phi i32 [ 0, %0 ], [ %14, %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 = add nuw nsw i32 %7, 1
%15 = tail call double @f(double %6)
%16 = tail call double @log(double %13)
%17 = tail call double @log(double %5)
%18 = fdiv double %16, %17
%19 = 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 %15, double %13, double %18)
%20 = fcmp ogt double %13, 0x3E7AD7F29ABCAF48
br i1 %20, label %4, label %21
21: ; preds = %4
%22 = 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
}