#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 f(float);
float fabs(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
main() {
  float epsilon;
  float esquerdo;
  float direito;
  float largura = direito - esquerdo;
  int maximoIteracoes = 100;
  int iteracoes = 0;
  float medio = (esquerdo + direito) / 2.0;
  float fMedio = f(medio);
  printf("Digite o extremo esquerdo do intervalo:\n");
  scanf("%f", &esquerdo);
  printf("Digite o extremo direito do intervalo:\n");
  scanf("%f", &direito);
  printf("Digite a precisão requerida:\n");
  scanf("%f", &epsilon);
  while (fabs(fMedio) > epsilon) {
    medio = (esquerdo + direito) / 2.0;
    fMedio = f(medio);
    if (fMedio == 0.0) {
      break;
    }
    if (f(esquerdo) * f(medio) < 0) {
      direito = medio;
    } else {
      esquerdo = medio;
    }
    largura = direito - esquerdo;
    iteracoes = iteracoes + 1;
    if (iteracoes >= maximoIteracoes) {
      printf("Limite de iterações (=%d) atingido!!!\n\n", maximoIteracoes);
      break;
    }
  }
  medio = (esquerdo + direito) / 2.0;
  printf("Após %d iterações foi obtido x = %f e f(x) = %f\n", iteracoes, medio,
         f(medio));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x64,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movss  -0xc(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe7e(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
call   1030 <f@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7a(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5c(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movss  -0x24(%rbp),%xmm0
call   1050 <fabs@plt>
ucomiss -0x8(%rbp),%xmm0
jbe    12ee <main+0x1ae>
movss  -0xc(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdda(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
call   1030 <f@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1267 <main+0x127>
jp     1267 <main+0x127>
jmp    12ee <main+0x1ae>
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x30(%rbp)
movss  -0x20(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    12a5 <main+0x165>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    12af <main+0x16f>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     12e9 <main+0x1a9>
mov    -0x18(%rbp),%esi
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ee <main+0x1ae>
jmp    11fc <main+0xbc>
movss  -0xc(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xcfc(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movss  -0x20(%rbp),%xmm0
call   1030 <f@plt>
mov    -0x3c(%rbp),%esi
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
lea    0xd64(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
movss  0xeb3(%rip),%xmm0
call   1040 <f@plt>
cvtsd2ss %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xf27(%rip),%rdi
call   1030 <puts@plt>
lea    0xeba(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xf2f(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xf3d(%rip),%rdi
call   1030 <puts@plt>
lea    0x1c(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
movaps 0x20(%rsp),%xmm0
xor    %ebx,%ebx
jmp    11dd <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
movss  0x10(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
movaps 0x20(%rsp),%xmm0
add    $0x1,%ebx
cmp    $0x64,%ebx
je     1263 <main+0x123>
andps  0xe2c(%rip),%xmm0
ucomiss 0x1c(%rsp),%xmm0
jbe    127b <main+0x13b>
movss  0x8(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
mulss  0xe01(%rip),%xmm0
movss  %xmm0,0x10(%rsp)
call   1040 <f@plt>
cvtsd2ss %xmm0,%xmm0
ucomiss 0xdef(%rip),%xmm0
jne    121d <main+0xdd>
jnp    127b <main+0x13b>
movaps %xmm0,0x20(%rsp)
movss  0x8(%rsp),%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x38(%rsp)
movss  0x10(%rsp),%xmm0
call   1040 <f@plt>
mulsd  0x38(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    11c0 <main+0x80>
movss  0x10(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
jmp    11cc <main+0x8c>
lea    0xdc1(%rip),%rdi
mov    $0x64,%ebx
mov    $0x64,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movss  0x8(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
mulss  0xd75(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
call   1040 <f@plt>
movaps %xmm0,%xmm1
lea    0xdaa(%rip),%rdi
mov    %ebx,%esi
movsd  0x10(%rsp),%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Digite o extremo esquerdo do intervalo:\0A\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [40 x i8] c"Digite o extremo direito do intervalo:\0A\00"
@.str.3 = [31 x i8] c"Digite a precis\C3\A3o requerida:\0A\00"
@.str.4 = [42 x i8] c"Limite de itera\C3\A7\C3\B5es (=%d) atingido!!!\0A\0A\00"
@.str.5 = [52 x i8] c"Ap\C3\B3s %d itera\C3\A7\C3\B5es foi obtido x = %f e f(x) = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
%9 = alloca float
store i32 0, i32* %1
%10 = load float, float* %4
%11 = load float, float* %3
%12 = fsub float %10, %11
store float %12, float* %5
store i32 100, i32* %6
store i32 0, i32* %7
%13 = load float, float* %3
%14 = load float, float* %4
%15 = fadd float %13, %14
%16 = fpext float %15 to double
%17 = fdiv double %16, 2.000000e+00
%18 = fptrunc double %17 to float
store float %18, float* %8
%19 = load float, float* %8
%20 = call double @f(float %19)
%21 = fptrunc double %20 to float
store float %21, float* %9
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %3)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %4)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
br label %28
28: ; preds = %70, %0
%29 = load float, float* %9
%30 = call float @fabs(float %29)
%31 = load float, float* %2
%32 = fcmp ogt float %30, %31
br i1 %32, label %33, label %71
33: ; preds = %28
%34 = load float, float* %3
%35 = load float, float* %4
%36 = fadd float %34, %35
%37 = fpext float %36 to double
%38 = fdiv double %37, 2.000000e+00
%39 = fptrunc double %38 to float
store float %39, float* %8
%40 = load float, float* %8
%41 = call double @f(float %40)
%42 = fptrunc double %41 to float
store float %42, float* %9
%43 = load float, float* %9
%44 = fpext float %43 to double
%45 = fcmp oeq double %44, 0.000000e+00
br i1 %45, label %46, label %47
46: ; preds = %33
br label %71
47: ; preds = %33
%48 = load float, float* %3
%49 = call double @f(float %48)
%50 = load float, float* %8
%51 = call double @f(float %50)
%52 = fmul double %49, %51
%53 = fcmp olt double %52, 0.000000e+00
br i1 %53, label %54, label %56
54: ; preds = %47
%55 = load float, float* %8
store float %55, float* %4
br label %58
56: ; preds = %47
%57 = load float, float* %8
store float %57, float* %3
br label %58
58: ; preds = %56, %54
%59 = load float, float* %4
%60 = load float, float* %3
%61 = fsub float %59, %60
store float %61, float* %5
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
%64 = load i32, i32* %7
%65 = load i32, i32* %6
%66 = icmp sge i32 %64, %65
br i1 %66, label %67, label %70
67: ; preds = %58
%68 = load i32, i32* %6
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %68)
br label %71
70: ; preds = %58
br label %28
71: ; preds = %67, %46, %28
%72 = load float, float* %3
%73 = load float, float* %4
%74 = fadd float %72, %73
%75 = fpext float %74 to double
%76 = fdiv double %75, 2.000000e+00
%77 = fptrunc double %76 to float
store float %77, float* %8
%78 = load i32, i32* %7
%79 = load float, float* %8
%80 = fpext float %79 to double
%81 = load float, float* %8
%82 = call double @f(float %81)
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %78, double %80, double %82)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%f\00"
@.str.4 = [42 x i8] c"Limite de itera\C3\A7\C3\B5es (=%d) atingido!!!\0A\0A\00"
@.str.5 = [52 x i8] c"Ap\C3\B3s %d itera\C3\A7\C3\B5es foi obtido x = %f e f(x) = %f\0A\00"
@str = [40 x i8] c"Digite o extremo esquerdo do intervalo:\00"
@str.6 = [39 x i8] c"Digite o extremo direito do intervalo:\00"
@str.7 = [30 x i8] c"Digite a precis\C3\A3o requerida:\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = bitcast float* %1 to i8*
%5 = bitcast float* %2 to i8*
%6 = bitcast float* %3 to i8*
%7 = tail call double @f(float 0x7FF8000000000000)
%8 = fptrunc double %7 to float
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.6, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %3)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.7, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
br label %15
15: ; preds = %37, %0
%16 = phi i32 [ 0, %0 ], [ %38, %37 ]
%17 = phi float [ %8, %0 ], [ %27, %37 ]
%18 = call float @llvm.fabs.f32(float %17)
%19 = load float, float* %1
%20 = fcmp ogt float %18, %19
br i1 %20, label %21, label %42
21: ; preds = %15
%22 = load float, float* %2
%23 = load float, float* %3
%24 = fadd float %22, %23
%25 = fmul float %24, 5.000000e-01
%26 = call double @f(float %25)
%27 = fptrunc double %26 to float
%28 = fcmp oeq float %27, 0.000000e+00
br i1 %28, label %42, label %29
29: ; preds = %21
%30 = load float, float* %2
%31 = call double @f(float %30)
%32 = call double @f(float %25)
%33 = fmul double %31, %32
%34 = fcmp olt double %33, 0.000000e+00
br i1 %34, label %35, label %36
35: ; preds = %29
store float %25, float* %3
br label %37
36: ; preds = %29
store float %25, float* %2
br label %37
37: ; preds = %36, %35
%38 = add nuw nsw i32 %16, 1
%39 = icmp eq i32 %38, 100
br i1 %39, label %40, label %15
40: ; preds = %37
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 100)
br label %42
42: ; preds = %21, %15, %40
%43 = phi i32 [ 100, %40 ], [ %16, %15 ], [ %16, %21 ]
%44 = load float, float* %2
%45 = load float, float* %3
%46 = fadd float %44, %45
%47 = fmul float %46, 5.000000e-01
%48 = fpext float %47 to double
%49 = call double @f(float %47)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %43, double %48, double %49)
ret i32 0
}