#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(int *);
int *make_array(int);
int /*<<< orphan*/ printf(char *, unsigned long long);
unsigned long long rdtsc();
int main() {
  int *arr;
  int i;
  int sum = 0;
  unsigned long long start = 0;
  unsigned long long end = 0;
  int size = 1024 * 1024 * 16 / 4;
  arr = make_array(size);
  FILE *fp = fopen("garbage.txt", "a");
  unsigned long long coldstart = rdtsc();
  start = rdtsc();
  for (i = 0; i < size; i += 10) {
    arr[i] = 123;
    arr[i + 1] = 123;
    arr[i + 2] = 123;
    arr[i + 3] = 123;
    arr[i + 4] = 123;
    arr[i + 5] = 123;
    arr[i + 6] = 123;
    arr[i + 7] = 123;
    arr[i + 8] = 123;
    arr[i + 9] = 123;
  }
  end = rdtsc();
  if ((end - start) < 10000000000000000) {
    printf("%llu\n", (end - start));
  }
  fclose(fp);
  free(arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x400000,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1080 <make_array@plt>
mov    %rax,-0x10(%rbp)
lea    0xe60(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1060 <rdtsc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1060 <rdtsc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12aa <main+0x14a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x6,%ecx
movslq %ecx,%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x7,%ecx
movslq %ecx,%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x8,%ecx
movslq %ecx,%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x9,%ecx
movslq %ecx,%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x14(%rbp)
jmp    11cd <main+0x6d>
mov    $0x0,%al
call   1060 <rdtsc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
movabs $0x2386f26fc10000,%rcx
cmp    %rcx,%rax
jae    12e4 <main+0x184>
mov    -0x28(%rbp),%rsi
sub    -0x20(%rbp),%rsi
lea    0xd2f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x400000,%edi
call   1080 <make_array@plt>
mov    %rax,%r12
lea    0xe94(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <rdtsc@plt>
xor    %eax,%eax
call   1060 <rdtsc@plt>
mov    %rax,%r15
movaps 0xe5b(%rip),%xmm0
movabs $0x7b0000007b,%rax
nop
movups %xmm0,(%r12,%rbx,4)
movups %xmm0,0x10(%r12,%rbx,4)
mov    %rax,0x20(%r12,%rbx,4)
cmp    $0x3ffff5,%rbx
ja     11e0 <main+0x80>
movups %xmm0,0x28(%r12,%rbx,4)
movups %xmm0,0x38(%r12,%rbx,4)
mov    %rax,0x48(%r12,%rbx,4)
add    $0x14,%rbx
jmp    11b0 <main+0x50>
xor    %eax,%eax
call   1060 <rdtsc@plt>
sub    %r15,%rax
movabs $0x2386f26fc0ffff,%rcx
cmp    %rcx,%rax
ja     1208 <main+0xa8>
lea    0xe1e(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"garbage.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %4
store i64 0, i64* %5
store i64 0, i64* %6
store i32 4194304, i32* %7
%10 = load i32, i32* %7
%11 = call i32* @make_array(i32 %10)
store i32* %11, i32** %2
%12 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %8
%13 = call i64 (...) @rdtsc()
store i64 %13, i64* %9
%14 = call i64 (...) @rdtsc()
store i64 %14, i64* %5
store i32 0, i32* %3
br label %15
15: ; preds = %69, %0
%16 = load i32, i32* %3
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %72
19: ; preds = %15
%20 = load i32*, i32** %2
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 123, i32* %23
%24 = load i32*, i32** %2
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %24, i64 %27
store i32 123, i32* %28
%29 = load i32*, i32** %2
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %29, i64 %32
store i32 123, i32* %33
%34 = load i32*, i32** %2
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %34, i64 %37
store i32 123, i32* %38
%39 = load i32*, i32** %2
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %39, i64 %42
store i32 123, i32* %43
%44 = load i32*, i32** %2
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %44, i64 %47
store i32 123, i32* %48
%49 = load i32*, i32** %2
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %49, i64 %52
store i32 123, i32* %53
%54 = load i32*, i32** %2
%55 = load i32, i32* %3
%56 = add nsw i32 %55, 7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %54, i64 %57
store i32 123, i32* %58
%59 = load i32*, i32** %2
%60 = load i32, i32* %3
%61 = add nsw i32 %60, 8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %59, i64 %62
store i32 123, i32* %63
%64 = load i32*, i32** %2
%65 = load i32, i32* %3
%66 = add nsw i32 %65, 9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %64, i64 %67
store i32 123, i32* %68
br label %69
69: ; preds = %19
%70 = load i32, i32* %3
%71 = add nsw i32 %70, 10
store i32 %71, i32* %3
br label %15
72: ; preds = %15
%73 = call i64 (...) @rdtsc()
store i64 %73, i64* %6
%74 = load i64, i64* %6
%75 = load i64, i64* %5
%76 = sub i64 %74, %75
%77 = icmp ult i64 %76, 10000000000000000
br i1 %77, label %78, label %83
78: ; preds = %72
%79 = load i64, i64* %6
%80 = load i64, i64* %5
%81 = sub i64 %79, %80
%82 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %81)
br label %83
83: ; preds = %78, %72
%84 = load i32*, i32** %8
%85 = call i32 @fclose(i32* %84)
%86 = load i32*, i32** %2
%87 = call i32 @free(i32* %86)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"garbage.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = tail call i32* @make_array(i32 4194304)
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i64 (...) @rdtsc()
%4 = tail call i64 (...) @rdtsc()
br label %5
5: ; preds = %17, %0
%6 = phi i64 [ 0, %0 ], [ %28, %17 ]
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> <i32 123, i32 123, i32 123, i32 123>, <4 x i32>* %8
%9 = add nuw nsw i64 %6, 4
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 123, i32 123, i32 123, i32 123>, <4 x i32>* %11
%12 = add nuw nsw i64 %6, 8
%13 = getelementptr inbounds i32, i32* %1, i64 %12
store i32 123, i32* %13
%14 = add nuw nsw i64 %6, 9
%15 = getelementptr inbounds i32, i32* %1, i64 %14
store i32 123, i32* %15
%16 = icmp ult i64 %6, 4194294
br i1 %16, label %17, label %29
17: ; preds = %5
%18 = add nuw nsw i64 %6, 10
%19 = getelementptr inbounds i32, i32* %1, i64 %18
%20 = bitcast i32* %19 to <4 x i32>*
store <4 x i32> <i32 123, i32 123, i32 123, i32 123>, <4 x i32>* %20
%21 = add nuw nsw i64 %6, 14
%22 = getelementptr inbounds i32, i32* %1, i64 %21
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> <i32 123, i32 123, i32 123, i32 123>, <4 x i32>* %23
%24 = add nuw nsw i64 %6, 18
%25 = getelementptr inbounds i32, i32* %1, i64 %24
store i32 123, i32* %25
%26 = add nuw nsw i64 %6, 19
%27 = getelementptr inbounds i32, i32* %1, i64 %26
store i32 123, i32* %27
%28 = add nuw nsw i64 %6, 20
br label %5
29: ; preds = %5
%30 = tail call i64 (...) @rdtsc()
%31 = sub i64 %30, %4
%32 = icmp ult i64 %31, 10000000000000000
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %31)
br label %35
35: ; preds = %33, %29
%36 = tail call i32 @fclose(i32* %2)
%37 = tail call i32 @free(i32* %1)
ret i32 0
}