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


x86 assembly (clang, -O0):
<NUM_ptfix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     1142 <NUM_ptfix+0x42>
movl   $0x1,-0x4(%rbp)
jmp    11b7 <NUM_ptfix+0xb7>
mov    -0x10(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xe9d(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x40(%rbp),%xmm1
movaps 0xe8d(%rip),%xmm2
pand   %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movsd  -0x48(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
ja     1126 <NUM_ptfix+0x26>
movsd  -0x40(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NUM_ptfix>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movapd %xmm0,%xmm1
mov    %rdi,%rbx
xor    %ebp,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
ucomisd 0x10(%rsp),%xmm0
jae    1169 <NUM_ptfix+0x69>
movapd %xmm1,%xmm0
movsd  %xmm1,0x18(%rsp)
call   *%rbx
movapd %xmm0,%xmm1
subsd  0x18(%rsp),%xmm1
divsd  %xmm0,%xmm1
andpd  0xeaf(%rip),%xmm1
add    $0x1,%ebp
ucomisd 0x8(%rsp),%xmm1
movapd %xmm0,%xmm1
ja     1120 <NUM_ptfix+0x20>
movsd  %xmm0,(%r14)
xor    %eax,%eax
jmp    116e <NUM_ptfix+0x6e>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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