#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 */
scalar_t__ f(double);
double fp(double);
double fpp(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main() {
  double a = 0;
  double b = 4;
  double p;
  double c;
  double d;
  double x[4];
  int i;
  double h;
  printf("METODO 1\n\n");
  for (i = 0; i < 20; i++) {
    h = (b - a) / 3;
    c = a + h;
    d = 2 * h + a;
    if (f(c) < f(d))
      a = c;
    else
      b = d;
  }
  p = (a + b) / 2;
  printf("x: %lf y: %lf\n", p, f(p));
  printf("METODO 2\n\n");
  x[0] = 2;
  for (i = 1; i < 4; i++) {
    x[i] = x[i - 1] - (fp(x[i - 1]) / fpp(x[i - 1]));
    p = x[i];
  }
  printf("estimacion: x= %lf y= %lf\n", p, f(p));
  system("PAUSE");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe8e(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x14,-0x54(%rbp)
jge    122b <main+0xdb>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xe68(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <f@plt>
mov    %rax,-0x68(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <f@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
cmp    %rcx,%rax
jge    120e <main+0xbe>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1218 <main+0xc8>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    121d <main+0xcd>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    118c <main+0x3c>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xdcb(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <f@plt>
movsd  -0x70(%rbp),%xmm0
mov    %rax,%rsi
lea    0xdba(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movsd  0xd82(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x1,-0x54(%rbp)
cmpl   $0x4,-0x54(%rbp)
jge    1316 <main+0x1c6>
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0x50(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0x50(%rbp,%rax,8),%xmm0
call   1030 <fp@plt>
movsd  %xmm0,-0x80(%rbp)
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0x50(%rbp,%rax,8),%xmm0
call   1070 <fpp@plt>
movsd  -0x80(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x78(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movslq -0x54(%rbp),%rax
movsd  %xmm0,-0x50(%rbp,%rax,8)
movslq -0x54(%rbp),%rax
movsd  -0x50(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1292 <main+0x142>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x20(%rbp),%xmm0
call   1040 <f@plt>
movsd  -0x88(%rbp),%xmm0
ff
mov    %rax,%rsi
lea    0xcfe(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xd0b(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
lea    0xee3(%rip),%rdi
call   1040 <puts@plt>
movsd  0xe86(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
xorpd  %xmm1,%xmm1
mov    $0x14,%ebp
movapd %xmm1,%xmm3
jmp    1199 <main+0x39>
nop
movapd %xmm3,%xmm1
add    $0xffffffff,%ebp
je     1201 <main+0xa1>
movsd  0x18(%rsp),%xmm0
subsd  %xmm1,%xmm0
divsd  0xe5d(%rip),%xmm0
addsd  %xmm0,%xmm3
movsd  %xmm3,0x8(%rsp)
addsd  %xmm0,%xmm0
movsd  %xmm1,0x20(%rsp)
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <f@plt>
mov    %rax,%rbx
movsd  0x10(%rsp),%xmm0
call   1050 <f@plt>
movsd  0x8(%rsp),%xmm3
cmp    %rax,%rbx
jl     1190 <main+0x30>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x20(%rsp),%xmm3
jmp    1190 <main+0x30>
movsd  0x18(%rsp),%xmm0
addsd  %xmm3,%xmm0
mulsd  0xdfd(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
call   1050 <f@plt>
lea    0xdfb(%rip),%rdi
movsd  0x18(%rsp),%xmm0
mov    %rax,%rsi
mov    $0x1,%al
call   1070 <printf@plt>
lea    0xe1e(%rip),%rdi
call   1040 <puts@plt>
movsd  0xdcf(%rip),%xmm0
call   1030 <fp@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xdbc(%rip),%xmm0
call   1080 <fpp@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xda5(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <fp@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1080 <fpp@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <fp@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1080 <fpp@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <f@plt>
lea    0xd46(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    %rax,%rsi
mov    $0x1,%al
call   1070 <printf@plt>
lea    0xd4a(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"METODO 1\0A\0A\00"
@.str.1 = [15 x i8] c"x: %lf y: %lf\0A\00"
@.str.2 = [11 x i8] c"METODO 2\0A\0A\00"
@.str.3 = [27 x i8] c"estimacion: x= %lf y= %lf\0A\00"
@.str.4 = [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 [4 x double]
%8 = alloca i32
%9 = alloca double
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 4.000000e+00, double* %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %11
11: ; preds = %35, %0
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 20
br i1 %13, label %14, label %38
14: ; preds = %11
%15 = load double, double* %3
%16 = load double, double* %2
%17 = fsub double %15, %16
%18 = fdiv double %17, 3.000000e+00
store double %18, double* %9
%19 = load double, double* %2
%20 = load double, double* %9
%21 = fadd double %19, %20
store double %21, double* %5
%22 = load double, double* %9
%23 = load double, double* %2
%24 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %22, double %23)
store double %24, double* %6
%25 = load double, double* %5
%26 = call i64 @f(double %25)
%27 = load double, double* %6
%28 = call i64 @f(double %27)
%29 = icmp slt i64 %26, %28
br i1 %29, label %30, label %32
30: ; preds = %14
%31 = load double, double* %5
store double %31, double* %2
br label %34
32: ; preds = %14
%33 = load double, double* %6
store double %33, double* %3
br label %34
34: ; preds = %32, %30
br label %35
35: ; preds = %34
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %11
38: ; preds = %11
%39 = load double, double* %2
%40 = load double, double* %3
%41 = fadd double %39, %40
%42 = fdiv double %41, 2.000000e+00
store double %42, double* %4
%43 = load double, double* %4
%44 = load double, double* %4
%45 = call i64 @f(double %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %43, i64 %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%48 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 0
store double 2.000000e+00, double* %48
store i32 1, i32* %8
br label %49
49: ; preds = %79, %38
%50 = load i32, i32* %8
%51 = icmp slt i32 %50, 4
br i1 %51, label %52, label %82
52: ; preds = %49
%53 = load i32, i32* %8
%54 = sub nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 %55
%57 = load double, double* %56
%58 = load i32, i32* %8
%59 = sub nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 %60
%62 = load double, double* %61
%63 = call double @fp(double %62)
%64 = load i32, i32* %8
%65 = sub nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 %66
%68 = load double, double* %67
%69 = call double @fpp(double %68)
%70 = fdiv double %63, %69
%71 = fsub double %57, %70
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 %73
store double %71, double* %74
%75 = load i32, i32* %8
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 %76
%78 = load double, double* %77
store double %78, double* %4
br label %79
79: ; preds = %52
%80 = load i32, i32* %8
%81 = add nsw i32 %80, 1
store i32 %81, i32* %8
br label %49
82: ; preds = %49
%83 = load double, double* %4
%84 = load double, double* %4
%85 = call i64 @f(double %84)
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %83, i64 %85)
%87 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"x: %lf y: %lf\0A\00"
@.str.3 = [27 x i8] c"estimacion: x= %lf y= %lf\0A\00"
@.str.4 = [6 x i8] c"PAUSE\00"
@str = [10 x i8] c"METODO 1\0A\00"
@str.5 = [10 x i8] c"METODO 2\0A\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi double [ 0.000000e+00, %0 ], [ %14, %2 ]
%4 = phi i32 [ 0, %0 ], [ %15, %2 ]
%5 = phi double [ 4.000000e+00, %0 ], [ %13, %2 ]
%6 = fsub double %5, %3
%7 = fdiv double %6, 3.000000e+00
%8 = fadd double %3, %7
%9 = tail call double @llvm.fmuladd.f64(double %7, double 2.000000e+00, double %3)
%10 = tail call i64 @f(double %8)
%11 = tail call i64 @f(double %9)
%12 = icmp slt i64 %10, %11
%13 = select i1 %12, double %5, double %9
%14 = select i1 %12, double %8, double %3
%15 = add nuw nsw i32 %4, 1
%16 = icmp eq i32 %15, 20
br i1 %16, label %17, label %2
17: ; preds = %2
%18 = fadd double %13, %14
%19 = fmul double %18, 5.000000e-01
%20 = tail call i64 @f(double %19)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %19, i64 %20)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0))
%23 = tail call double @fp(double 2.000000e+00)
%24 = tail call double @fpp(double 2.000000e+00)
%25 = fdiv double %23, %24
%26 = fsub double 2.000000e+00, %25
%27 = tail call double @fp(double %26)
%28 = tail call double @fpp(double %26)
%29 = fdiv double %27, %28
%30 = fsub double %26, %29
%31 = tail call double @fp(double %30)
%32 = tail call double @fpp(double %30)
%33 = fdiv double %31, %32
%34 = fsub double %30, %33
%35 = tail call i64 @f(double %34)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %34, i64 %35)
%37 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}