double secant(double initialminus1, double initial0, double accuracy,
              double (*f)(double)) {
  int i = 1;
  double xiplus1, xi = initial0, ximinus1 = initialminus1, fxi, fximinus1,
                  ei = exp(1);
  printf("SECANT METHOD:\n\ni\txi\t\tf(xi)\t\t|ei|\t\t|log(ei)/log(e(i-1))|\n");
  do {
    fxi = f(xi);
    if (!(fximinus1 = f(ximinus1)))
      break;
    xiplus1 = (ximinus1 * fxi - xi * fximinus1) / (fxi - fximinus1);
    printf("%02d\t%+09g\t%+09g\t%+09g\t%+09g\n", i++, xi, fxi,
           abslt(xi - ximinus1), abslt(log(abslt(xi - ximinus1)) / log(ei)));
    ei = abslt(xi - ximinus1);
    ximinus1 = xi;
    xi = xiplus1;
  } while (abslt(xi - ximinus1) > accuracy);
  return xi;
}


x86 assembly (clang, -O0):
<secant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe7f(%rip),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x58(%rbp)
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
movsd  -0x38(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x40(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d1 <secant+0x91>
jp     11d1 <secant+0x91>
jmp    12f5 <secant+0x1b5>
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x48(%rbp),%xmm1
subsd  -0x50(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x74(%rbp)
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %eax,-0x5c(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    -0x74(%rbp),%esi
movsd  -0x70(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
mov    -0x5c(%rbp),%edx
mov    %eax,%ecx
lea    0xda2(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
ucomisd -0x18(%rbp),%xmm0
ja     1199 <secant+0x59>
movsd  -0x38(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<secant>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%r15
movsd  %xmm2,0x38(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
lea    0xec6(%rip),%rdi
call   1040 <puts@plt>
movsd  0x8(%rsp),%xmm2
movsd  0xe85(%rip),%xmm1
movsd  %xmm1,0x18(%rsp)
mov    $0x1,%ebx
lea    0xe83(%rip),%r14
nopl   (%rax)
movsd  %xmm2,0x8(%rsp)
movaps %xmm2,%xmm0
call   *%r15
movsd  %xmm0,0x30(%rsp)
movsd  0x10(%rsp),%xmm0
call   *%r15
ucomisd 0xe55(%rip),%xmm0
jne    11bb <secant+0x7b>
jnp    12c3 <secant+0x183>
movapd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0x10(%rsp),%xmm3
subsd  %xmm3,%xmm2
movsd  %xmm2,0x20(%rsp)
movsd  0x30(%rsp),%xmm4
mulsd  %xmm4,%xmm3
subsd  %xmm1,%xmm3
movapd %xmm4,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm3,%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x28(%rsp)
lea    0x1(%rbx),%r12d
movapd %xmm2,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %eax,%ebp
movsd  0x20(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
call   1060 <log@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %r14,%rdi
mov    %ebx,%esi
movsd  0x8(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
mov    %ebp,%edx
mov    %eax,%ecx
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0x20(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x28(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
movsd  0x28(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
ucomisd 0x38(%rsp),%xmm1
movsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x10(%rsp)
movaps %xmm0,%xmm2
mov    %r12d,%ebx
ja     1190 <secant+0x50>
jmp    12c9 <secant+0x189>
movsd  0x8(%rsp),%xmm0
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [58 x i8] c"SECANT METHOD:\0A\0Ai\09xi\09\09f(xi)\09\09|ei|\09\09|log(ei)/log(e(i-1))|\0A\00"
@.str.1 = [30 x i8] c"%02d\09%+09g\09%+09g\09%+09g\09%+09g\0A\00"
define double @secant(double %0, double %1, double %2, double (double)* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double (double)*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double (double)* %3, double (double)** %8
store i32 1, i32* %9
%16 = load double, double* %6
store double %16, double* %11
%17 = load double, double* %5
store double %17, double* %12
%18 = call double @exp(double 1.000000e+00)
store double %18, double* %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %67, %4
%21 = load double (double)*, double (double)** %8
%22 = load double, double* %11
%23 = call double %21(double %22)
store double %23, double* %13
%24 = load double (double)*, double (double)** %8
%25 = load double, double* %12
%26 = call double %24(double %25)
store double %26, double* %14
%27 = fcmp une double %26, 0.000000e+00
br i1 %27, label %29, label %28
28: ; preds = %20
br label %75
29: ; preds = %20
%30 = load double, double* %12
%31 = load double, double* %13
%32 = load double, double* %11
%33 = load double, double* %14
%34 = fmul double %32, %33
%35 = fneg double %34
%36 = call double @llvm.fmuladd.f64(double %30, double %31, double %35)
%37 = load double, double* %13
%38 = load double, double* %14
%39 = fsub double %37, %38
%40 = fdiv double %36, %39
store double %40, double* %10
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
%43 = load double, double* %11
%44 = load double, double* %13
%45 = load double, double* %11
%46 = load double, double* %12
%47 = fsub double %45, %46
%48 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %47)
%49 = load double, double* %11
%50 = load double, double* %12
%51 = fsub double %49, %50
%52 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %51)
%53 = sitofp i32 %52 to double
%54 = call double @log(double %53)
%55 = load double, double* %15
%56 = call double @log(double %55)
%57 = fdiv double %54, %56
%58 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %41, double %43, double %44, i32 %48, i32 %58)
%60 = load double, double* %11
%61 = load double, double* %12
%62 = fsub double %60, %61
%63 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %62)
%64 = sitofp i32 %63 to double
store double %64, double* %15
%65 = load double, double* %11
store double %65, double* %12
%66 = load double, double* %10
store double %66, double* %11
br label %67
67: ; preds = %29
%68 = load double, double* %11
%69 = load double, double* %12
%70 = fsub double %68, %69
%71 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %70)
%72 = sitofp i32 %71 to double
%73 = load double, double* %7
%74 = fcmp ogt double %72, %73
br i1 %74, label %20, label %75
75: ; preds = %67, %28
%76 = load double, double* %11
ret double %76
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"%02d\09%+09g\09%+09g\09%+09g\09%+09g\0A\00"
@str = [57 x i8] c"SECANT METHOD:\0A\0Ai\09xi\09\09f(xi)\09\09|ei|\09\09|log(ei)/log(e(i-1))|\00"
define double @secant(double %0, double %1, double %2, double (double)* nocapture %3) {
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %14, %4
%7 = phi double [ %0, %4 ], [ %8, %14 ]
%8 = phi double [ %1, %4 ], [ %19, %14 ]
%9 = phi i32 [ 1, %4 ], [ %20, %14 ]
%10 = phi double [ 0x4005BF0A8B145769, %4 ], [ %31, %14 ]
%11 = tail call double %3(double %8)
%12 = tail call double %3(double %7)
%13 = fcmp une double %12, 0.000000e+00
br i1 %13, label %14, label %36
14: ; preds = %6
%15 = fneg double %8
%16 = fmul double %12, %15
%17 = tail call double @llvm.fmuladd.f64(double %7, double %11, double %16)
%18 = fsub double %11, %12
%19 = fdiv double %17, %18
%20 = add nuw nsw i32 %9, 1
%21 = fsub double %8, %7
%22 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %21)
%23 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %21)
%24 = sitofp i32 %23 to double
%25 = tail call double @log(double %24)
%26 = tail call double @log(double %10)
%27 = fdiv double %25, %26
%28 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %9, double %8, double %11, i32 %22, i32 %28)
%30 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %21)
%31 = sitofp i32 %30 to double
%32 = fsub double %19, %8
%33 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %32)
%34 = sitofp i32 %33 to double
%35 = fcmp ogt double %34, %2
br i1 %35, label %6, label %36
36: ; preds = %6, %14
%37 = phi double [ %19, %14 ], [ %8, %6 ]
ret double %37
}