#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 = 1;
  double b = 2;
  double erro = 0.00005;
  if (fn(a) * fn(b) < 0) {
    double x = 0;
    while (fabs(a - b) > erro) {
      x = (a + b) / 2;
      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    $0x50,%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    128a <main+0x16a>
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    1245 <main+0x125>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe49(%rip),%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    1209 <main+0xe9>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1213 <main+0xf3>
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 0xdf2(%rip),%xmm3
pand   %xmm3,%xmm2
lea    0xdf7(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
jmp    118d <main+0x6d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fn@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
lea    0xdd8(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129f <main+0x17f>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%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    1248 <main+0x118>
lea    0xed2(%rip),%rbx
movsd  0xe92(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xe7c(%rip),%xmm0
jmp    11f2 <main+0xc2>
cs nopw 0x0(%rax,%rax,1)
xorpd  %xmm3,%xmm3
cmpltsd %xmm0,%xmm3
movapd %xmm3,%xmm0
andpd  (%rsp),%xmm0
andnpd 0x30(%rsp),%xmm3
orpd   %xmm0,%xmm3
movapd %xmm3,%xmm2
movapd %xmm3,%xmm0
movapd %xmm3,0x30(%rsp)
subsd  %xmm1,%xmm2
andpd  0xe6a(%rip),%xmm2
movapd %xmm2,0x20(%rsp)
mov    %rbx,%rdi
movsd  %xmm1,0x18(%rsp)
mov    $0x3,%al
call   1050 <printf@plt>
movapd 0x20(%rsp),%xmm0
ucomisd 0xe2e(%rip),%xmm0
movapd 0x30(%rsp),%xmm0
jbe    1256 <main+0x126>
movapd %xmm0,%xmm1
addsd  0x18(%rsp),%xmm1
mulsd  0xe0c(%rip),%xmm1
movapd %xmm1,(%rsp)
movapd %xmm0,0x30(%rsp)
call   1040 <fn@plt>
movsd  %xmm0,0x20(%rsp)
movapd (%rsp),%xmm0
call   1040 <fn@plt>
mulsd  0x20(%rsp),%xmm0
ucomisd 0xdee(%rip),%xmm0
movsd  0x18(%rsp),%xmm1
ja     1190 <main+0x60>
movapd (%rsp),%xmm1
jmp    1190 <main+0x60>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
jmp    1279 <main+0x149>
movaps (%rsp),%xmm0
call   1040 <fn@plt>
movaps %xmm0,%xmm2
lea    0xdf6(%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 1.000000e+00, double* %2
store double 2.000000e+00, double* %3
store double 5.000000e-05, 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 %49
12: ; preds = %0
store double 0.000000e+00, double* %5
br label %13
13: ; preds = %35, %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 %43
20: ; preds = %13
%21 = load double, double* %2
%22 = load double, double* %3
%23 = fadd double %21, %22
%24 = fdiv double %23, 2.000000e+00
store double %24, double* %5
%25 = load double, double* %2
%26 = call double @fn(double %25)
%27 = load double, double* %5
%28 = call double @fn(double %27)
%29 = fmul double %26, %28
%30 = fcmp ogt double %29, 0.000000e+00
br i1 %30, label %31, label %33
31: ; preds = %20
%32 = load double, double* %5
store double %32, double* %2
br label %35
33: ; preds = %20
%34 = load double, double* %5
store double %34, double* %3
br label %35
35: ; preds = %33, %31
%36 = load double, double* %2
%37 = load double, double* %3
%38 = load double, double* %2
%39 = load double, double* %3
%40 = fsub double %38, %39
%41 = call double @llvm.fabs.f64(double %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %36, double %37, double %41)
br label %13
43: ; preds = %13
%44 = load double, double* %5
%45 = load double, double* %5
%46 = load double, double* %5
%47 = call double @fn(double %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), double %44, double %45, double %47)
store i32 0, i32* %1
br label %51
49: ; preds = %0
%50 = 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 %51
51: ; preds = %49, %43
%52 = load i32, i32* %1
ret i32 %52
}

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 1.000000e+00)
%2 = tail call double @fn(double 2.000000e+00)
%3 = fmul double %1, %2
%4 = fcmp olt double %3, 0.000000e+00
br i1 %4, label %5, label %23
5: ; preds = %0, %5
%6 = phi double [ %15, %5 ], [ 2.000000e+00, %0 ]
%7 = phi double [ %14, %5 ], [ 1.000000e+00, %0 ]
%8 = fadd double %7, %6
%9 = fmul double %8, 5.000000e-01
%10 = tail call double @fn(double %7)
%11 = tail call double @fn(double %9)
%12 = fmul double %10, %11
%13 = fcmp ogt double %12, 0.000000e+00
%14 = select i1 %13, double %9, double %7
%15 = select i1 %13, double %6, double %9
%16 = fsub double %14, %15
%17 = tail call double @llvm.fabs.f64(double %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %14, double %15, double %17)
%19 = fcmp ogt double %17, 5.000000e-05
br i1 %19, label %5, label %20
20: ; preds = %5
%21 = tail call double @fn(double %9)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), double %9, double %9, double %21)
br label %25
23: ; preds = %0
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
ret i32 0
}