#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 */
int /*<<< orphan*/ printf(char *, int, ...);
double NRMethod(double x0, double (*f)(double), double (*g)(double),
                double accuracy, int verbose) {
  double x1, diff;
  int i = 0;
  do {
    x1 = x0 - f(x0) / g(x0);
    diff = x0 > x1 ? (x0 - x1) : x1 - x0;
    if (verbose)
      printf("x0 = %lf x1 = %lf and |x1-x0| = %lf\n", x0, x1, diff);
    x0 = x1;
    i++;
  } while (diff > accuracy);
  if (verbose)
    printf("No of Iterations: %d\n", i);
  return x1;
}


x86 assembly (clang, -O0):
<NRMethod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
movl   $0x0,-0x3c(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
call   *%rax
movsd  -0x50(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1197 <NRMethod+0x87>
movsd  -0x8(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    11a6 <NRMethod+0x96>
movsd  -0x30(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11d7 <NRMethod+0xc7>
cvttsd2si -0x8(%rbp),%esi
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xe30(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
ja     1134 <NRMethod+0x24>
cmpl   $0x0,-0x24(%rbp)
je     1215 <NRMethod+0x105>
mov    -0x3c(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NRMethod>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
movsd  %xmm1,0x8(%rsp)
mov    %rsi,%r15
mov    %rdi,%rbp
movapd %xmm0,%xmm1
xor    %ebx,%ebx
lea    0xec8(%rip),%r12
jmp    1153 <NRMethod+0x43>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
ucomisd 0x8(%rsp),%xmm1
movapd %xmm0,%xmm1
jbe    11f5 <NRMethod+0xe5>
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
call   *%rbp
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
call   *%r15
movsd  (%rsp),%xmm3
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
movapd %xmm3,%xmm2
subsd  %xmm0,%xmm2
movapd %xmm0,%xmm4
subsd  %xmm3,%xmm4
movapd %xmm0,%xmm1
cmpltsd %xmm3,%xmm1
andpd  %xmm1,%xmm2
andnpd %xmm4,%xmm1
orpd   %xmm2,%xmm1
test   %r14d,%r14d
je     1140 <NRMethod+0x30>
cvttsd2si %xmm3,%esi
mov    %r12,%rdi
mov    $0x2,%al
movsd  %xmm0,(%rsp)
movapd %xmm1,0x10(%rsp)
call   1030 <printf@plt>
add    $0x1,%ebx
movapd 0x10(%rsp),%xmm0
ucomisd 0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
ja     1153 <NRMethod+0x43>
lea    0xe3e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"x0 = %lf x1 = %lf and |x1-x0| = %lf\0A\00"
@.str.1 = [22 x i8] c"No of Iterations: %d\0A\00"
define double @NRMethod(double %0, double (double)* %1, double (double)* %2, double %3, i32 %4) {
%6 = alloca double
%7 = alloca double (double)*
%8 = alloca double (double)*
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca i32
store double %0, double* %6
store double (double)* %1, double (double)** %7
store double (double)* %2, double (double)** %8
store double %3, double* %9
store i32 %4, i32* %10
store i32 0, i32* %13
br label %14
14: ; preds = %49, %5
%15 = load double, double* %6
%16 = load double (double)*, double (double)** %7
%17 = load double, double* %6
%18 = call double %16(double %17)
%19 = load double (double)*, double (double)** %8
%20 = load double, double* %6
%21 = call double %19(double %20)
%22 = fdiv double %18, %21
%23 = fsub double %15, %22
store double %23, double* %11
%24 = load double, double* %6
%25 = load double, double* %11
%26 = fcmp ogt double %24, %25
br i1 %26, label %27, label %31
27: ; preds = %14
%28 = load double, double* %6
%29 = load double, double* %11
%30 = fsub double %28, %29
br label %35
31: ; preds = %14
%32 = load double, double* %11
%33 = load double, double* %6
%34 = fsub double %32, %33
br label %35
35: ; preds = %31, %27
%36 = phi double [ %30, %27 ], [ %34, %31 ]
store double %36, double* %12
%37 = load i32, i32* %10
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %35
%40 = load double, double* %6
%41 = fptosi double %40 to i32
%42 = load double, double* %11
%43 = load double, double* %12
%44 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %41, double %42, double %43)
br label %45
45: ; preds = %39, %35
%46 = load double, double* %11
store double %46, double* %6
%47 = load i32, i32* %13
%48 = add nsw i32 %47, 1
store i32 %48, i32* %13
br label %49
49: ; preds = %45
%50 = load double, double* %12
%51 = load double, double* %9
%52 = fcmp ogt double %50, %51
br i1 %52, label %14, label %53
53: ; preds = %49
%54 = load i32, i32* %10
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i32, i32* %13
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %56, %53
%60 = load double, double* %11
ret double %60
}

LLVM IR (-O2):
@.str = [37 x i8] c"x0 = %lf x1 = %lf and |x1-x0| = %lf\0A\00"
@.str.1 = [22 x i8] c"No of Iterations: %d\0A\00"
define double @NRMethod(double %0, double (double)* nocapture %1, double (double)* nocapture %2, double %3, i32 %4) {
%6 = icmp eq i32 %4, 0
br label %7
7: ; preds = %21, %5
%8 = phi double [ %0, %5 ], [ %13, %21 ]
%9 = phi i32 [ 0, %5 ], [ %22, %21 ]
%10 = tail call double %1(double %8)
%11 = tail call double %2(double %8)
%12 = fdiv double %10, %11
%13 = fsub double %8, %12
%14 = fcmp ogt double %8, %13
%15 = fsub double %8, %13
%16 = fsub double %13, %8
%17 = select i1 %14, double %15, double %16
br i1 %6, label %18, label %23
18: ; preds = %7
%19 = add nuw nsw i32 %9, 1
%20 = fcmp ogt double %17, %3
br i1 %20, label %21, label %30
21: ; preds = %18, %23
%22 = phi i32 [ %19, %18 ], [ %26, %23 ]
br label %7
23: ; preds = %7
%24 = fptosi double %8 to i32
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %24, double %13, double %17)
%26 = add nuw nsw i32 %9, 1
%27 = fcmp ogt double %17, %3
br i1 %27, label %21, label %28
28: ; preds = %23
%29 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %30
30: ; preds = %18, %28
ret double %13
}