#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 TheFunction(double);
double fabs(double);
double Secant(double a, double b) {
  int maxIterationNumber = 100, n = 1;
  double x, fa, fb;
  while (n <= maxIterationNumber) {
    fa = TheFunction(a);
    fb = TheFunction(b);
    x = b - (a - b) * fb / (fa - fb);
    if (fabs(x - b) < 0.0001) {
      return x;
    } else {
      a = b;
      b = x;
    }
  }
  return x;
}


x86 assembly (clang, -O0):
<Secant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movl   $0x64,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11d4 <Secant+0xc4>
movsd  -0x10(%rbp),%xmm0
call   1030 <TheFunction@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <TheFunction@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
subsd  -0x38(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movaps 0xe7a(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe5e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11bb <Secant+0xab>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11de <Secant+0xce>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1130 <Secant+0x20>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Secant>:
sub    $0x28,%rsp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm1,0x20(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <TheFunction@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <TheFunction@plt>
movsd  0x20(%rsp),%xmm1
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
subsd  %xmm3,%xmm2
mulsd  %xmm0,%xmm2
movsd  0x18(%rsp),%xmm4
subsd  %xmm0,%xmm4
divsd  %xmm4,%xmm2
subsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
subsd  %xmm3,%xmm0
andpd  0xe7c(%rip),%xmm0
movsd  0xe84(%rip),%xmm2
ucomisd %xmm0,%xmm2
movapd %xmm3,%xmm0
jbe    1120 <Secant+0x10>
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
define double @Secant(double %0, double %1) {
br label %3
3: ; preds = %3, %2
%4 = phi double [ %1, %2 ], [ %12, %3 ]
%5 = phi double [ %0, %2 ], [ %4, %3 ]
%6 = tail call double @TheFunction(double %5)
%7 = tail call double @TheFunction(double %4)
%8 = fsub double %5, %4
%9 = fmul double %8, %7
%10 = fsub double %6, %7
%11 = fdiv double %9, %10
%12 = fsub double %4, %11
%13 = fsub double %12, %4
%14 = tail call double @llvm.fabs.f64(double %13)
%15 = fcmp olt double %14, 1.000000e-04
br i1 %15, label %16, label %3
16: ; preds = %3
ret double %12
}