#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 calcError(double, double, int);
double pow(int, int);
int /*<<< orphan*/ printf(char *, double, int, ...);
double bissecao(double a, double b, int p, double (*f)(double x)) {
  double precision = .5 * pow(10, -p);
  int i = 0;
  double c;
  while ((b - a) / 2 > precision) {
    c = (a + b) / 2;
    printf("a: %lf,  b:%lf,  c: %lf\n", a, b, c);
    if (f(c) == 0 || (b - a) / 2 <= precision) {
      break;
    }
    if (f(a) * f(c) < 0) {
      b = c;
    } else {
      a = c;
    }
    i++;
  }
  double er = calcError(a, b, i);
  printf("erro %lf\n, interações:%d\n", er, i);
  return (a + b) / 2;
}


x86 assembly (clang, -O0):
<bissecao>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
xor    %esi,%esi
sub    -0x14(%rbp),%esi
mov    $0xa,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe9d(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  0xe83(%rip),%xmm1
divsd  %xmm1,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1271 <bissecao+0x141>
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xe62(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
cvttsd2si -0x10(%rbp),%esi
movsd  -0x38(%rbp),%xmm1
lea    0xe4b(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movsd  -0x38(%rbp),%xmm0
call   *%rax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ef <bissecao+0xbf>
jp     11ef <bissecao+0xbf>
jmp    1214 <bissecao+0xe4>
movsd  -0x10(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
movsd  0xe07(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1219 <bissecao+0xe9>
jmp    1271 <bissecao+0x141>
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x38(%rbp),%xmm0
call   *%rax
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1259 <bissecao+0x129>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1263 <bissecao+0x133>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1173 <bissecao+0x43>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mov    -0x2c(%rbp),%edi
call   1050 <calcError@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x2c(%rbp),%esi
lea    0xd92(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xd58(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bissecao>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
mov    %edi,%esi
movsd  %xmm1,0x8(%rsp)
movapd %xmm0,0x10(%rsp)
neg    %esi
mov    $0xa,%edi
call   1040 <pow@plt>
movsd  0x8(%rsp),%xmm3
movapd 0x10(%rsp),%xmm4
movsd  0xe96(%rip),%xmm2
mulsd  %xmm2,%xmm0
movapd %xmm3,%xmm5
subsd  %xmm4,%xmm5
mulsd  %xmm2,%xmm5
xor    %ebx,%ebx
ucomisd %xmm0,%xmm5
jbe    1279 <bissecao+0x149>
xor    %ebx,%ebx
lea    0xe79(%rip),%r15
movsd  %xmm0,0x48(%rsp)
jmp    11e4 <bissecao+0xb4>
nopw   0x0(%rax,%rax,1)
cmpltsd %xmm2,%xmm0
movapd 0x10(%rsp),%xmm4
andpd  %xmm0,%xmm4
andnpd 0x30(%rsp),%xmm0
orpd   %xmm0,%xmm4
add    $0x1,%ebx
movapd %xmm1,%xmm5
subsd  %xmm4,%xmm5
movsd  0xe34(%rip),%xmm2
mulsd  %xmm2,%xmm5
movsd  0x48(%rsp),%xmm0
ucomisd %xmm0,%xmm5
movapd %xmm1,%xmm3
jbe    128a <bissecao+0x15a>
movsd  %xmm5,0x28(%rsp)
movapd %xmm3,%xmm1
addsd  %xmm4,%xmm1
mulsd  %xmm2,%xmm1
movapd %xmm1,0x30(%rsp)
movsd  %xmm3,0x8(%rsp)
cvttsd2si %xmm3,%esi
mov    %r15,%rdi
movapd %xmm4,0x10(%rsp)
movapd %xmm4,%xmm0
mov    $0x2,%al
call   1030 <printf@plt>
movapd 0x30(%rsp),%xmm0
call   *%r14
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    122f <bissecao+0xff>
jnp    127f <bissecao+0x14f>
movsd  0x48(%rsp),%xmm0
ucomisd 0x28(%rsp),%xmm0
jae    127f <bissecao+0x14f>
movaps 0x10(%rsp),%xmm0
call   *%r14
movsd  %xmm0,0x28(%rsp)
movapd 0x30(%rsp),%xmm0
call   *%r14
xorpd  %xmm2,%xmm2
mulsd  0x28(%rsp),%xmm0
ucomisd %xmm0,%xmm2
movapd 0x30(%rsp),%xmm1
ja     11a0 <bissecao+0x70>
movsd  0x8(%rsp),%xmm1
jmp    11a0 <bissecao+0x70>
movapd %xmm3,%xmm1
jmp    128a <bissecao+0x15a>
movsd  0x8(%rsp),%xmm1
movaps 0x10(%rsp),%xmm4
movsd  %xmm1,0x30(%rsp)
movapd %xmm4,0x10(%rsp)
movapd %xmm4,%xmm0
mov    %ebx,%edi
call   1050 <calcError@plt>
lea    0xd79(%rip),%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0x30(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
mulsd  0xd3b(%rip),%xmm0
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"a: %lf, b:%lf, c: %lf\0A\00"
@.str.1 = [28 x i8] c"erro %lf\0A, intera\C3\A7\C3\B5es:%d\0A\00"
define double @bissecao(double %0, double %1, i32 %2, double (double)* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double (double)*
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca double
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
store double (double)* %3, double (double)** %8
%13 = load i32, i32* %7
%14 = sub nsw i32 0, %13
%15 = call double @pow(i32 10, i32 %14)
%16 = fmul double 5.000000e-01, %15
store double %16, double* %9
store i32 0, i32* %10
br label %17
17: ; preds = %59, %4
%18 = load double, double* %6
%19 = load double, double* %5
%20 = fsub double %18, %19
%21 = fdiv double %20, 2.000000e+00
%22 = load double, double* %9
%23 = fcmp ogt double %21, %22
br i1 %23, label %24, label %62
24: ; preds = %17
%25 = load double, double* %5
%26 = load double, double* %6
%27 = fadd double %25, %26
%28 = fdiv double %27, 2.000000e+00
store double %28, double* %11
%29 = load double, double* %5
%30 = load double, double* %6
%31 = fptosi double %30 to i32
%32 = load double, double* %11
%33 = call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %29, i32 %31, double %32)
%34 = load double (double)*, double (double)** %8
%35 = load double, double* %11
%36 = call double %34(double %35)
%37 = fcmp oeq double %36, 0.000000e+00
br i1 %37, label %45, label %38
38: ; preds = %24
%39 = load double, double* %6
%40 = load double, double* %5
%41 = fsub double %39, %40
%42 = fdiv double %41, 2.000000e+00
%43 = load double, double* %9
%44 = fcmp ole double %42, %43
br i1 %44, label %45, label %46
45: ; preds = %38, %24
br label %62
46: ; preds = %38
%47 = load double (double)*, double (double)** %8
%48 = load double, double* %5
%49 = call double %47(double %48)
%50 = load double (double)*, double (double)** %8
%51 = load double, double* %11
%52 = call double %50(double %51)
%53 = fmul double %49, %52
%54 = fcmp olt double %53, 0.000000e+00
br i1 %54, label %55, label %57
55: ; preds = %46
%56 = load double, double* %11
store double %56, double* %6
br label %59
57: ; preds = %46
%58 = load double, double* %11
store double %58, double* %5
br label %59
59: ; preds = %57, %55
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
br label %17
62: ; preds = %45, %17
%63 = load double, double* %5
%64 = load double, double* %6
%65 = load i32, i32* %10
%66 = call double @calcError(double %63, double %64, i32 %65)
store double %66, double* %12
%67 = load double, double* %12
%68 = load i32, i32* %10
%69 = call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), double %67, i32 %68)
%70 = load double, double* %5
%71 = load double, double* %6
%72 = fadd double %70, %71
%73 = fdiv double %72, 2.000000e+00
ret double %73
}

LLVM IR (-O2):
@.str = [25 x i8] c"a: %lf, b:%lf, c: %lf\0A\00"
@.str.1 = [28 x i8] c"erro %lf\0A, intera\C3\A7\C3\B5es:%d\0A\00"
define double @bissecao(double %0, double %1, i32 %2, double (double)* nocapture %3) {
%5 = sub nsw i32 0, %2
%6 = tail call double @pow(i32 10, i32 %5)
%7 = fmul double %6, 5.000000e-01
%8 = fsub double %1, %0
%9 = fmul double %8, 5.000000e-01
%10 = fcmp ogt double %9, %7
br i1 %10, label %11, label %35
11: ; preds = %4, %24
%12 = phi double [ %33, %24 ], [ %9, %4 ]
%13 = phi double [ %30, %24 ], [ %0, %4 ]
%14 = phi double [ %29, %24 ], [ %1, %4 ]
%15 = phi i32 [ %31, %24 ], [ 0, %4 ]
%16 = fadd double %14, %13
%17 = fmul double %16, 5.000000e-01
%18 = fptosi double %14 to i32
%19 = tail call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %13, i32 %18, double %17)
%20 = tail call double %3(double %17)
%21 = fcmp une double %20, 0.000000e+00
%22 = fcmp ugt double %12, %7
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %24, label %35
24: ; preds = %11
%25 = tail call double %3(double %13)
%26 = tail call double %3(double %17)
%27 = fmul double %25, %26
%28 = fcmp olt double %27, 0.000000e+00
%29 = select i1 %28, double %17, double %14
%30 = select i1 %28, double %13, double %17
%31 = add nuw nsw i32 %15, 1
%32 = fsub double %29, %30
%33 = fmul double %32, 5.000000e-01
%34 = fcmp ogt double %33, %7
br i1 %34, label %11, label %35
35: ; preds = %24, %11, %4
%36 = phi i32 [ 0, %4 ], [ %15, %11 ], [ %31, %24 ]
%37 = phi double [ %1, %4 ], [ %14, %11 ], [ %29, %24 ]
%38 = phi double [ %0, %4 ], [ %13, %11 ], [ %30, %24 ]
%39 = tail call double @calcError(double %38, double %37, i32 %36)
%40 = tail call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), double %39, i32 %36)
%41 = fadd double %37, %38
%42 = fmul double %41, 5.000000e-01
ret double %42
}