#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);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
main() {
  float epsilon;
  float esquerdo;
  float direito;
  float medio;
  float largura = direito - esquerdo;
  int maximoIteracoes = 100;
  int iteracoes = 0;
  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);
  largura = direito - esquerdo;
  medio = (esquerdo + direito) / 2.0;
  while (largura > epsilon) {
    medio = (esquerdo + direito) / 2.0;
    float 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,-0x18(%rbp)
movl   $0x64,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe84(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe25(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x18(%rbp),%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    12d5 <main+0x1a5>
movss  -0xc(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdf3(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%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    124e <main+0x11e>
jp     124e <main+0x11e>
jmp    12d5 <main+0x1a5>
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x30(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    128c <main+0x15c>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    1296 <main+0x166>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     12d0 <main+0x1a0>
mov    -0x1c(%rbp),%esi
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d5 <main+0x1a5>
jmp    11e8 <main+0xb8>
movss  -0xc(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd15(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
mov    -0x3c(%rbp),%esi
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
lea    0xd7d(%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    $0x20,%rsp
lea    0xf25(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xf2f(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xf3d(%rip),%rdi
call   1030 <puts@plt>
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
movss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm2
movaps %xmm0,%xmm1
subss  %xmm2,%xmm1
xor    %ebx,%ebx
jmp    11d0 <main+0x90>
nopl   0x0(%rax,%rax,1)
movss  0x8(%rsp),%xmm2
movss  %xmm2,(%rsp)
movss  0x4(%rsp),%xmm0
movaps %xmm0,%xmm1
subss  %xmm2,%xmm1
add    $0x1,%ebx
cmp    $0x64,%ebx
je     123a <main+0xfa>
ucomiss 0x14(%rsp),%xmm1
jbe    1252 <main+0x112>
addss  %xmm2,%xmm0
mulss  0xe1d(%rip),%xmm0
movss  %xmm0,0x8(%rsp)
call   1040 <f@plt>
cvtsd2ss %xmm0,%xmm0
ucomiss 0xe0b(%rip),%xmm0
jne    11fd <main+0xbd>
jnp    1252 <main+0x112>
movss  (%rsp),%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x18(%rsp)
movss  0x8(%rsp),%xmm0
call   1040 <f@plt>
mulsd  0x18(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    11b0 <main+0x70>
movss  0x8(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
movss  (%rsp),%xmm2
jmp    11c1 <main+0x81>
lea    0xdd2(%rip),%rdi
mov    $0x64,%ebx
mov    $0x64,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movss  (%rsp),%xmm0
addss  0x4(%rsp),%xmm0
mulss  0xd9b(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1040 <f@plt>
movaps %xmm0,%xmm1
lea    0xdbc(%rip),%rdi
mov    %ebx,%esi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%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 float
%7 = alloca i32
%8 = alloca i32
%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* %6
store i32 100, i32* %7
store i32 0, i32* %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %3)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %4)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%19 = load float, float* %4
%20 = load float, float* %3
%21 = fsub float %19, %20
store float %21, float* %6
%22 = load float, float* %3
%23 = load float, float* %4
%24 = fadd float %22, %23
%25 = fpext float %24 to double
%26 = fdiv double %25, 2.000000e+00
%27 = fptrunc double %26 to float
store float %27, float* %5
br label %28
28: ; preds = %69, %0
%29 = load float, float* %6
%30 = load float, float* %2
%31 = fcmp ogt float %29, %30
br i1 %31, label %32, label %70
32: ; preds = %28
%33 = load float, float* %3
%34 = load float, float* %4
%35 = fadd float %33, %34
%36 = fpext float %35 to double
%37 = fdiv double %36, 2.000000e+00
%38 = fptrunc double %37 to float
store float %38, float* %5
%39 = load float, float* %5
%40 = call double @f(float %39)
%41 = fptrunc double %40 to float
store float %41, float* %9
%42 = load float, float* %9
%43 = fpext float %42 to double
%44 = fcmp oeq double %43, 0.000000e+00
br i1 %44, label %45, label %46
45: ; preds = %32
br label %70
46: ; preds = %32
%47 = load float, float* %3
%48 = call double @f(float %47)
%49 = load float, float* %5
%50 = call double @f(float %49)
%51 = fmul double %48, %50
%52 = fcmp olt double %51, 0.000000e+00
br i1 %52, label %53, label %55
53: ; preds = %46
%54 = load float, float* %5
store float %54, float* %4
br label %57
55: ; preds = %46
%56 = load float, float* %5
store float %56, float* %3
br label %57
57: ; preds = %55, %53
%58 = load float, float* %4
%59 = load float, float* %3
%60 = fsub float %58, %59
store float %60, float* %6
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
%63 = load i32, i32* %8
%64 = load i32, i32* %7
%65 = icmp sge i32 %63, %64
br i1 %65, label %66, label %69
66: ; preds = %57
%67 = load i32, i32* %7
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %67)
br label %70
69: ; preds = %57
br label %28
70: ; preds = %66, %45, %28
%71 = load float, float* %3
%72 = load float, float* %4
%73 = fadd float %71, %72
%74 = fpext float %73 to double
%75 = fdiv double %74, 2.000000e+00
%76 = fptrunc double %75 to float
store float %76, float* %5
%77 = load i32, i32* %8
%78 = load float, float* %5
%79 = fpext float %78 to double
%80 = load float, float* %5
%81 = call double @f(float %80)
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %77, double %79, double %81)
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 i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.6, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %3)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.7, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%13 = load float, float* %3
%14 = load float, float* %2
%15 = fsub float %13, %14
br label %16
16: ; preds = %39, %0
%17 = phi float [ %13, %0 ], [ %41, %39 ]
%18 = phi float [ %14, %0 ], [ %40, %39 ]
%19 = phi float [ %15, %0 ], [ %42, %39 ]
%20 = phi i32 [ 0, %0 ], [ %43, %39 ]
%21 = load float, float* %1
%22 = fcmp ogt float %19, %21
br i1 %22, label %23, label %47
23: ; preds = %16
%24 = fadd float %18, %17
%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 %47, label %29
29: ; preds = %23
%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 %37
35: ; preds = %29
store float %25, float* %3
%36 = load float, float* %2
br label %39
37: ; preds = %29
store float %25, float* %2
%38 = load float, float* %3
br label %39
39: ; preds = %37, %35
%40 = phi float [ %25, %37 ], [ %36, %35 ]
%41 = phi float [ %38, %37 ], [ %25, %35 ]
%42 = fsub float %41, %40
%43 = add nuw nsw i32 %20, 1
%44 = icmp eq i32 %43, 100
br i1 %44, label %45, label %16
45: ; preds = %39
%46 = 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 %47
47: ; preds = %23, %16, %45
%48 = phi i32 [ 100, %45 ], [ %20, %16 ], [ %20, %23 ]
%49 = load float, float* %2
%50 = load float, float* %3
%51 = fadd float %49, %50
%52 = fmul float %51, 5.000000e-01
%53 = fpext float %52 to double
%54 = call double @f(float %52)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %48, double %53, double %54)
ret i32 0
}