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


x86 assembly (clang, -O0):
<NUM_sec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %esi,-0x24(%rbp)
movsd  %xmm2,-0x30(%rbp)
mov    %rdx,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     1141 <NUM_sec+0x41>
movl   $0x1,-0x4(%rbp)
jmp    1216 <NUM_sec+0x116>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x20(%rbp),%xmm0
call   *%rax
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x20(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
call   *%rax
movsd  -0x68(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x58(%rbp),%xmm0
subsd  %xmm3,%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movaps 0xe48(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x48(%rbp),%xmm1
movaps 0xe38(%rip),%xmm2
pand   %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%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     1129 <NUM_sec+0x29>
movsd  -0x48(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NUM_sec>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%r14
movsd  %xmm2,0x18(%rsp)
mov    %rdi,%rbx
xor    %ebp,%ebp
test   %esi,%esi
cmovg  %esi,%ebp
add    $0x1,%ebp
xchg   %ax,%ax
add    $0xffffffff,%ebp
je     11b8 <NUM_sec+0xb8>
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
movapd %xmm1,%xmm0
call   *%rbx
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm2
subsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x28(%rsp)
movapd %xmm1,%xmm0
call   *%rbx
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   *%rbx
movsd  0x20(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0x28(%rsp),%xmm0
divsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
divsd  %xmm1,%xmm0
andpd  0xe61(%rip),%xmm0
ucomisd 0x18(%rsp),%xmm0
movapd %xmm2,%xmm0
ja     1120 <NUM_sec+0x20>
movsd  %xmm1,(%r14)
xor    %eax,%eax
jmp    11bd <NUM_sec+0xbd>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @NUM_sec(double (double)* %0, double %1, double %2, i32 %3, double %4, double* %5) {
%7 = alloca i32
%8 = alloca double (double)*
%9 = alloca 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 %1, 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 = %51, %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 %58
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* %10
%28 = load double, double* %9
%29 = fsub double %27, %28
%30 = fmul double %26, %29
%31 = load double (double)*, double (double)** %8
%32 = load double, double* %10
%33 = call double %31(double %32)
%34 = load double (double)*, double (double)** %8
%35 = load double, double* %9
%36 = call double %34(double %35)
%37 = fsub double %33, %36
%38 = fdiv double %30, %37
%39 = fsub double %23, %38
store double %39, double* %15
%40 = load double, double* %15
%41 = load double, double* %10
%42 = fsub double %40, %41
%43 = call double @llvm.fabs.f64(double %42)
%44 = load double, double* %15
%45 = call double @llvm.fabs.f64(double %44)
%46 = fdiv double %43, %45
store double %46, double* %16
%47 = load double, double* %10
store double %47, double* %9
%48 = load double, double* %15
store double %48, double* %10
%49 = load i32, i32* %14
%50 = add nsw i32 %49, 1
store i32 %50, i32* %14
br label %51
51: ; preds = %22
%52 = load double, double* %16
%53 = load double, double* %12
%54 = fcmp ogt double %52, %53
br i1 %54, label %17, label %55
55: ; preds = %51
%56 = load double, double* %15
%57 = load double*, double** %13
store double %56, double* %57
store i32 0, i32* %7
br label %58
58: ; preds = %55, %21
%59 = load i32, i32* %7
ret i32 %59
}

LLVM IR (-O2):
define i32 @NUM_sec(double (double)* nocapture %0, double %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 = %13, %6
%9 = phi double [ %2, %6 ], [ %21, %13 ]
%10 = phi i32 [ 0, %6 ], [ %25, %13 ]
%11 = phi double [ %1, %6 ], [ %9, %13 ]
%12 = icmp eq i32 %10, %7
br i1 %12, label %28, label %13
13: ; preds = %8
%14 = tail call double %0(double %9)
%15 = fsub double %9, %11
%16 = fmul double %15, %14
%17 = tail call double %0(double %9)
%18 = tail call double %0(double %11)
%19 = fsub double %17, %18
%20 = fdiv double %16, %19
%21 = fsub double %9, %20
%22 = fsub double %21, %9
%23 = fdiv double %22, %21
%24 = tail call double @llvm.fabs.f64(double %23)
%25 = add nuw i32 %10, 1
%26 = fcmp ogt double %24, %4
br i1 %26, label %8, label %27
27: ; preds = %13
store double %21, double* %5
br label %28
28: ; preds = %8, %27
%29 = phi i32 [ 0, %27 ], [ 1, %8 ]
ret i32 %29
}