#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 */
typedef double clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
double clock();
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(long);
int /*<<< orphan*/ printf(char *, double, int, ...);
main() {
  double *V;
  long int N, i;
  N = 2 * 3000000000;
  int j, iter = 40;
  clock_t start = clock();
  V = (double *)malloc(N * sizeof(double));
  clock_t end = clock();
  double seconds = (end - start) / CLOCKS_PER_SEC;
  double size_gb = N / 1024 / 1024 / 1024 * 8;
  printf("Tiempo: %f seg de alojar %.3f GB\n", seconds / 60, size_gb);
  start = clock();
  for (j = 0; j < iter; j++)
    for (i = 0; i < N; i++)
      V[i] = 0;
  end = clock();
  seconds = (end - start) / CLOCKS_PER_SEC;
  printf("Tiempo: %f seg en recorrer %d veces %.3f GB", seconds / 60, iter,
         size_gb);
  free(V);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x165a0bc00,%rax
mov    %rax,-0x18(%rbp)
movl   $0x28,-0x28(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    0x2e4a(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    $0x400,%ecx
cqto
idiv   %rcx
shl    $0x3,%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xe1c(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si -0x48(%rbp),%esi
lea    0xe14(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1264 <main+0x124>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1251 <main+0x111>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1222 <main+0xe2>
jmp    1256 <main+0x116>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    120e <main+0xce>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    0x2d67(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xd69(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%esi
movsd  -0x48(%rbp),%xmm1
lea    0xd80(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x8(%rsp)
movabs $0xb2d05e000,%r14
mov    %r14,%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <clock@plt>
subsd  0x8(%rsp),%xmm0
mov    0x2e59(%rip),%r15
divsd  (%r15),%xmm0
divsd  0xe64(%rip),%xmm0
lea    0xe6d(%rip),%rdi
mov    $0x28,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1060 <memset@plt>
xor    %eax,%eax
call   1040 <clock@plt>
subsd  0x8(%rsp),%xmm0
divsd  (%r15),%xmm0
divsd  0xe1d(%rip),%xmm0
lea    0xe48(%rip),%rdi
movsd  0xe16(%rip),%xmm1
mov    $0x28,%esi
mov    $0x2,%al
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [34 x i8] c"Tiempo: %f seg de alojar %.3f GB\0A\00"
@.str.1 = [44 x i8] c"Tiempo: %f seg en recorrer %d veces %.3f GB\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 0, i32* %1
store i64 6000000000, i64* %3
store i32 40, i32* %6
%11 = call double (...) @clock()
store double %11, double* %7
%12 = load i64, i64* %3
%13 = mul i64 %12, 8
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to double*
store double* %15, double** %2
%16 = call double (...) @clock()
store double %16, double* %8
%17 = load double, double* %8
%18 = load double, double* %7
%19 = fsub double %17, %18
%20 = load double, double* @CLOCKS_PER_SEC
%21 = fdiv double %19, %20
store double %21, double* %9
%22 = load i64, i64* %3
%23 = sdiv i64 %22, 1024
%24 = sdiv i64 %23, 1024
%25 = sdiv i64 %24, 1024
%26 = mul nsw i64 %25, 8
%27 = sitofp i64 %26 to double
store double %27, double* %10
%28 = load double, double* %9
%29 = fdiv double %28, 6.000000e+01
%30 = load double, double* %10
%31 = fptosi double %30 to i32
%32 = call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), double %29, i32 %31)
%33 = call double (...) @clock()
store double %33, double* %7
store i32 0, i32* %5
br label %34
34: ; preds = %51, %0
%35 = load i32, i32* %5
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %54
38: ; preds = %34
store i64 0, i64* %4
br label %39
39: ; preds = %47, %38
%40 = load i64, i64* %4
%41 = load i64, i64* %3
%42 = icmp slt i64 %40, %41
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load double*, double** %2
%45 = load i64, i64* %4
%46 = getelementptr inbounds double, double* %44, i64 %45
store double 0.000000e+00, double* %46
br label %47
47: ; preds = %43
%48 = load i64, i64* %4
%49 = add nsw i64 %48, 1
store i64 %49, i64* %4
br label %39
50: ; preds = %39
br label %51
51: ; preds = %50
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %34
54: ; preds = %34
%55 = call double (...) @clock()
store double %55, double* %8
%56 = load double, double* %8
%57 = load double, double* %7
%58 = fsub double %56, %57
%59 = load double, double* @CLOCKS_PER_SEC
%60 = fdiv double %58, %59
store double %60, double* %9
%61 = load double, double* %9
%62 = fdiv double %61, 6.000000e+01
%63 = load i32, i32* %6
%64 = load double, double* %10
%65 = call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), double %62, i32 %63, double %64)
%66 = load double*, double** %2
%67 = call i32 @free(double* %66)
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [34 x i8] c"Tiempo: %f seg de alojar %.3f GB\0A\00"
@.str.1 = [44 x i8] c"Tiempo: %f seg en recorrer %d veces %.3f GB\00"
define i32 @main() {
%1 = tail call double (...) @clock()
%2 = tail call i64 @malloc(i64 48000000000)
%3 = inttoptr i64 %2 to double*
%4 = inttoptr i64 %2 to i8*
%5 = tail call double (...) @clock()
%6 = fsub double %5, %1
%7 = load double, double* @CLOCKS_PER_SEC
%8 = fdiv double %6, %7
%9 = fdiv double %8, 6.000000e+01
%10 = tail call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), double %9, i32 40)
%11 = tail call double (...) @clock()
%12 = tail call double (...) @clock()
%13 = fsub double %12, %11
%14 = load double, double* @CLOCKS_PER_SEC
%15 = fdiv double %13, %14
%16 = fdiv double %15, 6.000000e+01
%17 = tail call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), double %16, i32 40, double 4.000000e+01)
%18 = tail call i32 @free(double* %3)
ret i32 0
}