#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 df(double);
double f(double);
double fabs(double);
double newton_raphson(double x0) {
  double last, current;
  current = x0 - (f(x0) / df(x0));
  do {
    last = current;
    current -= f(current) / df(current);
  } while (fabs(last - current) > 0.00001);
  return current;
}


x86 assembly (clang, -O0):
<newton_raphson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <df@plt>
movsd  -0x28(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x20(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <df@plt>
movsd  -0x30(%rbp),%xmm1
divsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xe5b(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe3f(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     116a <newton_raphson+0x4a>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newton_raphson>:
sub    $0x28,%rsp
movsd  %xmm0,0x8(%rsp)
call   1030 <f@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <df@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
movapd %xmm0,0x10(%rsp)
call   1030 <f@plt>
movsd  %xmm0,0x20(%rsp)
movapd 0x10(%rsp),%xmm0
call   1040 <df@plt>
movsd  0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
movapd 0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
andpd  0xe58(%rip),%xmm1
ucomisd 0xe60(%rip),%xmm1
ja     1160 <newton_raphson+0x40>
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @newton_raphson(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %2
%5 = load double, double* %2
%6 = load double, double* %2
%7 = call double @f(double %6)
%8 = load double, double* %2
%9 = call double @df(double %8)
%10 = fdiv double %7, %9
%11 = fsub double %5, %10
store double %11, double* %4
br label %12
12: ; preds = %21, %1
%13 = load double, double* %4
store double %13, double* %3
%14 = load double, double* %4
%15 = call double @f(double %14)
%16 = load double, double* %4
%17 = call double @df(double %16)
%18 = fdiv double %15, %17
%19 = load double, double* %4
%20 = fsub double %19, %18
store double %20, double* %4
br label %21
21: ; preds = %12
%22 = load double, double* %3
%23 = load double, double* %4
%24 = fsub double %22, %23
%25 = call double @llvm.fabs.f64(double %24)
%26 = fcmp ogt double %25, 1.000000e-05
br i1 %26, label %12, label %27
27: ; preds = %21
%28 = load double, double* %4
ret double %28
}

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