#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 /*<<< orphan*/ usleep(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 (1) {
    int read_addr = count % MEM_SIZE;
    tmp += mem[read_addr];
    elapsed += DELAY_OPS;
    count += 16;
    usleep(10);
  }
  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   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
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,-0x40(%rbp)
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x38(%rbp)
mov    %eax,-0x20(%rbp)
mov    $0xa,%edi
call   1040 <usleep@plt>
jmp    1173 <main+0x53>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x2800000,%edi
call   1030 <malloc@plt>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1040 <usleep@plt>
jmp    1130 <main+0x10>

LLVM IR (-O0):
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 = %2, %20
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = srem i32 %21, %22
store i32 %23, i32* %13
%24 = load i32*, i32** %10
%25 = load i32, i32* %13
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = load i32, i32* %12
%30 = add nsw i32 %29, %28
store i32 %30, i32* %12
%31 = load i32, i32* %8
%32 = load i32, i32* %11
%33 = add nsw i32 %32, %31
store i32 %33, i32* %11
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 16
store i32 %35, i32* %9
%36 = call i32 @usleep(i32 10)
br label %20
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 41943040)
br label %4
4: ; preds = %4, %2
%5 = tail call i32 @usleep(i32 10)
br label %4
}