#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 fabs(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
int main(void) {
  double x = 10, x1 = 0.0;
  int iter = 0;
  printf("Enter Initial Guess :");
  scanf("%lf", &x);
  printf("The Solution for the Equation using Newton Raphson method : "
         "x*x-x-6=0 \n");
  printf("\nIter\tx\tf(x) \t ERROR \n");
  do {
    x1 = x;
    x = x1 - ((x1 * x1 - x1 - 6) / (2 * x1 - 1));
    printf("%d  %lf %lf %lf \n", (++iter), x, (x * x - x - 6), fabs(x - x1));
  } while (fabs(x - x1) > 0.00001);
  printf("The solution is : %lf", x);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf69(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm3
movsd  -0x18(%rbp),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
movsd  0xe3e(%rip),%xmm2
subsd  %xmm2,%xmm1
movsd  -0x18(%rbp),%xmm2
addsd  %xmm2,%xmm2
movsd  0xe31(%rip),%xmm3
addsd  %xmm3,%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
movsd  0xdd4(%rip),%xmm2
subsd  %xmm2,%xmm1
movsd  -0x10(%rbp),%xmm2
subsd  -0x18(%rbp),%xmm2
movaps 0xdd7(%rip),%xmm3
pand   %xmm3,%xmm2
lea    0xe51(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xdb4(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xda0(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1185 <main+0x65>
movsd  -0x10(%rbp),%xmm0
lea    0xe29(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x4024000000000000,%rax
mov    %rax,0x8(%rsp)
lea    0xee3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf0f(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xf02(%rip),%rdi
call   1030 <puts@plt>
lea    0xf3d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
movsd  0x8(%rsp),%xmm0
lea    0xeb7(%rip),%r14
nop
movapd %xmm0,%xmm3
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
subsd  %xmm0,%xmm1
movsd  0xe58(%rip),%xmm2
addsd  %xmm2,%xmm1
addsd  %xmm0,%xmm0
addsd  0xe50(%rip),%xmm0
divsd  %xmm0,%xmm1
movapd %xmm3,%xmm0
movsd  %xmm3,0x10(%rsp)
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
subsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm3,%xmm2
movapd 0xe30(%rip),%xmm3
andpd  %xmm3,%xmm2
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x3,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
andpd  0xe08(%rip),%xmm1
add    $0x1,%ebx
ucomisd 0xded(%rip),%xmm1
ja     1190 <main+0x60>
lea    0xe28(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter Initial Guess :\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [72 x i8] c"The Solution for the Equation using Newton Raphson method : x*x-x-6=0 \0A\00"
@.str.3 = [23 x i8] c"\0AIter\09x\09f(x) \09 ERROR \0A\00"
@.str.4 = [18 x i8] c"%d %lf %lf %lf \0A\00"
@.str.5 = [22 x i8] c"The solution is : %lf\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i32
store i32 0, i32* %1
store double 1.000000e+01, double* %2
store double 0.000000e+00, double* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %9
9: ; preds = %36, %0
%10 = load double, double* %2
store double %10, double* %3
%11 = load double, double* %3
%12 = load double, double* %3
%13 = load double, double* %3
%14 = load double, double* %3
%15 = fneg double %14
%16 = call double @llvm.fmuladd.f64(double %12, double %13, double %15)
%17 = fsub double %16, 6.000000e+00
%18 = load double, double* %3
%19 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %18, double -1.000000e+00)
%20 = fdiv double %17, %19
%21 = fsub double %11, %20
store double %21, double* %2
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
%24 = load double, double* %2
%25 = load double, double* %2
%26 = load double, double* %2
%27 = load double, double* %2
%28 = fneg double %27
%29 = call double @llvm.fmuladd.f64(double %25, double %26, double %28)
%30 = fsub double %29, 6.000000e+00
%31 = load double, double* %2
%32 = load double, double* %3
%33 = fsub double %31, %32
%34 = call double @llvm.fabs.f64(double %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %23, double %24, double %30, double %34)
br label %36
36: ; preds = %9
%37 = load double, double* %2
%38 = load double, double* %3
%39 = fsub double %37, %38
%40 = call double @llvm.fabs.f64(double %39)
%41 = fcmp ogt double %40, 1.000000e-05
br i1 %41, label %9, label %42
42: ; preds = %36
%43 = load double, double* %2
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), double %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter Initial Guess :\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.4 = [18 x i8] c"%d %lf %lf %lf \0A\00"
@.str.5 = [22 x i8] c"The solution is : %lf\00"
@str = [71 x i8] c"The Solution for the Equation using Newton Raphson method : x*x-x-6=0 \00"
@str.6 = [22 x i8] c"\0AIter\09x\09f(x) \09 ERROR \00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
store double 1.000000e+01, double* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
%7 = load double, double* %1
br label %8
8: ; preds = %8, %0
%9 = phi double [ %7, %0 ], [ %24, %8 ]
%10 = phi i32 [ 0, %0 ], [ %17, %8 ]
%11 = fneg double %9
%12 = call double @llvm.fmuladd.f64(double %9, double %9, double %11)
%13 = fadd double %12, -6.000000e+00
%14 = call double @llvm.fmuladd.f64(double %9, double 2.000000e+00, double -1.000000e+00)
%15 = fdiv double %13, %14
%16 = fsub double %9, %15
store double %16, double* %1
%17 = add nuw nsw i32 %10, 1
%18 = fneg double %16
%19 = call double @llvm.fmuladd.f64(double %16, double %16, double %18)
%20 = fadd double %19, -6.000000e+00
%21 = fsub double %16, %9
%22 = call double @llvm.fabs.f64(double %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %17, double %16, double %20, double %22)
%24 = load double, double* %1
%25 = fsub double %24, %9
%26 = call double @llvm.fabs.f64(double %25)
%27 = fcmp ogt double %26, 1.000000e-05
br i1 %27, label %8, label %28
28: ; preds = %8
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), double %24)
ret i32 0
}