#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 fn(double);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  double a = -2;
  double b = -1;
  double erro = 0.005;
  if (fn(a) * fn(b) < 0) {
    double x = 0;
    while (fabs(a - b) > erro) {
      x = (a * fn(b) - b * fn(a)) / (fn(b) - fn(a));
      if (fn(a) * fn(x) > 0)
        a = x;
      else
        b = x;
      printf("\nan=%e | bn=%e | precisao = %e", a, b, fabs(a - b));
    }
    printf("\nRaiz é aproximadamente %e | f(%e) = %e \n", x, x, fn(x));
    return 0;
  }
  printf("Intervalo errado \n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xed9(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xec4(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeaf(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <fn@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <fn@plt>
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1309 <main+0x1e9>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xe82(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    12c4 <main+0x1a4>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <fn@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <fn@plt>
movsd  -0x60(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <fn@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <fn@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <fn@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fn@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1288 <main+0x168>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1292 <main+0x172>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
subsd  -0x18(%rbp),%xmm2
movaps 0xd73(%rip),%xmm3
pand   %xmm3,%xmm2
lea    0xd78(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
jmp    118d <main+0x6d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fn@plt>
movsd  -0x70(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
lea    0xd59(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    131e <main+0x1fe>
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
movsd  0xec3(%rip),%xmm0
call   1040 <fn@plt>
movsd  %xmm0,(%rsp)
movsd  0xeb9(%rip),%xmm0
call   1040 <fn@plt>
mulsd  (%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    12a2 <main+0x172>
lea    0xec2(%rip),%rbx
movsd  0xe92(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xe7c(%rip),%xmm0
jmp    11f5 <main+0xc5>
cs nopw 0x0(%rax,%rax,1)
xorpd  %xmm3,%xmm3
cmpltsd %xmm0,%xmm3
movapd %xmm3,%xmm0
andpd  (%rsp),%xmm0
andnpd 0x20(%rsp),%xmm3
orpd   %xmm0,%xmm3
movapd %xmm3,%xmm2
movapd %xmm3,%xmm0
movapd %xmm3,0x20(%rsp)
subsd  %xmm1,%xmm2
andpd  0xe5a(%rip),%xmm2
movapd %xmm2,0x30(%rsp)
mov    %rbx,%rdi
movsd  %xmm1,0x18(%rsp)
mov    $0x3,%al
call   1050 <printf@plt>
movapd 0x30(%rsp),%xmm0
ucomisd 0xe26(%rip),%xmm0
movaps 0x20(%rsp),%xmm0
jbe    12b0 <main+0x180>
movaps %xmm0,0x20(%rsp)
movsd  0x18(%rsp),%xmm0
call   1040 <fn@plt>
movaps %xmm0,(%rsp)
movapd 0x20(%rsp),%xmm0
call   1040 <fn@plt>
movsd  0x18(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movapd (%rsp),%xmm2
mulsd  0x20(%rsp),%xmm2
subsd  %xmm0,%xmm2
movapd %xmm2,(%rsp)
movapd %xmm1,%xmm0
call   1040 <fn@plt>
movsd  %xmm0,0x30(%rsp)
movapd 0x20(%rsp),%xmm0
call   1040 <fn@plt>
movsd  0x30(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd (%rsp),%xmm0
divsd  %xmm1,%xmm0
movapd %xmm0,(%rsp)
movaps 0x20(%rsp),%xmm0
call   1040 <fn@plt>
movsd  %xmm0,0x30(%rsp)
movapd (%rsp),%xmm0
call   1040 <fn@plt>
mulsd  0x30(%rsp),%xmm0
ucomisd 0xd8c(%rip),%xmm0
movsd  0x18(%rsp),%xmm1
ja     1190 <main+0x60>
movapd (%rsp),%xmm1
jmp    1190 <main+0x60>
lea    0xdd1(%rip),%rdi
call   1030 <puts@plt>
jmp    12d3 <main+0x1a3>
movaps (%rsp),%xmm0
call   1040 <fn@plt>
movaps %xmm0,%xmm2
lea    0xd8c(%rip),%rdi
movapd (%rsp),%xmm0
movapd %xmm0,%xmm1
mov    $0x3,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"\0Aan=%e | bn=%e | precisao = %e\00"
@.str.1 = [43 x i8] c"\0ARaiz \C3\A9 aproximadamente %e | f(%e) = %e \0A\00"
@.str.2 = [19 x i8] c"Intervalo errado \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store i32 0, i32* %1
store double -2.000000e+00, double* %2
store double -1.000000e+00, double* %3
store double 5.000000e-03, double* %4
%6 = load double, double* %2
%7 = call double @fn(double %6)
%8 = load double, double* %3
%9 = call double @fn(double %8)
%10 = fmul double %7, %9
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %60
12: ; preds = %0
store double 0.000000e+00, double* %5
br label %13
13: ; preds = %46, %12
%14 = load double, double* %2
%15 = load double, double* %3
%16 = fsub double %14, %15
%17 = call double @llvm.fabs.f64(double %16)
%18 = load double, double* %4
%19 = fcmp ogt double %17, %18
br i1 %19, label %20, label %54
20: ; preds = %13
%21 = load double, double* %2
%22 = load double, double* %3
%23 = call double @fn(double %22)
%24 = load double, double* %3
%25 = load double, double* %2
%26 = call double @fn(double %25)
%27 = fmul double %24, %26
%28 = fneg double %27
%29 = call double @llvm.fmuladd.f64(double %21, double %23, double %28)
%30 = load double, double* %3
%31 = call double @fn(double %30)
%32 = load double, double* %2
%33 = call double @fn(double %32)
%34 = fsub double %31, %33
%35 = fdiv double %29, %34
store double %35, double* %5
%36 = load double, double* %2
%37 = call double @fn(double %36)
%38 = load double, double* %5
%39 = call double @fn(double %38)
%40 = fmul double %37, %39
%41 = fcmp ogt double %40, 0.000000e+00
br i1 %41, label %42, label %44
42: ; preds = %20
%43 = load double, double* %5
store double %43, double* %2
br label %46
44: ; preds = %20
%45 = load double, double* %5
store double %45, double* %3
br label %46
46: ; preds = %44, %42
%47 = load double, double* %2
%48 = load double, double* %3
%49 = load double, double* %2
%50 = load double, double* %3
%51 = fsub double %49, %50
%52 = call double @llvm.fabs.f64(double %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %47, double %48, double %52)
br label %13
54: ; preds = %13
%55 = load double, double* %5
%56 = load double, double* %5
%57 = load double, double* %5
%58 = call double @fn(double %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), double %55, double %56, double %58)
store i32 0, i32* %1
br label %62
60: ; preds = %0
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %62
62: ; preds = %60, %54
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
@.str = [31 x i8] c"\0Aan=%e | bn=%e | precisao = %e\00"
@.str.1 = [43 x i8] c"\0ARaiz \C3\A9 aproximadamente %e | f(%e) = %e \0A\00"
@str = [18 x i8] c"Intervalo errado \00"
define i32 @main() {
%1 = tail call double @fn(double -2.000000e+00)
%2 = tail call double @fn(double -1.000000e+00)
%3 = fmul double %1, %2
%4 = fcmp olt double %3, 0.000000e+00
br i1 %4, label %5, label %30
5: ; preds = %0, %5
%6 = phi double [ %22, %5 ], [ -1.000000e+00, %0 ]
%7 = phi double [ %21, %5 ], [ -2.000000e+00, %0 ]
%8 = tail call double @fn(double %6)
%9 = tail call double @fn(double %7)
%10 = fneg double %6
%11 = fmul double %9, %10
%12 = tail call double @llvm.fmuladd.f64(double %7, double %8, double %11)
%13 = tail call double @fn(double %6)
%14 = tail call double @fn(double %7)
%15 = fsub double %13, %14
%16 = fdiv double %12, %15
%17 = tail call double @fn(double %7)
%18 = tail call double @fn(double %16)
%19 = fmul double %17, %18
%20 = fcmp ogt double %19, 0.000000e+00
%21 = select i1 %20, double %16, double %7
%22 = select i1 %20, double %6, double %16
%23 = fsub double %21, %22
%24 = tail call double @llvm.fabs.f64(double %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %21, double %22, double %24)
%26 = fcmp ogt double %24, 5.000000e-03
br i1 %26, label %5, label %27
27: ; preds = %5
%28 = tail call double @fn(double %16)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), double %16, double %16, double %28)
br label %32
30: ; preds = %0
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
ret i32 0
}