#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__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  int MEM_SIZE = 10 * 1024 * 1024;
  int DURATION = 60 * 1000 * 1000;
  int DELAY_OPS = 1;
  int count = 0;
  int *mem = (int *)malloc(sizeof(int) * MEM_SIZE);
  int elapsed = 0;
  int tmp = 0;
  while (elapsed < DURATION) {
    int read_addr = count % MEM_SIZE;
    tmp += mem[read_addr];
    elapsed += DELAY_OPS;
    count += 16;
  }
  printf("Sum is %d\n", tmp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xa00000,-0x14(%rbp)
movl   $0x3938700,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11b1 <main+0x91>
mov    -0x20(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x34(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x20(%rbp)
jmp    1173 <main+0x53>
mov    -0x30(%rbp),%esi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x2800000,%edi
call   1040 <malloc@plt>
mov    %rax,%r8
lea    0x80(%rax),%r10
mov    %rax,%r11
add    $0x40,%r11
xor    %r9d,%r9d
mov    $0x20,%edi
mov    $0x10,%ecx
mov    $0x3938700,%r15d
movabs $0xcccccccccccccccd,%r14
cc cc cc
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rdi,%rax
mul    %r14
and    $0xffffffffff800000,%rdx
lea    (%rdx,%rdx,4),%rbx
neg    %rbx
mov    %rcx,%rax
mul    %r14
and    $0xffffffffff800000,%rdx
lea    (%rdx,%rdx,4),%rbp
neg    %rbp
mov    %r9,%rax
mul    %r14
and    $0xffffffffff800000,%rdx
lea    (%rdx,%rdx,4),%rax
neg    %rax
add    (%r8,%rax,1),%esi
add    (%r11,%rbp,1),%esi
add    (%r10,%rbx,1),%esi
add    $0xc0,%r10
add    $0x30,%rdi
add    $0xc0,%r11
add    $0x30,%rcx
add    $0xc0,%r8
add    $0x30,%r9
add    $0xfffffffd,%r15d
jne    1170 <main+0x50>
lea    0xe1a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Sum is %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*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10485760, i32* %6
store i32 60000000, i32* %7
store i32 1, i32* %8
store i32 0, i32* %9
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = mul i64 4, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %20
20: ; preds = %24, %2
%21 = load i32, i32* %11
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = load i32, i32* %9
%26 = load i32, i32* %6
%27 = srem i32 %25, %26
store i32 %27, i32* %13
%28 = load i32*, i32** %10
%29 = load i32, i32* %13
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = load i32, i32* %12
%34 = add nsw i32 %33, %32
store i32 %34, i32* %12
%35 = load i32, i32* %8
%36 = load i32, i32* %11
%37 = add nsw i32 %36, %35
store i32 %37, i32* %11
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 16
store i32 %39, i32* %9
br label %20
40: ; preds = %20
%41 = load i32, i32* %12
%42 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [11 x i8] c"Sum is %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 41943040)
%4 = inttoptr i64 %3 to i32*
br label %5
5: ; preds = %5, %2
%6 = phi i32 [ 0, %2 ], [ %27, %5 ]
%7 = phi i32 [ 0, %2 ], [ %25, %5 ]
%8 = phi i32 [ 0, %2 ], [ %26, %5 ]
%9 = urem i32 %6, 10485760
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %4, i64 %10
%12 = load i32, i32* %11
%13 = add nsw i32 %12, %7
%14 = add nuw nsw i32 %6, 16
%15 = urem i32 %14, 10485760
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %4, i64 %16
%18 = load i32, i32* %17
%19 = add nsw i32 %18, %13
%20 = add nuw nsw i32 %6, 32
%21 = urem i32 %20, 10485760
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %4, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %24, %19
%26 = add nuw nsw i32 %8, 3
%27 = add nuw nsw i32 %6, 48
%28 = icmp eq i32 %26, 60000000
br i1 %28, label %29, label %5
29: ; preds = %5
%30 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %25)
ret i32 0
}