#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 calc_fa(double);
double calc_fx(double);
int calc_k(double, double);
double calc_ponto_medio(double, double);
int existence(double, double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
int main() {
  double a, b;
  printf("Digite o primeiro valor do intervalo: \n");
  scanf("%lf", &a);
  printf("Digite o segundo valor do intervalo: \n");
  scanf("%lf", &b);
  if (existence(a, b) == 1) {
    int k = calc_k(a, b);
    double x = 0.0;
    double fx = 0.0;
    double fa = 0.0;
    for (int i = 0; i < k; i++) {
      x = calc_ponto_medio(a, b);
      fx = calc_fx(x);
      fa = calc_fa(a);
      if (fx * fa > 0) {
        a = x;
      } else {
        b = x;
      }
    }
    printf("%.11lf \n", x);
  } else {
    printf("Nao existe raiz neste Ponto\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe94(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1080 <scanf@plt>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe76(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <scanf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1090 <existence@plt>
cmp    $0x1,%eax
jne    129d <main+0x12d>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1060 <calc_k@plt>
mov    %eax,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1285 <main+0x115>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1040 <calc_ponto_medio@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1070 <calc_fx@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <calc_fa@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1268 <main+0xf8>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1272 <main+0x102>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1277 <main+0x107>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1204 <main+0x94>
movsd  -0x28(%rbp),%xmm0
lea    0xdc2(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    12ab <main+0x13b>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
lea    0xe70(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1090 <scanf@plt>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <scanf@plt>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   10a0 <existence@plt>
cmp    $0x1,%eax
jne    1249 <main+0xc9>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1070 <calc_k@plt>
test   %eax,%eax
jle    1257 <main+0xd7>
mov    %eax,%ebx
jmp    1201 <main+0x81>
nopl   0x0(%rax)
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0xffffffff,%ebx
je     125a <main+0xda>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1050 <calc_ponto_medio@plt>
movsd  %xmm0,0x10(%rsp)
call   1080 <calc_fx@plt>
movsd  %xmm0,0x18(%rsp)
movsd  (%rsp),%xmm0
call   1040 <calc_fa@plt>
mulsd  0x18(%rsp),%xmm0
ucomisd 0xdc6(%rip),%xmm0
jbe    11f0 <main+0x70>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rsp)
jmp    11fc <main+0x7c>
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
jmp    1268 <main+0xe8>
xorps  %xmm0,%xmm0
lea    0xdab(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Digite o primeiro valor do intervalo: \0A\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [39 x i8] c"Digite o segundo valor do intervalo: \0A\00"
@.str.3 = [9 x i8] c"%.11lf \0A\00"
@.str.4 = [29 x i8] c"Nao existe raiz neste Ponto\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%13 = load double, double* %2
%14 = load double, double* %3
%15 = call i32 @existence(double %13, double %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %48
17: ; preds = %0
%18 = load double, double* %2
%19 = load double, double* %3
%20 = call i32 @calc_k(double %18, double %19)
store i32 %20, i32* %4
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %21
21: ; preds = %42, %17
%22 = load i32, i32* %8
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %45
25: ; preds = %21
%26 = load double, double* %2
%27 = load double, double* %3
%28 = call double @calc_ponto_medio(double %26, double %27)
store double %28, double* %5
%29 = load double, double* %5
%30 = call double @calc_fx(double %29)
store double %30, double* %6
%31 = load double, double* %2
%32 = call double @calc_fa(double %31)
store double %32, double* %7
%33 = load double, double* %6
%34 = load double, double* %7
%35 = fmul double %33, %34
%36 = fcmp ogt double %35, 0.000000e+00
br i1 %36, label %37, label %39
37: ; preds = %25
%38 = load double, double* %5
store double %38, double* %2
br label %41
39: ; preds = %25
%40 = load double, double* %5
store double %40, double* %3
br label %41
41: ; preds = %39, %37
br label %42
42: ; preds = %41
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %21
45: ; preds = %21
%46 = load double, double* %5
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double %46)
br label %50
48: ; preds = %0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %45
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%lf\00"
@.str.3 = [9 x i8] c"%.11lf \0A\00"
@str = [39 x i8] c"Digite o primeiro valor do intervalo: \00"
@str.5 = [38 x i8] c"Digite o segundo valor do intervalo: \00"
@str.6 = [28 x i8] c"Nao existe raiz neste Ponto\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = bitcast double* %1 to i8*
%4 = bitcast double* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%9 = load double, double* %1
%10 = load double, double* %2
%11 = call i32 @existence(double %9, double %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %36
13: ; preds = %0
%14 = load double, double* %1
%15 = load double, double* %2
%16 = call i32 @calc_k(double %14, double %15)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %33, %13
%19 = phi double [ 0.000000e+00, %13 ], [ %25, %33 ]
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double %19)
br label %38
21: ; preds = %13, %33
%22 = phi i32 [ %34, %33 ], [ 0, %13 ]
%23 = load double, double* %1
%24 = load double, double* %2
%25 = call double @calc_ponto_medio(double %23, double %24)
%26 = call double @calc_fx(double %25)
%27 = load double, double* %1
%28 = call double @calc_fa(double %27)
%29 = fmul double %26, %28
%30 = fcmp ogt double %29, 0.000000e+00
br i1 %30, label %31, label %32
31: ; preds = %21
store double %25, double* %1
br label %33
32: ; preds = %21
store double %25, double* %2
br label %33
33: ; preds = %31, %32
%34 = add nuw nsw i32 %22, 1
%35 = icmp eq i32 %34, %16
br i1 %35, label %18, label %21
36: ; preds = %0
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.6, i64 0, i64 0))
br label %38
38: ; preds = %36, %18
ret i32 0
}