#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 */
int f(double);
int fabs(double);
int /*<<< orphan*/ printf(char *, int, ...);
double biseccion(double a, double b, double err, int maxIter) {
  double c, errAprox = 1, valorReal = 0, valorAprox = 0;
  int ciclos = 0;
  c = (a + b) / 2;
  printf("\t%3d %8.4f %8.4f %8.4f\n", ciclos, a, b, c);
  do {
    if ((f(a) * f(c)) <= 0) {
      b = c;
    } else {
      a = c;
    }
    valorAprox = c;
    c = (a + b) / 2;
    valorReal = c;
    errAprox = fabs((valorReal - valorAprox) / valorReal) * 100;
    ciclos++;
    printf("|\n\t%3d %8.4f %8.4f %8.4f %8.8f \n", ciclos, a, b, c, errAprox);
  } while (ciclos <= maxIter && err < errAprox);
  if (ciclos <= maxIter) {
    printf("\n\n\t La raíz de la ec. es: %lf\n", c);
  } else {
    printf("No se encontro la raíz en  %d iteraciones\n", maxIter);
  }
  return c;
}


x86 assembly (clang, -O0):
<biseccion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
movsd  0xeb6(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xe80(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x44(%rbp),%esi
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
lea    0xe6e(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
movsd  -0x8(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
imul   %ecx,%eax
cmp    $0x0,%eax
jg     11e0 <biseccion+0xb0>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11ea <biseccion+0xba>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xdfa(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
call   1050 <fabs@plt>
imul   $0x64,%eax,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
lea    0xdc8(%rip),%rdi
mov    $0x4,%al
call   1040 <printf@plt>
mov    -0x44(%rbp),%ecx
xor    %eax,%eax
cmp    -0x1c(%rbp),%ecx
mov    %al,-0x49(%rbp)
jg     128c <biseccion+0x15c>
movsd  -0x18(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11a9 <biseccion+0x79>
mov    -0x44(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     12bb <biseccion+0x18b>
cvttsd2si -0x28(%rbp),%esi
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12cc <biseccion+0x19c>
mov    -0x1c(%rbp),%esi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<biseccion>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%r15d
movsd  %xmm2,0x20(%rsp)
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
mulsd  0xead(%rip),%xmm2
lea    0xeae(%rip),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
movsd  %xmm0,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm2,(%rsp)
mov    $0x3,%al
call   1040 <printf@plt>
lea    0xea3(%rip),%r14
nopl   (%rax)
mov    %ebp,%ebx
movsd  0x8(%rsp),%xmm0
call   1030 <f@plt>
mov    %eax,%ebp
movsd  (%rsp),%xmm0
call   1030 <f@plt>
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
imul   %ebp,%eax
movapd %xmm1,%xmm2
test   %eax,%eax
jle    11b9 <biseccion+0x89>
movsd  0x10(%rsp),%xmm2
movapd %xmm1,%xmm0
movsd  %xmm2,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
movapd %xmm0,%xmm3
addsd  %xmm2,%xmm3
mulsd  0xe2b(%rip),%xmm3
movsd  %xmm3,0x18(%rsp)
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
divsd  %xmm3,%xmm0
call   1050 <fabs@plt>
imul   $0x64,%eax,%eax
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
lea    0x1(%rbx),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
movsd  %xmm3,(%rsp)
mov    $0x4,%al
call   1040 <printf@plt>
movsd  0x18(%rsp),%xmm0
cmp    %r15d,%ebx
jge    123d <biseccion+0x10d>
movsd  (%rsp),%xmm1
ucomisd 0x20(%rsp),%xmm1
movsd  %xmm0,(%rsp)
ja     1180 <biseccion+0x50>
cmp    %r15d,%ebx
jge    124f <biseccion+0x11f>
cvttsd2si %xmm0,%esi
lea    0xdf4(%rip),%rdi
jmp    1259 <biseccion+0x129>
lea    0xe0b(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0x18(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"\09%3d %8.4f %8.4f %8.4f\0A\00"
@.str.1 = [33 x i8] c"|\0A\09%3d %8.4f %8.4f %8.4f %8.8f \0A\00"
@.str.2 = [32 x i8] c"\0A\0A\09 La ra\C3\ADz de la ec. es: %lf\0A\00"
@.str.3 = [44 x i8] c"No se encontro la ra\C3\ADz en %d iteraciones\0A\00"
define double @biseccion(double %0, double %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store i32 %3, i32* %8
store double 1.000000e+00, double* %10
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
store i32 0, i32* %13
%14 = load double, double* %5
%15 = load double, double* %6
%16 = fadd double %14, %15
%17 = fdiv double %16, 2.000000e+00
store double %17, double* %9
%18 = load i32, i32* %13
%19 = load double, double* %5
%20 = load double, double* %6
%21 = load double, double* %9
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %18, double %19, double %20, double %21)
br label %23
23: ; preds = %65, %4
%24 = load double, double* %5
%25 = call i32 @f(double %24)
%26 = load double, double* %9
%27 = call i32 @f(double %26)
%28 = mul nsw i32 %25, %27
%29 = icmp sle i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = load double, double* %9
store double %31, double* %6
br label %34
32: ; preds = %23
%33 = load double, double* %9
store double %33, double* %5
br label %34
34: ; preds = %32, %30
%35 = load double, double* %9
store double %35, double* %12
%36 = load double, double* %5
%37 = load double, double* %6
%38 = fadd double %36, %37
%39 = fdiv double %38, 2.000000e+00
store double %39, double* %9
%40 = load double, double* %9
store double %40, double* %11
%41 = load double, double* %11
%42 = load double, double* %12
%43 = fsub double %41, %42
%44 = load double, double* %11
%45 = fdiv double %43, %44
%46 = call i32 @fabs(double %45)
%47 = mul nsw i32 %46, 100
%48 = sitofp i32 %47 to double
store double %48, double* %10
%49 = load i32, i32* %13
%50 = add nsw i32 %49, 1
store i32 %50, i32* %13
%51 = load i32, i32* %13
%52 = load double, double* %5
%53 = load double, double* %6
%54 = load double, double* %9
%55 = load double, double* %10
%56 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %51, double %52, double %53, double %54, double %55)
br label %57
57: ; preds = %34
%58 = load i32, i32* %13
%59 = load i32, i32* %8
%60 = icmp sle i32 %58, %59
br i1 %60, label %61, label %65
61: ; preds = %57
%62 = load double, double* %7
%63 = load double, double* %10
%64 = fcmp olt double %62, %63
br label %65
65: ; preds = %61, %57
%66 = phi i1 [ false, %57 ], [ %64, %61 ]
br i1 %66, label %23, label %67
67: ; preds = %65
%68 = load i32, i32* %13
%69 = load i32, i32* %8
%70 = icmp sle i32 %68, %69
br i1 %70, label %71, label %75
71: ; preds = %67
%72 = load double, double* %9
%73 = fptosi double %72 to i32
%74 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %73)
br label %78
75: ; preds = %67
%76 = load i32, i32* %8
%77 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %75, %71
%79 = load double, double* %9
ret double %79
}

LLVM IR (-O2):
@.str = [24 x i8] c"\09%3d %8.4f %8.4f %8.4f\0A\00"
@.str.1 = [33 x i8] c"|\0A\09%3d %8.4f %8.4f %8.4f %8.8f \0A\00"
@.str.2 = [32 x i8] c"\0A\0A\09 La ra\C3\ADz de la ec. es: %lf\0A\00"
@.str.3 = [44 x i8] c"No se encontro la ra\C3\ADz en %d iteraciones\0A\00"
define double @biseccion(double %0, double %1, double %2, i32 %3) {
%5 = fadd double %0, %1
%6 = fmul double %5, 5.000000e-01
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 0, double %0, double %1, double %6)
br label %8
8: ; preds = %8, %4
%9 = phi double [ %1, %4 ], [ %17, %8 ]
%10 = phi double [ %0, %4 ], [ %18, %8 ]
%11 = phi double [ %6, %4 ], [ %20, %8 ]
%12 = phi i32 [ 0, %4 ], [ %26, %8 ]
%13 = tail call i32 @f(double %10)
%14 = tail call i32 @f(double %11)
%15 = mul nsw i32 %14, %13
%16 = icmp slt i32 %15, 1
%17 = select i1 %16, double %11, double %9
%18 = select i1 %16, double %10, double %11
%19 = fadd double %18, %17
%20 = fmul double %19, 5.000000e-01
%21 = fsub double %20, %11
%22 = fdiv double %21, %20
%23 = tail call i32 @fabs(double %22)
%24 = mul nsw i32 %23, 100
%25 = sitofp i32 %24 to double
%26 = add nuw nsw i32 %12, 1
%27 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %26, double %18, double %17, double %20, double %25)
%28 = icmp slt i32 %12, %3
%29 = fcmp ogt double %25, %2
%30 = and i1 %28, %29
br i1 %30, label %8, label %31
31: ; preds = %8
br i1 %28, label %32, label %35
32: ; preds = %31
%33 = fptosi double %20 to i32
%34 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %37
35: ; preds = %31
%36 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %3)
br label %37
37: ; preds = %35, %32
ret double %20
}