#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 /*<<< orphan*/ system(char *);
int main() {
  double tol = pow(10, -11);
  double a = 6;
  double b = 7;
  double x, y;
  double error = 7;
  int i = 0;
  while (error > tol) {
    i++;
    x = (a + b) / 2;
    error = (b - a) / 2;
    y = 20 - x;
    printf("iteracion: %d\n x: %lf\ny: %lf\n", i, x, y);
    if ((f(a) * f(x)) < 0)
      b = x;
    else
      a = x;
  }
  printf("\n\nsoluciones:");
  printf("\n\nx: %lf; y: %lf\n", x, y);
  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  0xe9d(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe88(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe7b(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1253 <main+0x113>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe41(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe28(%rip),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x3c(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xe1a(%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    1244 <main+0x104>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    124e <main+0x10e>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1191 <main+0x51>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xdda(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
lea    0xdde(%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  0xea1(%rip),%xmm2
movsd  %xmm0,0x20(%rsp)
ucomisd %xmm0,%xmm2
jbe    123e <main+0xfe>
movsd  0xe91(%rip),%xmm0
mov    $0x1,%ebx
movsd  0xe8c(%rip),%xmm3
lea    0xe95(%rip),%r14
movsd  %xmm0,0x8(%rsp)
jmp    11c7 <main+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
subsd  0x10(%rsp),%xmm2
movsd  0xe62(%rip),%xmm3
mulsd  %xmm3,%xmm2
add    $0x1,%ebx
ucomisd 0x20(%rsp),%xmm2
movapd %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
jbe    123e <main+0xfe>
movsd  %xmm0,0x10(%rsp)
movsd  %xmm2,0x28(%rsp)
addsd  %xmm2,%xmm0
mulsd  %xmm3,%xmm0
movsd  %xmm0,(%rsp)
movsd  0xe30(%rip),%xmm1
subsd  %xmm0,%xmm1
mov    %r14,%rdi
mov    %ebx,%esi
movsd  %xmm1,0x18(%rsp)
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0x10(%rsp),%xmm0
call   1030 <f@plt>
mov    %eax,%ebp
movsd  (%rsp),%xmm0
call   1030 <f@plt>
movsd  0x28(%rsp),%xmm2
movsd  (%rsp),%xmm1
imul   %ebp,%eax
movapd %xmm1,%xmm0
test   %eax,%eax
js     11a0 <main+0x60>
movsd  %xmm1,0x8(%rsp)
movapd %xmm2,%xmm0
jmp    11a0 <main+0x60>
movsd  %xmm1,(%rsp)
lea    0xdf4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdf4(%rip),%rdi
movsd  (%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mov    $0x2,%al
call   1050 <printf@plt>
lea    0xded(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"iteracion: %d\0A x: %lf\0Ay: %lf\0A\00"
@.str.1 = [14 x i8] c"\0A\0Asoluciones:\00"
@.str.2 = [18 x i8] c"\0A\0Ax: %lf; y: %lf\0A\00"
@.str.3 = [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 double
%8 = alloca i32
store i32 0, i32* %1
%9 = call double @pow(i32 10, i32 -11)
store double %9, double* %2
store double 6.000000e+00, double* %3
store double 7.000000e+00, double* %4
store double 7.000000e+00, double* %7
store i32 0, i32* %8
br label %10
10: ; preds = %41, %0
%11 = load double, double* %7
%12 = load double, double* %2
%13 = fcmp ogt double %11, %12
br i1 %13, label %14, label %42
14: ; preds = %10
%15 = load i32, i32* %8
%16 = add nsw i32 %15, 1
store i32 %16, i32* %8
%17 = load double, double* %3
%18 = load double, double* %4
%19 = fadd double %17, %18
%20 = fdiv double %19, 2.000000e+00
store double %20, double* %5
%21 = load double, double* %4
%22 = load double, double* %3
%23 = fsub double %21, %22
%24 = fdiv double %23, 2.000000e+00
store double %24, double* %7
%25 = load double, double* %5
%26 = fsub double 2.000000e+01, %25
store double %26, double* %6
%27 = load i32, i32* %8
%28 = load double, double* %5
%29 = load double, double* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %27, double %28, double %29)
%31 = load double, double* %3
%32 = call i32 @f(double %31)
%33 = load double, double* %5
%34 = call i32 @f(double %33)
%35 = mul nsw i32 %32, %34
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %14
%38 = load double, double* %5
store double %38, double* %4
br label %41
39: ; preds = %14
%40 = load double, double* %5
store double %40, double* %3
br label %41
41: ; preds = %39, %37
br label %10
42: ; preds = %10
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%44 = load double, double* %5
%45 = load double, double* %6
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), double %44, double %45)
%47 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [30 x i8] c"iteracion: %d\0A x: %lf\0Ay: %lf\0A\00"
@.str.1 = [14 x i8] c"\0A\0Asoluciones:\00"
@.str.2 = [18 x i8] c"\0A\0Ax: %lf; y: %lf\0A\00"
@.str.3 = [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 i1 %2, label %3, label %21
3: ; preds = %0, %3
%4 = phi i32 [ %7, %3 ], [ 0, %0 ]
%5 = phi double [ %19, %3 ], [ 7.000000e+00, %0 ]
%6 = phi double [ %18, %3 ], [ 6.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 = fsub double 2.000000e+01, %9
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %7, double %9, double %12)
%14 = tail call i32 @f(double %6)
%15 = tail call i32 @f(double %9)
%16 = mul nsw i32 %15, %14
%17 = icmp slt i32 %16, 0
%18 = select i1 %17, double %6, double %9
%19 = select i1 %17, double %9, double %5
%20 = fcmp ogt double %11, %1
br i1 %20, label %3, label %21
21: ; preds = %3, %0
%22 = phi double [ undef, %0 ], [ %9, %3 ]
%23 = phi double [ undef, %0 ], [ %12, %3 ]
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), double %22, double %23)
%26 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}