#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*/ free(int *);
int /*<<< orphan*/ init_array(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
long long wall_clock_time();
int main() {
  long long start, end;
  int stepsize, i, j, k, run, sum,
      lengthmod = 3 * 1024 * 1024 / sizeof(int) - 1;
  int *array = malloc(3 * 1024 * 1024);
  init_array(array);
  printf("start testing!\n");
  for (stepsize = 1; stepsize < 1024 / sizeof(int); stepsize *= 2) {
    start = wall_clock_time();
    for (i = 0; i < 512 * 1024; i++) {
      array[(i * stepsize) & lengthmod]++;
    }
    end = wall_clock_time();
    printf("stepsize: %3lu time%lf\n", stepsize * sizeof(int),
           ((float)(end - start)) / 1000000000);
  }
  free(array);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xbffff,-0x34(%rbp)
mov    $0x300000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <init_array@plt>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x100,%rax
jae    1235 <main+0xe5>
mov    $0x0,%al
call   1060 <wall_clock_time@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x80000,-0x20(%rbp)
jge    11e9 <main+0x99>
mov    -0x40(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
and    -0x34(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b4 <main+0x64>
mov    $0x0,%al
call   1060 <wall_clock_time@plt>
mov    %rax,-0x18(%rbp)
movslq -0x1c(%rbp),%rsi
shl    $0x2,%rsi
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2ss %rax,%xmm0
movss  0xdef(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf4(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1192 <main+0x42>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x300000,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <init_array@plt>
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    $0x1,%r15d
lea    0xe66(%rip),%r14
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <wall_clock_time@plt>
mov    %rax,%r12
lea    0x0(%rbp,%rbp,1),%r13d
mov    $0x80000,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%edx
and    $0xbfffe,%edx
addl   $0x1,(%rbx,%rdx,4)
lea    (%rcx,%rbp,1),%edx
and    $0xbffff,%edx
addl   $0x1,(%rbx,%rdx,4)
add    %r13d,%ecx
add    $0xfffffffe,%eax
jne    11c0 <main+0x60>
xor    %eax,%eax
call   1070 <wall_clock_time@plt>
sub    %r12,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
shl    $0x2,%r15
divss  0xe01(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r13,%r15
mov    %r13d,%ebp
cmp    $0x100,%r13d
jb     11a0 <main+0x40>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"start testing!\0A\00"
@.str.1 = [24 x i8] c"stepsize: %3lu time%lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i32 0, i32* %1
store i32 786431, i32* %10
%12 = call i32* @malloc(i32 3145728)
store i32* %12, i32** %11
%13 = load i32*, i32** %11
%14 = call i32 @init_array(i32* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
br label %16
16: ; preds = %51, %0
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = icmp ult i64 %18, 256
br i1 %19, label %20, label %54
20: ; preds = %16
%21 = call i64 (...) @wall_clock_time()
store i64 %21, i64* %2
store i32 0, i32* %5
br label %22
22: ; preds = %36, %20
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 524288
br i1 %24, label %25, label %39
25: ; preds = %22
%26 = load i32*, i32** %11
%27 = load i32, i32* %5
%28 = load i32, i32* %4
%29 = mul nsw i32 %27, %28
%30 = load i32, i32* %10
%31 = and i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %26, i64 %32
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* %33
br label %36
36: ; preds = %25
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %22
39: ; preds = %22
%40 = call i64 (...) @wall_clock_time()
store i64 %40, i64* %3
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = mul i64 %42, 4
%44 = load i64, i64* %3
%45 = load i64, i64* %2
%46 = sub nsw i64 %44, %45
%47 = sitofp i64 %46 to float
%48 = fdiv float %47, 1.000000e+09
%49 = fpext float %48 to double
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %43, double %49)
br label %51
51: ; preds = %39
%52 = load i32, i32* %4
%53 = mul nsw i32 %52, 2
store i32 %53, i32* %4
br label %16
54: ; preds = %16
%55 = load i32*, i32** %11
%56 = call i32 @free(i32* %55)
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c"stepsize: %3lu time%lf\0A\00"
@str = [15 x i8] c"start testing!\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 3145728)
%2 = tail call i32 @init_array(i32* %1)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %0, %25
%5 = phi i64 [ 1, %0 ], [ %34, %25 ]
%6 = phi i32 [ 1, %0 ], [ %33, %25 ]
%7 = tail call i64 (...) @wall_clock_time()
br label %8
8: ; preds = %8, %4
%9 = phi i32 [ 0, %4 ], [ %23, %8 ]
%10 = mul nuw nsw i32 %9, %6
%11 = and i32 %10, 786430
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %1, i64 %12
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
store i32 %15, i32* %13
%16 = or i32 %9, 1
%17 = mul nuw nsw i32 %16, %6
%18 = and i32 %17, 786431
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1
store i32 %22, i32* %20
%23 = add nuw nsw i32 %9, 2
%24 = icmp eq i32 %23, 524288
br i1 %24, label %25, label %8
25: ; preds = %8
%26 = tail call i64 (...) @wall_clock_time()
%27 = shl nuw nsw i64 %5, 2
%28 = sub nsw i64 %26, %7
%29 = sitofp i64 %28 to float
%30 = fdiv float %29, 1.000000e+09
%31 = fpext float %30 to double
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %27, double %31)
%33 = shl nsw i32 %6, 1
%34 = zext i32 %33 to i64
%35 = icmp ult i32 %33, 256
br i1 %35, label %4, label %36
36: ; preds = %25
%37 = tail call i32 @free(i32* %1)
ret i32 0
}