#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 */
int fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, double, int);
int /*<<< orphan*/ stdout;
double regulaFalsi(double (*f)(double), double a, double b) {
  double fa, fb, x, fx;
  int i;
  i = 0;
  fa = f(a);
  fb = f(b);
  fx = 1.0;
  while ((fabs(fx) > 1e-9) && (i < 200)) {
    x = ((a * fb) - (b * fa)) / (fb - fa);
    fx = f(x);
    if ((fa * fx) > 0.0) {
      a = x;
      fa = fx;
    } else {
      b = x;
      fb = fx;
    }
    i++;
  }
  fprintf(stdout, "Regula Falsi: %f %f %d\n", fx, x, i);
  return x;
}


x86 assembly (clang, -O0):
<regulaFalsi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x28(%rbp)
movsd  0xe9b(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
xor    %eax,%eax
movsd  0xe86(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x3d(%rbp)
jbe    119c <regulaFalsi+0x7c>
cmpl   $0xc8,-0x3c(%rbp)
setl   %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
test   $0x1,%al
jne    11ac <regulaFalsi+0x8c>
jmp    1254 <regulaFalsi+0x134>
movsd  -0x10(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x30(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1232 <regulaFalsi+0x112>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1246 <regulaFalsi+0x126>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    116a <regulaFalsi+0x4a>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mov    -0x3c(%rbp),%edx
lea    0xd9f(%rip),%rsi
call   1040 <fprintf@plt>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regulaFalsi>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
movsd  %xmm1,0x10(%rsp)
movaps %xmm0,0x30(%rsp)
mov    %rdi,%r14
call   *%rdi
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   *%r14
movsd  %xmm0,0x18(%rsp)
movsd  0xeab(%rip),%xmm0
call   1030 <fabs@plt>
movsd  0x8(%rsp),%xmm2
movapd 0x30(%rsp),%xmm1
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm2,0x8(%rsp)
movsd  0x8(%rsp),%xmm2
mulsd  0x10(%rsp),%xmm2
movapd %xmm1,0x30(%rsp)
movapd %xmm1,%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  %xmm1,%xmm0
subsd  %xmm2,%xmm0
subsd  0x8(%rsp),%xmm1
divsd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
call   *%r14
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x48(%rsp)
ucomisd 0xe3b(%rip),%xmm0
movapd %xmm2,%xmm0
ja     11e8 <regulaFalsi+0xc8>
movaps 0x20(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm2,0x18(%rsp)
movsd  %xmm0,0x8(%rsp)
lea    0x1(%rbx),%ebp
movsd  %xmm2,0x40(%rsp)
movapd %xmm2,%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
movapd 0x30(%rsp),%xmm2
jle    123f <regulaFalsi+0x11f>
xorpd  %xmm0,%xmm0
cmpltsd 0x48(%rsp),%xmm0
movapd %xmm0,%xmm1
andpd  0x20(%rsp),%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
movsd  0x8(%rsp),%xmm2
movapd %xmm0,%xmm1
cmp    $0xc7,%ebx
mov    %ebp,%ebx
jb     1170 <regulaFalsi+0x50>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
movsd  0x40(%rsp),%xmm0
movaps 0x20(%rsp),%xmm1
mov    %ebp,%edx
call   1040 <fprintf@plt>
movaps 0x20(%rsp),%xmm0
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [24 x i8] c"Regula Falsi: %f %f %d\0A\00"
define double @regulaFalsi(double (double)* %0, double %1, double %2) {
%4 = alloca double (double)*
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i32
store double (double)* %0, double (double)** %4
store double %1, double* %5
store double %2, double* %6
store i32 0, i32* %11
%12 = load double (double)*, double (double)** %4
%13 = load double, double* %5
%14 = call double %12(double %13)
store double %14, double* %7
%15 = load double (double)*, double (double)** %4
%16 = load double, double* %6
%17 = call double %15(double %16)
store double %17, double* %8
store double 1.000000e+00, double* %10
br label %18
18: ; preds = %53, %3
%19 = load double, double* %10
%20 = call i32 @fabs(double %19)
%21 = sitofp i32 %20 to double
%22 = fcmp ogt double %21, 1.000000e-09
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* %11
%25 = icmp slt i32 %24, 200
br label %26
26: ; preds = %23, %18
%27 = phi i1 [ false, %18 ], [ %25, %23 ]
br i1 %27, label %28, label %56
28: ; preds = %26
%29 = load double, double* %5
%30 = load double, double* %8
%31 = load double, double* %6
%32 = load double, double* %7
%33 = fmul double %31, %32
%34 = fneg double %33
%35 = call double @llvm.fmuladd.f64(double %29, double %30, double %34)
%36 = load double, double* %8
%37 = load double, double* %7
%38 = fsub double %36, %37
%39 = fdiv double %35, %38
store double %39, double* %9
%40 = load double (double)*, double (double)** %4
%41 = load double, double* %9
%42 = call double %40(double %41)
store double %42, double* %10
%43 = load double, double* %7
%44 = load double, double* %10
%45 = fmul double %43, %44
%46 = fcmp ogt double %45, 0.000000e+00
br i1 %46, label %47, label %50
47: ; preds = %28
%48 = load double, double* %9
store double %48, double* %5
%49 = load double, double* %10
store double %49, double* %7
br label %53
50: ; preds = %28
%51 = load double, double* %9
store double %51, double* %6
%52 = load double, double* %10
store double %52, double* %8
br label %53
53: ; preds = %50, %47
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 1
store i32 %55, i32* %11
br label %18
56: ; preds = %26
%57 = load i32, i32* @stdout
%58 = load double, double* %10
%59 = load double, double* %9
%60 = load i32, i32* %11
%61 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %58, double %59, i32 %60)
%62 = load double, double* %9
ret double %62
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [24 x i8] c"Regula Falsi: %f %f %d\0A\00"
define double @regulaFalsi(double (double)* nocapture %0, double %1, double %2) {
%4 = tail call double %0(double %1)
%5 = tail call double %0(double %2)
%6 = tail call i32 @fabs(double 1.000000e+00)
%7 = icmp sgt i32 %6, 0
br label %8
8: ; preds = %3, %8
%9 = phi i32 [ %26, %8 ], [ 0, %3 ]
%10 = phi double [ %25, %8 ], [ %5, %3 ]
%11 = phi double [ %24, %8 ], [ %4, %3 ]
%12 = phi double [ %23, %8 ], [ %2, %3 ]
%13 = phi double [ %22, %8 ], [ %1, %3 ]
%14 = fneg double %12
%15 = fmul double %11, %14
%16 = tail call double @llvm.fmuladd.f64(double %13, double %10, double %15)
%17 = fsub double %10, %11
%18 = fdiv double %16, %17
%19 = tail call double %0(double %18)
%20 = fmul double %11, %19
%21 = fcmp ogt double %20, 0.000000e+00
%22 = select i1 %21, double %18, double %13
%23 = select i1 %21, double %12, double %18
%24 = select i1 %21, double %19, double %11
%25 = select i1 %21, double %10, double %19
%26 = add nuw nsw i32 %9, 1
%27 = tail call i32 @fabs(double %19)
%28 = icmp sgt i32 %27, 0
%29 = icmp ult i32 %9, 199
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %8, label %31
31: ; preds = %8
%32 = load i32, i32* @stdout
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %19, double %18, i32 %26)
ret double %18
}