#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);
int NUM_newton(double (*f)(double x), double (*df)(double x), double x0,
               int nmax, double eps, double *ans) {
  int i = 0;
  double x1;
  double delta;
  do {
    if (i >= nmax) {
      return 1;
    }
    x1 = x0 - f(x0) / df(x0);
    delta = fabs(x1 - x0) / fabs(x1);
    x0 = x1;
    i++;
  } while (delta > eps);
  *ans = x1;
  return 0;
}


x86 assembly (clang, -O0):
<NUM_newton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
movsd  %xmm1,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     1140 <NUM_newton+0x40>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <NUM_newton+0xe4>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x20(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x20(%rbp),%xmm0
call   *%rax
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movaps 0xe70(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x48(%rbp),%xmm1
movaps 0xe60(%rip),%xmm2
pand   %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x50(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
ja     1128 <NUM_newton+0x28>
movsd  -0x48(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NUM_newton>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
movsd  %xmm1,0x8(%rsp)
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %ebp,%ebp
test   %edx,%edx
cmovg  %edx,%ebp
add    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%ebp
je     118a <NUM_newton+0x8a>
movsd  %xmm0,(%rsp)
call   *%rbx
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
call   *%r15
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
andpd  0xe8b(%rip),%xmm1
ucomisd 0x8(%rsp),%xmm1
movapd %xmm2,%xmm0
ja     1130 <NUM_newton+0x30>
movsd  %xmm2,(%r14)
xor    %eax,%eax
jmp    118f <NUM_newton+0x8f>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @NUM_newton(double (double)* %0, double (double)* %1, double %2, i32 %3, double %4, double* %5) {
%7 = alloca i32
%8 = alloca double (double)*
%9 = alloca double (double)*
%10 = alloca double
%11 = alloca i32
%12 = alloca double
%13 = alloca double*
%14 = alloca i32
%15 = alloca double
%16 = alloca double
store double (double)* %0, double (double)** %8
store double (double)* %1, double (double)** %9
store double %2, double* %10
store i32 %3, i32* %11
store double %4, double* %12
store double* %5, double** %13
store i32 0, i32* %14
br label %17
17: ; preds = %42, %6
%18 = load i32, i32* %14
%19 = load i32, i32* %11
%20 = icmp sge i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 1, i32* %7
br label %49
22: ; preds = %17
%23 = load double, double* %10
%24 = load double (double)*, double (double)** %8
%25 = load double, double* %10
%26 = call double %24(double %25)
%27 = load double (double)*, double (double)** %9
%28 = load double, double* %10
%29 = call double %27(double %28)
%30 = fdiv double %26, %29
%31 = fsub double %23, %30
store double %31, double* %15
%32 = load double, double* %15
%33 = load double, double* %10
%34 = fsub double %32, %33
%35 = call double @llvm.fabs.f64(double %34)
%36 = load double, double* %15
%37 = call double @llvm.fabs.f64(double %36)
%38 = fdiv double %35, %37
store double %38, double* %16
%39 = load double, double* %15
store double %39, double* %10
%40 = load i32, i32* %14
%41 = add nsw i32 %40, 1
store i32 %41, i32* %14
br label %42
42: ; preds = %22
%43 = load double, double* %16
%44 = load double, double* %12
%45 = fcmp ogt double %43, %44
br i1 %45, label %17, label %46
46: ; preds = %42
%47 = load double, double* %15
%48 = load double*, double** %13
store double %47, double* %48
store i32 0, i32* %7
br label %49
49: ; preds = %46, %21
%50 = load i32, i32* %7
ret i32 %50
}

LLVM IR (-O2):
define i32 @NUM_newton(double (double)* nocapture %0, double (double)* nocapture %1, double %2, i32 %3, double %4, double* nocapture writeonly %5) {
%7 = call i32 @llvm.smax.i32(i32 %3, i32 0)
br label %8
8: ; preds = %12, %6
%9 = phi i32 [ 0, %6 ], [ %20, %12 ]
%10 = phi double [ %2, %6 ], [ %16, %12 ]
%11 = icmp eq i32 %9, %7
br i1 %11, label %23, label %12
12: ; preds = %8
%13 = tail call double %0(double %10)
%14 = tail call double %1(double %10)
%15 = fdiv double %13, %14
%16 = fsub double %10, %15
%17 = fsub double %16, %10
%18 = fdiv double %17, %16
%19 = tail call double @llvm.fabs.f64(double %18)
%20 = add nuw i32 %9, 1
%21 = fcmp ogt double %19, %4
br i1 %21, label %8, label %22
22: ; preds = %12
store double %16, double* %5
br label %23
23: ; preds = %8, %22
%24 = phi i32 [ 0, %22 ], [ 1, %8 ]
ret i32 %24
}