#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);
double pow(int, int);
int /*<<< orphan*/ printf(char *, int, double, ...);
int /*<<< orphan*/ system(char *);
int main() {
  double tol = pow(10, -11);
  double a = 2;
  double b = 3;
  double x;
  double error = 7;
  int i = 0;
  while (error > tol) {
    i++;
    x = (a + b) / 2;
    error = (b - a) / 2;
    printf("iteracion: %d\n sol: %lf\n error: %lf\n", i, x, error);
    if ((f(a) * f(x)) < 0)
      b = x;
    else
      a = x;
  }
  printf("el numero de iteraciones es %d y la sol: %lf", i, x);
  system("PAUSE");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
mov    $0xfffffff5,%esi
call   1060 <pow@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  0xea5(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe90(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe7b(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1241 <main+0x101>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe54(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe39(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xe24(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
movsd  -0x18(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
imul   %ecx,%eax
cmp    $0x0,%eax
jge    1232 <main+0xf2>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    123c <main+0xfc>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1191 <main+0x51>
mov    -0x34(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
lea    0xded(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe0c(%rip),%rdi
call   1040 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    $0xa,%edi
mov    $0xfffffff5,%esi
call   1060 <pow@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0xe9b(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe95(%rip),%xmm1
xor    %ebx,%ebx
lea    0xe9c(%rip),%r14
jmp    1192 <main+0x52>
xchg   %ax,%ax
movsd  0x28(%rsp),%xmm2
ucomisd 0x18(%rsp),%xmm2
jbe    1217 <main+0xd7>
add    $0x1,%ebx
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  0xe65(%rip),%xmm0
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x20(%rsp)
subsd  %xmm3,%xmm1
mulsd  %xmm0,%xmm1
mov    %r14,%rdi
mov    %ebx,%esi
movapd %xmm2,%xmm0
movsd  %xmm1,0x28(%rsp)
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   1030 <f@plt>
mov    %eax,%ebp
movsd  0x10(%rsp),%xmm0
call   1030 <f@plt>
movsd  0x10(%rsp),%xmm0
imul   %ebp,%eax
movapd %xmm0,%xmm1
test   %eax,%eax
js     1180 <main+0x40>
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm1
jmp    1180 <main+0x40>
lea    0xe1f(%rip),%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe3c(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"iteracion: %d\0A sol: %lf\0A error: %lf\0A\00"
@.str.1 = [45 x i8] c"el numero de iteraciones es %d y la sol: %lf\00"
@.str.2 = [6 x i8] c"PAUSE\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store i32 0, i32* %1
%8 = call double @pow(i32 10, i32 -11)
store double %8, double* %2
store double 2.000000e+00, double* %3
store double 3.000000e+00, double* %4
store double 7.000000e+00, double* %6
store i32 0, i32* %7
br label %9
9: ; preds = %38, %0
%10 = load double, double* %6
%11 = load double, double* %2
%12 = fcmp ogt double %10, %11
br i1 %12, label %13, label %39
13: ; preds = %9
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 1
store i32 %15, i32* %7
%16 = load double, double* %3
%17 = load double, double* %4
%18 = fadd double %16, %17
%19 = fdiv double %18, 2.000000e+00
store double %19, double* %5
%20 = load double, double* %4
%21 = load double, double* %3
%22 = fsub double %20, %21
%23 = fdiv double %22, 2.000000e+00
store double %23, double* %6
%24 = load i32, i32* %7
%25 = load double, double* %5
%26 = load double, double* %6
%27 = call i32 (i8*, i32, double, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %24, double %25, double %26)
%28 = load double, double* %3
%29 = call i32 @f(double %28)
%30 = load double, double* %5
%31 = call i32 @f(double %30)
%32 = mul nsw i32 %29, %31
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %13
%35 = load double, double* %5
store double %35, double* %4
br label %38
36: ; preds = %13
%37 = load double, double* %5
store double %37, double* %3
br label %38
38: ; preds = %36, %34
br label %9
39: ; preds = %9
%40 = load i32, i32* %7
%41 = load double, double* %5
%42 = call i32 (i8*, i32, double, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %40, double %41)
%43 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [37 x i8] c"iteracion: %d\0A sol: %lf\0A error: %lf\0A\00"
@.str.1 = [45 x i8] c"el numero de iteraciones es %d y la sol: %lf\00"
@.str.2 = [6 x i8] c"PAUSE\00"
define i32 @main() {
%1 = tail call double @pow(i32 10, i32 -11)
%2 = fcmp olt double %1, 7.000000e+00
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ %7, %3 ], [ 0, %0 ]
%5 = phi double [ %18, %3 ], [ 3.000000e+00, %0 ]
%6 = phi double [ %17, %3 ], [ 2.000000e+00, %0 ]
%7 = add nuw nsw i32 %4, 1
%8 = fadd double %6, %5
%9 = fmul double %8, 5.000000e-01
%10 = fsub double %5, %6
%11 = fmul double %10, 5.000000e-01
%12 = tail call i32 (i8*, i32, double, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %7, double %9, double %11)
%13 = tail call i32 @f(double %6)
%14 = tail call i32 @f(double %9)
%15 = mul nsw i32 %14, %13
%16 = icmp slt i32 %15, 0
%17 = select i1 %16, double %6, double %9
%18 = select i1 %16, double %9, double %5
%19 = fcmp ogt double %11, %1
br i1 %19, label %3, label %20
20: ; preds = %3
%21 = tail call i32 (i8*, i32, double, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %7, double %9)
%22 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}