#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 /*<<< orphan*/ cacheflush();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ init(int *, int);
scalar_t__ loop(int *, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int c = 0;
  int k;
  int *a = malloc(sizeof(int) * 4096 * 32);
  int *d = malloc(sizeof(int) * 4096 * 10);
  int *b = malloc(sizeof(int) * 4096 * 32);
  init(a, 4096 * 32);
  init(b, 4096 * 32);
  cacheflush();
  printf("a: %p -> %p\n", &a[0], &a[4096 * 32]);
  printf("b: %p -> %p\n", &b[0], &b[4096 * 32]);
  fprintf(stderr, "ITERATION = 1\n");
  c += loop(a, 4096 * 32);
  fprintf(stderr, "ITERATION = 2\n");
  c += loop(a, 4096 * 32);
  fprintf(stderr, "ITERATION = 3\n");
  c += loop(a, 4096 * 32);
  fprintf(stderr, "ITERATION = 4\n");
  c += loop(b, 4096 * 32);
  printf("%d\n", c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x80000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x28000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x80000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x20000,%esi
call   1070 <init@plt>
mov    -0x30(%rbp),%rdi
mov    $0x20000,%esi
call   1070 <init@plt>
mov    $0x0,%al
call   1050 <cacheflush@plt>
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rdx
add    $0x80000,%rdx
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x30(%rbp),%rdx
add    $0x80000,%rdx
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x20000,%esi
call   1030 <loop@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x20000,%esi
call   1030 <loop@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x20000,%esi
call   1030 <loop@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    $0x20000,%esi
call   1030 <loop@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x80000,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    $0x28000,%edi
call   1080 <malloc@plt>
mov    $0x80000,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    $0x20000,%esi
call   1070 <init@plt>
mov    %r14,%rdi
mov    $0x20000,%esi
call   1070 <init@plt>
xor    %eax,%eax
call   1050 <cacheflush@plt>
lea    0x80000(%r15),%rdx
lea    0xe45(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x80000(%r14),%rdx
lea    0xe3a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dfc(%rip),%r12
mov    (%r12),%edi
lea    0xe2b(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r15,%rdi
mov    $0x20000,%esi
call   1030 <loop@plt>
mov    %rax,%rbx
mov    (%r12),%edi
lea    0xe1a(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r15,%rdi
mov    $0x20000,%esi
call   1030 <loop@plt>
add    %eax,%ebx
mov    (%r12),%edi
lea    0xe0a(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r15,%rdi
mov    $0x20000,%esi
call   1030 <loop@plt>
add    %eax,%ebx
mov    (%r12),%edi
lea    0xdfa(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r14,%rdi
mov    $0x20000,%esi
call   1030 <loop@plt>
add    %eax,%ebx
lea    0xdee(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"a: %p -> %p\0A\00"
@.str.1 = [13 x i8] c"b: %p -> %p\0A\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"ITERATION = 1\0A\00"
@.str.3 = [15 x i8] c"ITERATION = 2\0A\00"
@.str.4 = [15 x i8] c"ITERATION = 3\0A\00"
@.str.5 = [15 x i8] c"ITERATION = 4\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = call i32* @malloc(i32 524288)
store i32* %11, i32** %8
%12 = call i32* @malloc(i32 163840)
store i32* %12, i32** %9
%13 = call i32* @malloc(i32 524288)
store i32* %13, i32** %10
%14 = load i32*, i32** %8
%15 = call i32 @init(i32* %14, i32 131072)
%16 = load i32*, i32** %10
%17 = call i32 @init(i32* %16, i32 131072)
%18 = call i32 (...) @cacheflush()
%19 = load i32*, i32** %8
%20 = getelementptr inbounds i32, i32* %19, i64 0
%21 = load i32*, i32** %8
%22 = getelementptr inbounds i32, i32* %21, i64 131072
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %20, i32* %22)
%24 = load i32*, i32** %10
%25 = getelementptr inbounds i32, i32* %24, i64 0
%26 = load i32*, i32** %10
%27 = getelementptr inbounds i32, i32* %26, i64 131072
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %25, i32* %27)
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32*, i32** %8
%32 = call i64 @loop(i32* %31, i32 131072)
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = add nsw i64 %34, %32
%36 = trunc i64 %35 to i32
store i32 %36, i32* %6
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32*, i32** %8
%40 = call i64 @loop(i32* %39, i32 131072)
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = add nsw i64 %42, %40
%44 = trunc i64 %43 to i32
store i32 %44, i32* %6
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%47 = load i32*, i32** %8
%48 = call i64 @loop(i32* %47, i32 131072)
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = add nsw i64 %50, %48
%52 = trunc i64 %51 to i32
store i32 %52, i32* %6
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%55 = load i32*, i32** %10
%56 = call i64 @loop(i32* %55, i32 131072)
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = add nsw i64 %58, %56
%60 = trunc i64 %59 to i32
store i32 %60, i32* %6
%61 = load i32, i32* %6
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %61)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"a: %p -> %p\0A\00"
@.str.1 = [13 x i8] c"b: %p -> %p\0A\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"ITERATION = 1\0A\00"
@.str.3 = [15 x i8] c"ITERATION = 2\0A\00"
@.str.4 = [15 x i8] c"ITERATION = 3\0A\00"
@.str.5 = [15 x i8] c"ITERATION = 4\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @malloc(i32 524288)
%4 = tail call i32* @malloc(i32 163840)
%5 = tail call i32* @malloc(i32 524288)
%6 = tail call i32 @init(i32* %3, i32 131072)
%7 = tail call i32 @init(i32* %5, i32 131072)
%8 = tail call i32 (...) @cacheflush()
%9 = getelementptr inbounds i32, i32* %3, i64 131072
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %9)
%11 = getelementptr inbounds i32, i32* %5, i64 131072
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %5, i32* %11)
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i64 @loop(i32* %3, i32 131072)
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i64 @loop(i32* %3, i32 131072)
%19 = add i64 %18, %15
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%22 = tail call i64 @loop(i32* %3, i32 131072)
%23 = add i64 %19, %22
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%26 = tail call i64 @loop(i32* %5, i32 131072)
%27 = add i64 %23, %26
%28 = trunc i64 %27 to i32
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %28)
ret i32 0
}