double newton_raphson(int iter, double x0, void *data,
                      double (*fun)(void *data, double x),
                      double (*der)(void *data, double x)) {
  return (0 == iter)
             ? x0
             : newton_raphson(iter - 1, x0 - fun(data, x0) / der(data, x0),
                              data, fun, der);
}


x86 assembly (clang, -O0):
<newton_raphson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x4(%rbp),%eax
jne    1146 <newton_raphson+0x36>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11aa <newton_raphson+0x9a>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  -0x48(%rbp),%xmm1
mov    -0x3c(%rbp),%edi
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <newton_raphson@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newton_raphson>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
je     115d <newton_raphson+0x5d>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%ebp
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
call   *%r15
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
call   *%r14
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
add    $0xffffffff,%ebp
jne    1120 <newton_raphson+0x20>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @newton_raphson(i32 %0, double %1, i8* %2, double (i8*, double)* %3, double (i8*, double)* %4) {
%6 = alloca i32
%7 = alloca double
%8 = alloca i8*
%9 = alloca double (i8*, double)*
%10 = alloca double (i8*, double)*
store i32 %0, i32* %6
store double %1, double* %7
store i8* %2, i8** %8
store double (i8*, double)* %3, double (i8*, double)** %9
store double (i8*, double)* %4, double (i8*, double)** %10
%11 = load i32, i32* %6
%12 = icmp eq i32 0, %11
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = load double, double* %7
br label %33
15: ; preds = %5
%16 = load i32, i32* %6
%17 = sub nsw i32 %16, 1
%18 = load double, double* %7
%19 = load double (i8*, double)*, double (i8*, double)** %9
%20 = load i8*, i8** %8
%21 = load double, double* %7
%22 = call double %19(i8* %20, double %21)
%23 = load double (i8*, double)*, double (i8*, double)** %10
%24 = load i8*, i8** %8
%25 = load double, double* %7
%26 = call double %23(i8* %24, double %25)
%27 = fdiv double %22, %26
%28 = fsub double %18, %27
%29 = load i8*, i8** %8
%30 = load double (i8*, double)*, double (i8*, double)** %9
%31 = load double (i8*, double)*, double (i8*, double)** %10
%32 = call double @newton_raphson(i32 %17, double %28, i8* %29, double (i8*, double)* %30, double (i8*, double)* %31)
br label %33
33: ; preds = %15, %13
%34 = phi double [ %14, %13 ], [ %32, %15 ]
ret double %34
}

LLVM IR (-O2):
define double @newton_raphson(i32 %0, double %1, i8* %2, double (i8*, double)* nocapture %3, double (i8*, double)* nocapture %4) {
%6 = icmp eq i32 %0, 0
br i1 %6, label %16, label %7
7: ; preds = %5, %7
%8 = phi double [ %14, %7 ], [ %1, %5 ]
%9 = phi i32 [ %10, %7 ], [ %0, %5 ]
%10 = add nsw i32 %9, -1
%11 = tail call double %3(i8* %2, double %8)
%12 = tail call double %4(i8* %2, double %8)
%13 = fdiv double %11, %12
%14 = fsub double %8, %13
%15 = icmp eq i32 %10, 0
br i1 %15, label %16, label %7
16: ; preds = %7, %5
%17 = phi double [ %1, %5 ], [ %14, %7 ]
ret double %17
}