#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 calculaC(double, double);
int f(double);
double fabs(double);
double pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main() {
  double tol = pow(10, -7);
  double a = 2;
  double b = 3;
  double x;
  double s = 2.41679918;
  double error = 7;
  int i = 0;
  printf("METODO REGULA FALSI\n");
  system("PAUSE");
  while (error > tol) {
    i++;
    x = calculaC(a, b);
    error = fabs(x - s);
    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\n", i, x);
  system("PAUSE");
  system("cls");
  printf("METODO DE LA BISECCION\n");
  system("PAUSE");
  error = 8;
  a = 2;
  b = 3;
  i = 0;
  while (error > tol) {
    i++;
    x = (a + b) / 2;
    error = fabs(x - s);
    printf("iteracion: %d\n sol: %.10lf\n error: %.10lf\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    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
mov    $0xfffffff9,%esi
call   1060 <pow@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  0xe9d(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe88(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe73(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe5e(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe92(%rip),%rdi
call   1040 <system@plt>
movsd  -0x38(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1270 <main+0x120>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1070 <calculaC@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movaps 0xe2a(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xe38(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
movsd  -0x18(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
imul   %ecx,%eax
cmp    $0x0,%eax
jge    1261 <main+0x111>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    126b <main+0x11b>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11c8 <main+0x78>
mov    -0x3c(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
lea    0xe01(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xdc8(%rip),%rdi
call   1040 <system@plt>
lea    0xe15(%rip),%rdi
call   1040 <system@plt>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xda2(%rip),%rdi
call   1040 <system@plt>
movsd  0xd60(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xd4b(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xd36(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x3c(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1395 <main+0x245>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xd07(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movaps 0xd05(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xd82(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
movsd  -0x18(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,-0x44(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
imul   %ecx,%eax
cmp    $0x0,%eax
jge    1386 <main+0x236>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1390 <main+0x240>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    12e6 <main+0x196>
mov    -0x3c(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
lea    0xd51(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xca3(%rip),%rdi
call   1040 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    $0xa,%edi
mov    $0xfffffff9,%esi
call   1070 <pow@plt>
movsd  %xmm0,0x10(%rsp)
lea    0xf6f(%rip),%rdi
call   1030 <puts@plt>
lea    0xeae(%rip),%rdi
call   1050 <system@plt>
xor    %r15d,%r15d
movsd  0xe5e(%rip),%xmm0
ucomisd 0x10(%rsp),%xmm0
mov    $0x0,%ebp
jbe    1264 <main+0x104>
movsd  0xe4d(%rip),%xmm1
movsd  0xe4d(%rip),%xmm0
movsd  %xmm0,(%rsp)
xor    %ebp,%ebp
lea    0xe75(%rip),%r14
jmp    11ee <main+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movapd 0x20(%rsp),%xmm2
ucomisd 0x10(%rsp),%xmm2
jbe    1264 <main+0x104>
add    $0x1,%ebp
movsd  (%rsp),%xmm0
movsd  %xmm1,0x18(%rsp)
call   1080 <calculaC@plt>
movsd  %xmm0,0x8(%rsp)
movapd %xmm0,%xmm1
addsd  0xe05(%rip),%xmm1
andpd  0xe15(%rip),%xmm1
mov    %r14,%rdi
mov    %ebp,%esi
movapd %xmm1,0x20(%rsp)
mov    $0x2,%al
call   1060 <printf@plt>
movsd  (%rsp),%xmm0
call   1040 <f@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x8(%rsp),%xmm0
imul   %ebx,%eax
movaps %xmm0,%xmm1
test   %eax,%eax
js     11e0 <main+0x80>
movsd  0x18(%rsp),%xmm1
movsd  %xmm0,(%rsp)
jmp    11e0 <main+0x80>
movsd  %xmm0,0x8(%rsp)
lea    0xdfa(%rip),%rdi
mov    %ebp,%esi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xdbf(%rip),%rbx
mov    %rbx,%rdi
call   1050 <system@plt>
lea    0xe09(%rip),%rdi
call   1050 <system@plt>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xd69(%rip),%xmm1
ucomisd 0x10(%rsp),%xmm1
jbe    1386 <main+0x226>
movsd  0xd3d(%rip),%xmm1
movsd  0xd3d(%rip),%xmm0
movsd  %xmm0,(%rsp)
xor    %r15d,%r15d
lea    0xdbb(%rip),%rbp
jmp    1302 <main+0x1a2>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movapd 0x20(%rsp),%xmm2
ucomisd 0x10(%rsp),%xmm2
jbe    1386 <main+0x226>
add    $0x1,%r15d
movsd  %xmm1,0x18(%rsp)
movapd %xmm1,%xmm0
addsd  (%rsp),%xmm0
mulsd  0xd0b(%rip),%xmm0
movapd %xmm0,%xmm1
movsd  %xmm0,0x8(%rsp)
addsd  0xce9(%rip),%xmm1
andpd  0xcf9(%rip),%xmm1
mov    %rbp,%rdi
mov    %r15d,%esi
movapd %xmm1,0x20(%rsp)
mov    $0x2,%al
call   1060 <printf@plt>
movsd  (%rsp),%xmm0
call   1040 <f@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x8(%rsp),%xmm0
imul   %ebx,%eax
movapd %xmm0,%xmm1
test   %eax,%eax
js     12f0 <main+0x190>
movsd  0x18(%rsp),%xmm1
movsd  %xmm0,(%rsp)
jmp    12f0 <main+0x190>
lea    0xd3b(%rip),%rdi
mov    %r15d,%esi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xca2(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"METODO REGULA FALSI\0A\00"
@.str.1 = [6 x i8] c"PAUSE\00"
@.str.2 = [37 x i8] c"iteracion: %d\0A sol: %lf\0A error: %lf\0A\00"
@.str.3 = [46 x i8] c"el numero de iteraciones es %d y la sol: %lf\0A\00"
@.str.4 = [4 x i8] c"cls\00"
@.str.5 = [24 x i8] c"METODO DE LA BISECCION\0A\00"
@.str.6 = [43 x i8] c"iteracion: %d\0A sol: %.10lf\0A error: %.10lf\0A\00"
@.str.7 = [45 x i8] c"el numero de iteraciones es %d y la sol: %lf\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store i32 0, i32* %1
%9 = call double @pow(i32 10, i32 -7)
store double %9, double* %2
store double 2.000000e+00, double* %3
store double 3.000000e+00, double* %4
store double 0x4003559ACEF8CC04, double* %6
store double 7.000000e+00, double* %7
store i32 0, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %40, %0
%13 = load double, double* %7
%14 = load double, double* %2
%15 = fcmp ogt double %13, %14
br i1 %15, label %16, label %41
16: ; preds = %12
%17 = load i32, i32* %8
%18 = add nsw i32 %17, 1
store i32 %18, i32* %8
%19 = load double, double* %3
%20 = load double, double* %4
%21 = call double @calculaC(double %19, double %20)
store double %21, double* %5
%22 = load double, double* %5
%23 = load double, double* %6
%24 = fsub double %22, %23
%25 = call double @llvm.fabs.f64(double %24)
store double %25, double* %7
%26 = load i32, i32* %8
%27 = load double, double* %5
%28 = load double, double* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %26, double %27, double %28)
%30 = load double, double* %3
%31 = call i32 @f(double %30)
%32 = load double, double* %5
%33 = call i32 @f(double %32)
%34 = mul nsw i32 %31, %33
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %16
%37 = load double, double* %5
store double %37, double* %4
br label %40
38: ; preds = %16
%39 = load double, double* %5
store double %39, double* %3
br label %40
40: ; preds = %38, %36
br label %12
41: ; preds = %12
%42 = load i32, i32* %8
%43 = load double, double* %5
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %42, double %43)
%45 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%46 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store double 8.000000e+00, double* %7
store double 2.000000e+00, double* %3
store double 3.000000e+00, double* %4
store i32 0, i32* %8
br label %49
49: ; preds = %78, %41
%50 = load double, double* %7
%51 = load double, double* %2
%52 = fcmp ogt double %50, %51
br i1 %52, label %53, label %79
53: ; preds = %49
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
%56 = load double, double* %3
%57 = load double, double* %4
%58 = fadd double %56, %57
%59 = fdiv double %58, 2.000000e+00
store double %59, double* %5
%60 = load double, double* %5
%61 = load double, double* %6
%62 = fsub double %60, %61
%63 = call double @llvm.fabs.f64(double %62)
store double %63, double* %7
%64 = load i32, i32* %8
%65 = load double, double* %5
%66 = load double, double* %7
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %64, double %65, double %66)
%68 = load double, double* %3
%69 = call i32 @f(double %68)
%70 = load double, double* %5
%71 = call i32 @f(double %70)
%72 = mul nsw i32 %69, %71
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %53
%75 = load double, double* %5
store double %75, double* %4
br label %78
76: ; preds = %53
%77 = load double, double* %5
store double %77, double* %3
br label %78
78: ; preds = %76, %74
br label %49
79: ; preds = %49
%80 = load i32, i32* %8
%81 = load double, double* %5
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i32 %80, double %81)
%83 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%84 = load i32, i32* %1
ret i32 %84
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"PAUSE\00"
@.str.2 = [37 x i8] c"iteracion: %d\0A sol: %lf\0A error: %lf\0A\00"
@.str.3 = [46 x i8] c"el numero de iteraciones es %d y la sol: %lf\0A\00"
@.str.4 = [4 x i8] c"cls\00"
@.str.6 = [43 x i8] c"iteracion: %d\0A sol: %.10lf\0A error: %.10lf\0A\00"
@.str.7 = [45 x i8] c"el numero de iteraciones es %d y la sol: %lf\00"
@str = [20 x i8] c"METODO REGULA FALSI\00"
@str.8 = [23 x i8] c"METODO DE LA BISECCION\00"
define i32 @main() {
%1 = tail call double @pow(i32 10, i32 -7)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%4 = fcmp olt double %1, 7.000000e+00
br i1 %4, label %5, label %21
5: ; preds = %0, %5
%6 = phi i32 [ %9, %5 ], [ 0, %0 ]
%7 = phi double [ %19, %5 ], [ 2.000000e+00, %0 ]
%8 = phi double [ %18, %5 ], [ 3.000000e+00, %0 ]
%9 = add nuw nsw i32 %6, 1
%10 = tail call double @calculaC(double %7, double %8)
%11 = fadd double %10, 0xC003559ACEF8CC04
%12 = tail call double @llvm.fabs.f64(double %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %9, double %10, double %12)
%14 = tail call i32 @f(double %7)
%15 = tail call i32 @f(double %10)
%16 = mul nsw i32 %15, %14
%17 = icmp slt i32 %16, 0
%18 = select i1 %17, double %10, double %8
%19 = select i1 %17, double %7, double %10
%20 = fcmp ogt double %12, %1
br i1 %20, label %5, label %21
21: ; preds = %5, %0
%22 = phi double [ undef, %0 ], [ %10, %5 ]
%23 = phi i32 [ 0, %0 ], [ %9, %5 ]
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %23, double %22)
%25 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
%28 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%29 = fcmp olt double %1, 8.000000e+00
br i1 %29, label %30, label %47
30: ; preds = %21, %30
%31 = phi i32 [ %34, %30 ], [ 0, %21 ]
%32 = phi double [ %45, %30 ], [ 2.000000e+00, %21 ]
%33 = phi double [ %44, %30 ], [ 3.000000e+00, %21 ]
%34 = add nuw nsw i32 %31, 1
%35 = fadd double %33, %32
%36 = fmul double %35, 5.000000e-01
%37 = fadd double %36, 0xC003559ACEF8CC04
%38 = tail call double @llvm.fabs.f64(double %37)
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %34, double %36, double %38)
%40 = tail call i32 @f(double %32)
%41 = tail call i32 @f(double %36)
%42 = mul nsw i32 %41, %40
%43 = icmp slt i32 %42, 0
%44 = select i1 %43, double %36, double %33
%45 = select i1 %43, double %32, double %36
%46 = fcmp ogt double %38, %1
br i1 %46, label %30, label %47
47: ; preds = %30, %21
%48 = phi double [ %22, %21 ], [ %36, %30 ]
%49 = phi i32 [ 0, %21 ], [ %34, %30 ]
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i32 %49, double %48)
%51 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}