#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) {
  int i = 0;
  double x_n = 0;
  while (fabs(x[0] - x[1]) > prec && fun(x[1]) > prec && i++ < iter) {
    x_n = x[1] - fun(x[1]) * (x[1] - x[0]) / (fun(x[1]) - fun(x[0]));
    x[0] = x[1];
    x[1] = x_n;
  }
  if (fabs(x[0] - x[1]) <= prec || fun(x[1]) <= prec) {
    return 1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<secant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  0x8(%rax),%xmm0
movaps 0xeb3(%rip),%xmm1
pand   %xmm1,%xmm0
xor    %eax,%eax
ucomisd -0x18(%rbp),%xmm0
mov    %al,-0x31(%rbp)
jbe    119d <secant+0x8d>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
call   1030 <fun@plt>
xor    %eax,%eax
ucomisd -0x18(%rbp),%xmm0
mov    %al,-0x31(%rbp)
jbe    119d <secant+0x8d>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
cvtsi2sd %eax,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11ad <secant+0x9d>
jmp    124a <secant+0x13a>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
call   1030 <fun@plt>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
call   1030 <fun@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
call   1030 <fun@plt>
movsd  -0x50(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x40(%rbp),%xmm0
subsd  %xmm3,%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
jmp    1135 <secant+0x25>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
subsd  0x8(%rax),%xmm1
movaps 0xd9e(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jae    1295 <secant+0x185>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
call   1030 <fun@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     12a1 <secant+0x191>
movl   $0x1,-0x4(%rbp)
jmp    12a8 <secant+0x198>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<secant>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movsd  %xmm1,0x8(%rsp)
movapd %xmm0,%xmm1
movsd  (%rdi),%xmm0
movsd  0x8(%rdi),%xmm2
subsd  %xmm2,%xmm0
andpd  0xecb(%rip),%xmm0
ucomisd %xmm1,%xmm0
movsd  %xmm1,(%rsp)
jbe    121f <secant+0x10f>
mov    %rdi,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
movapd %xmm2,%xmm0
call   1030 <fun@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
jbe    120a <secant+0xfa>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  0x8(%rsp),%xmm2
ucomisd %xmm0,%xmm2
jbe    120a <secant+0xfa>
add    $0x1,%ebp
movsd  0x8(%rbx),%xmm0
movsd  %xmm0,0x20(%rsp)
call   1030 <fun@plt>
movsd  0x8(%rbx),%xmm1
movapd %xmm1,%xmm2
subsd  (%rbx),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x18(%rsp)
movapd %xmm1,%xmm0
call   1030 <fun@plt>
movsd  %xmm0,0x10(%rsp)
movsd  (%rbx),%xmm0
call   1030 <fun@plt>
movsd  0x20(%rsp),%xmm2
movsd  (%rsp),%xmm1
movsd  0x10(%rsp),%xmm3
subsd  %xmm0,%xmm3
movsd  0x18(%rsp),%xmm0
divsd  %xmm3,%xmm0
subsd  %xmm0,%xmm2
movsd  0x8(%rbx),%xmm0
movsd  %xmm0,(%rbx)
movsd  %xmm2,0x8(%rbx)
subsd  %xmm2,%xmm0
andpd  0xe02(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1150 <secant+0x40>
jmp    121f <secant+0x10f>
movsd  (%rbx),%xmm0
movsd  0x8(%rbx),%xmm2
subsd  %xmm2,%xmm0
andpd  0xde1(%rip),%xmm0
mov    $0x1,%ebx
ucomisd %xmm0,%xmm1
jae    1240 <secant+0x130>
movapd %xmm2,%xmm0
call   1030 <fun@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    1240 <secant+0x130>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x28,%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 i32
%9 = alloca double
store double* %0, double** %5
store double %1, double* %6
store double %2, double* %7
store i32 0, i32* %8
store double 0.000000e+00, double* %9
br label %10
10: ; preds = %36, %3
%11 = load double*, double** %5
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = load double, double* %12
%14 = load double*, double** %5
%15 = getelementptr inbounds double, double* %14, i64 1
%16 = load double, double* %15
%17 = fsub double %13, %16
%18 = call double @llvm.fabs.f64(double %17)
%19 = load double, double* %6
%20 = fcmp ogt double %18, %19
br i1 %20, label %21, label %34
21: ; preds = %10
%22 = load double*, double** %5
%23 = getelementptr inbounds double, double* %22, i64 1
%24 = load double, double* %23
%25 = call double @fun(double %24)
%26 = load double, double* %6
%27 = fcmp ogt double %25, %26
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
%31 = sitofp i32 %29 to double
%32 = load double, double* %7
%33 = fcmp olt double %31, %32
br label %34
34: ; preds = %28, %21, %10
%35 = phi i1 [ false, %21 ], [ false, %10 ], [ %33, %28 ]
br i1 %35, label %36, label %71
36: ; preds = %34
%37 = load double*, double** %5
%38 = getelementptr inbounds double, double* %37, i64 1
%39 = load double, double* %38
%40 = load double*, double** %5
%41 = getelementptr inbounds double, double* %40, i64 1
%42 = load double, double* %41
%43 = call double @fun(double %42)
%44 = load double*, double** %5
%45 = getelementptr inbounds double, double* %44, i64 1
%46 = load double, double* %45
%47 = load double*, double** %5
%48 = getelementptr inbounds double, double* %47, i64 0
%49 = load double, double* %48
%50 = fsub double %46, %49
%51 = fmul double %43, %50
%52 = load double*, double** %5
%53 = getelementptr inbounds double, double* %52, i64 1
%54 = load double, double* %53
%55 = call double @fun(double %54)
%56 = load double*, double** %5
%57 = getelementptr inbounds double, double* %56, i64 0
%58 = load double, double* %57
%59 = call double @fun(double %58)
%60 = fsub double %55, %59
%61 = fdiv double %51, %60
%62 = fsub double %39, %61
store double %62, double* %9
%63 = load double*, double** %5
%64 = getelementptr inbounds double, double* %63, i64 1
%65 = load double, double* %64
%66 = load double*, double** %5
%67 = getelementptr inbounds double, double* %66, i64 0
store double %65, double* %67
%68 = load double, double* %9
%69 = load double*, double** %5
%70 = getelementptr inbounds double, double* %69, i64 1
store double %68, double* %70
br label %10
71: ; preds = %34
%72 = load double*, double** %5
%73 = getelementptr inbounds double, double* %72, i64 0
%74 = load double, double* %73
%75 = load double*, double** %5
%76 = getelementptr inbounds double, double* %75, i64 1
%77 = load double, double* %76
%78 = fsub double %74, %77
%79 = call double @llvm.fabs.f64(double %78)
%80 = load double, double* %6
%81 = fcmp ole double %79, %80
br i1 %81, label %89, label %82
82: ; preds = %71
%83 = load double*, double** %5
%84 = getelementptr inbounds double, double* %83, i64 1
%85 = load double, double* %84
%86 = call double @fun(double %85)
%87 = load double, double* %6
%88 = fcmp ole double %86, %87
br i1 %88, label %89, label %90
89: ; preds = %82, %71
store i32 1, i32* %4
br label %91
90: ; preds = %82
store i32 0, i32* %4
br label %91
91: ; preds = %90, %89
%92 = load i32, i32* %4
ret i32 %92
}

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* %0
%6 = load double, double* %4
%7 = fsub double %5, %6
%8 = tail call double @llvm.fabs.f64(double %7)
%9 = fcmp ogt double %8, %1
br i1 %9, label %10, label %41
10: ; preds = %3, %23
%11 = phi double [ %36, %23 ], [ %6, %3 ]
%12 = phi i32 [ %24, %23 ], [ 0, %3 ]
%13 = tail call double @fun(double %11)
%14 = fcmp ogt double %13, %1
%15 = sitofp i32 %12 to double
%16 = fcmp olt double %15, %2
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %23, label %18
18: ; preds = %10
%19 = load double, double* %0
%20 = load double, double* %4
%21 = fsub double %19, %20
%22 = tail call double @llvm.fabs.f64(double %21)
br label %41
23: ; preds = %10
%24 = add nuw nsw i32 %12, 1
%25 = load double, double* %4
%26 = tail call double @fun(double %25)
%27 = load double, double* %4
%28 = load double, double* %0
%29 = fsub double %27, %28
%30 = fmul double %26, %29
%31 = tail call double @fun(double %27)
%32 = load double, double* %0
%33 = tail call double @fun(double %32)
%34 = fsub double %31, %33
%35 = fdiv double %30, %34
%36 = fsub double %25, %35
%37 = load double, double* %4
store double %37, double* %0
store double %36, double* %4
%38 = fsub double %37, %36
%39 = tail call double @llvm.fabs.f64(double %38)
%40 = fcmp ogt double %39, %1
br i1 %40, label %10, label %41
41: ; preds = %23, %18, %3
%42 = phi double [ %8, %3 ], [ %22, %18 ], [ %39, %23 ]
%43 = phi double [ %6, %3 ], [ %20, %18 ], [ %36, %23 ]
%44 = fcmp ugt double %42, %1
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = tail call double @fun(double %43)
%47 = fcmp ugt double %46, %1
br i1 %47, label %48, label %49
48: ; preds = %45
br label %49
49: ; preds = %41, %45, %48
%50 = phi i32 [ 0, %48 ], [ 1, %45 ], [ 1, %41 ]
ret i32 %50
}