double newtonraphson(double initial, double accuracy, double (*f)(double),
                     double (*df)(double)) {
  int i = 1;
  double xi, ximinus1 = initial, fxi, dfxi, ei = exp(1);
  printf("NEWTON RAPHSON "
         "METHOD:\n\ni\txi\t\tf(xi)\t\t|ei|\t\t|log(ei)/log(e(i-1))|\n");
  do {
    xi = ximinus1;
    fxi = f(xi);
    if (!(dfxi = df(xi)))
      break;
    ximinus1 = xi - fxi / dfxi;
    printf("%02d\t%+09g\t%+09g\t%+09g\t%+09g\n", i++, xi, fxi,
           abslt(xi - ximinus1), abslt(log(abslt(xi - ximinus1)) / log(ei)));
    ei = abslt(xi - ximinus1);
  } while (abslt(xi - ximinus1) > accuracy);
  return xi;
}


x86 assembly (clang, -O0):
<newtonraphson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe8a(%rip),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x50(%rbp)
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x30(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x30(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d0 <newtonraphson+0x90>
jp     11d0 <newtonraphson+0x90>
jmp    12b2 <newtonraphson+0x172>
movsd  -0x30(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
divsd  -0x48(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x6c(%rbp)
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %eax,-0x54(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x50(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    -0x6c(%rbp),%esi
movsd  -0x68(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
mov    -0x54(%rbp),%edx
mov    %eax,%ecx
lea    0xdd9(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
ucomisd -0x10(%rbp),%xmm0
ja     118e <newtonraphson+0x4e>
movsd  -0x30(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newtonraphson>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
movsd  %xmm1,0x28(%rsp)
movsd  %xmm0,0x18(%rsp)
lea    0xec7(%rip),%rdi
call   1040 <puts@plt>
movsd  0xe8c(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0x1,%ebx
lea    0xe8a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%rsp)
call   *%r12
movsd  %xmm0,0x20(%rsp)
movsd  (%rsp),%xmm0
call   *%r14
ucomisd 0xe54(%rip),%xmm0
jne    11bc <newtonraphson+0x7c>
jnp    1287 <newtonraphson+0x147>
movsd  0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
lea    0x1(%rbx),%r13d
movsd  %xmm2,0x18(%rsp)
subsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <log@plt>
movsd  0x30(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %r15,%rdi
mov    %ebx,%esi
movsd  (%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mov    %ebp,%edx
mov    %eax,%ecx
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ucomisd 0x28(%rsp),%xmm0
mov    %r13d,%ebx
ja     1190 <newtonraphson+0x50>
movsd  (%rsp),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"NEWTON RAPHSON METHOD:\0A\0Ai\09xi\09\09f(xi)\09\09|ei|\09\09|log(ei)/log(e(i-1))|\0A\00"
@.str.1 = [30 x i8] c"%02d\09%+09g\09%+09g\09%+09g\09%+09g\0A\00"
define double @newtonraphson(double %0, double %1, double (double)* %2, double (double)* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double (double)*
%8 = alloca double (double)*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double %0, double* %5
store double %1, double* %6
store double (double)* %2, double (double)** %7
store double (double)* %3, double (double)** %8
store i32 1, i32* %9
%15 = load double, double* %5
store double %15, double* %11
%16 = call double @exp(double 1.000000e+00)
store double %16, double* %14
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %58, %4
%19 = load double, double* %11
store double %19, double* %10
%20 = load double (double)*, double (double)** %7
%21 = load double, double* %10
%22 = call double %20(double %21)
store double %22, double* %12
%23 = load double (double)*, double (double)** %8
%24 = load double, double* %10
%25 = call double %23(double %24)
store double %25, double* %13
%26 = fcmp une double %25, 0.000000e+00
br i1 %26, label %28, label %27
27: ; preds = %18
br label %66
28: ; preds = %18
%29 = load double, double* %10
%30 = load double, double* %12
%31 = load double, double* %13
%32 = fdiv double %30, %31
%33 = fsub double %29, %32
store double %33, double* %11
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
%36 = load double, double* %10
%37 = load double, double* %12
%38 = load double, double* %10
%39 = load double, double* %11
%40 = fsub double %38, %39
%41 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %40)
%42 = load double, double* %10
%43 = load double, double* %11
%44 = fsub double %42, %43
%45 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %44)
%46 = sitofp i32 %45 to double
%47 = call double @log(double %46)
%48 = load double, double* %14
%49 = call double @log(double %48)
%50 = fdiv double %47, %49
%51 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %34, double %36, double %37, i32 %41, i32 %51)
%53 = load double, double* %10
%54 = load double, double* %11
%55 = fsub double %53, %54
%56 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %55)
%57 = sitofp i32 %56 to double
store double %57, double* %14
br label %58
58: ; preds = %28
%59 = load double, double* %10
%60 = load double, double* %11
%61 = fsub double %59, %60
%62 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %61)
%63 = sitofp i32 %62 to double
%64 = load double, double* %6
%65 = fcmp ogt double %63, %64
br i1 %65, label %18, label %66
66: ; preds = %58, %27
%67 = load double, double* %10
ret double %67
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"%02d\09%+09g\09%+09g\09%+09g\09%+09g\0A\00"
@str = [65 x i8] c"NEWTON RAPHSON METHOD:\0A\0Ai\09xi\09\09f(xi)\09\09|ei|\09\09|log(ei)/log(e(i-1))|\00"
define double @newtonraphson(double %0, double %1, double (double)* nocapture %2, double (double)* nocapture %3) {
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %13, %4
%7 = phi double [ %0, %4 ], [ %15, %13 ]
%8 = phi i32 [ 1, %4 ], [ %16, %13 ]
%9 = phi double [ 0x4005BF0A8B145769, %4 ], [ %27, %13 ]
%10 = tail call double %2(double %7)
%11 = tail call double %3(double %7)
%12 = fcmp une double %11, 0.000000e+00
br i1 %12, label %13, label %31
13: ; preds = %6
%14 = fdiv double %10, %11
%15 = fsub double %7, %14
%16 = add nuw nsw i32 %8, 1
%17 = fsub double %7, %15
%18 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %17)
%19 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %17)
%20 = sitofp i32 %19 to double
%21 = tail call double @log(double %20)
%22 = tail call double @log(double %9)
%23 = fdiv double %21, %22
%24 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %8, double %7, double %10, i32 %18, i32 %24)
%26 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %17)
%27 = sitofp i32 %26 to double
%28 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %17)
%29 = sitofp i32 %28 to double
%30 = fcmp ogt double %29, %1
br i1 %30, label %6, label %31
31: ; preds = %6, %13
ret double %7
}