#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 fun(double);
int secant(double *x, double prec, double iter) {
  double xn = x[1];
  double xn_1 = x[0];
  int n;
  double d;
  for (n = 1; n <= iter; n++) {
    d = (xn - xn_1) / (fun(xn) - fun(xn_1)) * fun(xn);
    if (fabs(d) < prec) {
      x[1] = xn;
      return 1;
    }
    xn_1 = xn;
    xn = xn - d;
  }
  return xn;
}


x86 assembly (clang, -O0):
<secant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1219 <secant+0x109>
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fun@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <fun@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fun@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movaps 0xe3b(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11f2 <secant+0xe2>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1221 <secant+0x111>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1148 <secant+0x38>
cvttsd2si -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<secant>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movapd %xmm0,%xmm4
movsd  0x8(%rdi),%xmm0
ucomisd 0xed9(%rip),%xmm1
jae    1132 <secant+0x22>
movapd %xmm0,%xmm3
jmp    11ef <secant+0xdf>
mov    %rdi,%rbx
movsd  (%rdi),%xmm5
mov    $0x2,%ebp
movsd  %xmm1,0x18(%rsp)
movsd  %xmm4,0x20(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm5,0x28(%rsp)
movapd %xmm0,%xmm1
subsd  %xmm5,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1030 <fun@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x28(%rsp),%xmm0
call   1030 <fun@plt>
movsd  0x30(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <fun@plt>
movsd  0x20(%rsp),%xmm4
mulsd  0x10(%rsp),%xmm0
movapd %xmm0,%xmm1
andpd  0xe53(%rip),%xmm1
ucomisd %xmm1,%xmm4
ja     11f5 <secant+0xe5>
movsd  0x8(%rsp),%xmm5
movapd %xmm5,%xmm3
xorps  %xmm2,%xmm2
cvtsi2sd %ebp,%xmm2
subsd  %xmm0,%xmm3
add    $0x1,%ebp
movsd  0x18(%rsp),%xmm1
ucomisd %xmm2,%xmm1
movapd %xmm3,%xmm0
jae    1150 <secant+0x40>
cvttsd2si %xmm3,%eax
jmp    1205 <secant+0xf5>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rbx)
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @secant(double* nocapture %0, double %1, double %2) {
%4 = getelementptr inbounds double, double* %0, i64 1
%5 = load double, double* %4
%6 = fcmp ult double %2, 1.000000e+00
br i1 %6, label %28, label %7
7: ; preds = %3
%8 = load double, double* %0
br label %9
9: ; preds = %7, %23
%10 = phi i32 [ %25, %23 ], [ 1, %7 ]
%11 = phi double [ %12, %23 ], [ %8, %7 ]
%12 = phi double [ %24, %23 ], [ %5, %7 ]
%13 = fsub double %12, %11
%14 = tail call double @fun(double %12)
%15 = tail call double @fun(double %11)
%16 = fsub double %14, %15
%17 = fdiv double %13, %16
%18 = tail call double @fun(double %12)
%19 = fmul double %18, %17
%20 = tail call double @llvm.fabs.f64(double %19)
%21 = fcmp olt double %20, %1
br i1 %21, label %22, label %23
22: ; preds = %9
store double %12, double* %4
br label %31
23: ; preds = %9
%24 = fsub double %12, %19
%25 = add nuw nsw i32 %10, 1
%26 = sitofp i32 %25 to double
%27 = fcmp ugt double %26, %2
br i1 %27, label %28, label %9
28: ; preds = %23, %3
%29 = phi double [ %5, %3 ], [ %24, %23 ]
%30 = fptosi double %29 to i32
br label %31
31: ; preds = %28, %22
%32 = phi i32 [ 1, %22 ], [ %30, %28 ]
ret i32 %32
}