#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);
double newton(double x0, double epsilon, double (*f)(double),
              double (*fprim)(double)) {
  double x_pre, x;
  x_pre = x0;
  for (;;) {
    x = x_pre - f(x_pre) * 1.0 / fprim(x_pre);
    if (fabs(x - x_pre) < epsilon)
      break;
    x_pre = x;
  }
  return x;
}


x86 assembly (clang, -O0):
<newton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x28(%rbp),%xmm0
call   *%rax
movsd  0xecf(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x28(%rbp),%xmm0
call   *%rax
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movaps 0xe80(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1198 <newton+0x98>
jmp    11a7 <newton+0xa7>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1124 <newton+0x24>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newton>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  %xmm1,0x10(%rsp)
movapd %xmm0,%xmm1
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x20(%rsp)
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   *%rbx
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   *%r14
movsd  0x20(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
divsd  %xmm0,%xmm2
subsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
subsd  0x8(%rsp),%xmm0
andpd  0xe99(%rip),%xmm0
movsd  0x10(%rsp),%xmm2
ucomisd %xmm0,%xmm2
jbe    1120 <newton+0x20>
movapd %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @newton(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 double
%10 = 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
%11 = load double, double* %5
store double %11, double* %9
br label %12
12: ; preds = %30, %4
%13 = load double, double* %9
%14 = load double (double)*, double (double)** %7
%15 = load double, double* %9
%16 = call double %14(double %15)
%17 = fmul double %16, 1.000000e+00
%18 = load double (double)*, double (double)** %8
%19 = load double, double* %9
%20 = call double %18(double %19)
%21 = fdiv double %17, %20
%22 = fsub double %13, %21
store double %22, double* %10
%23 = load double, double* %10
%24 = load double, double* %9
%25 = fsub double %23, %24
%26 = call double @llvm.fabs.f64(double %25)
%27 = load double, double* %6
%28 = fcmp olt double %26, %27
br i1 %28, label %29, label %30
29: ; preds = %12
br label %32
30: ; preds = %12
%31 = load double, double* %10
store double %31, double* %9
br label %12
32: ; preds = %29
%33 = load double, double* %10
ret double %33
}

LLVM IR (-O2):
define double @newton(double %0, double %1, double (double)* nocapture %2, double (double)* nocapture %3) {
br label %5
5: ; preds = %5, %4
%6 = phi double [ %0, %4 ], [ %10, %5 ]
%7 = tail call double %2(double %6)
%8 = tail call double %3(double %6)
%9 = fdiv double %7, %8
%10 = fsub double %6, %9
%11 = fsub double %10, %6
%12 = tail call double @llvm.fabs.f64(double %11)
%13 = fcmp olt double %12, %1
br i1 %13, label %14, label %5
14: ; preds = %5
ret double %10
}