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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1000000,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x100,%rax
jae    1214 <main+0xd4>
mov    $0x0,%al
call   1060 <wall_clock_time@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    $0x1000000,%rax
jae    11c8 <main+0x88>
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1199 <main+0x59>
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  0xe10(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe15(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1177 <main+0x37>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1000000,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%r13
lea    0xeaa(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rax
add    $0x10,%rax
mov    %rax,(%rsp)
mov    $0x1,%ebx
mov    $0x1,%r14d
lea    0xe6e(%rip),%rbp
jmp    11e5 <main+0x95>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <wall_clock_time@plt>
sub    %r12,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
shl    $0x2,%r14
divss  0xe42(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1050 <printf@plt>
add    %r15d,%r15d
mov    %r15,%r14
mov    %r15d,%ebx
cmp    $0x100,%r15d
jae    12c7 <main+0x177>
xor    %eax,%eax
call   1070 <wall_clock_time@plt>
mov    %rax,%r12
mov    %ebx,%r15d
mov    $0xffffff,%eax
xor    %edx,%edx
div    %ebx
cmp    $0x1,%ebx
jne    12a0 <main+0x150>
mov    %rbp,%r8
add    $0x1,%rax
mov    %eax,%edx
and    $0x1fffff8,%edx
mov    %rdx,%rcx
imul   %r15,%rcx
mov    %r15,%rsi
shl    $0x5,%rsi
mov    %r15,%rdi
shl    $0x6,%rdi
mov    (%rsp),%rbx
xor    %ebp,%ebp
pcmpeqd %xmm2,%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqu -0x10(%rbx),%xmm0
movdqu (%rbx),%xmm1
psubd  %xmm2,%xmm0
psubd  %xmm2,%xmm1
movdqu %xmm0,-0x10(%rbx)
movdqu %xmm1,(%rbx)
movdqu -0x10(%rbx,%rsi,1),%xmm0
movdqu (%rbx,%rsi,1),%xmm1
psubd  %xmm2,%xmm0
psubd  %xmm2,%xmm1
movdqu %xmm0,-0x10(%rbx,%rsi,1)
movdqu %xmm1,(%rbx,%rsi,1)
add    $0x10,%rbp
add    %rdi,%rbx
cmp    %rdx,%rbp
jne    1240 <main+0xf0>
cmp    %rdx,%rax
mov    %r8,%rbp
jne    12b0 <main+0x160>
jmp    11a0 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
addl   $0x1,0x0(%r13,%rcx,4)
add    %r15,%rcx
cmp    $0x1000000,%rcx
jb     12b0 <main+0x160>
jmp    11a0 <main+0x50>
mov    %r13,%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 = [26 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*
store i32 0, i32* %1
%7 = call i32* @calloc(i32 16777216, i32 4)
store i32* %7, i32** %6
%8 = 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 %9
9: ; preds = %42, %0
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = icmp ult i64 %11, 256
br i1 %12, label %13, label %45
13: ; preds = %9
%14 = call i64 (...) @wall_clock_time()
store i64 %14, i64* %2
store i32 0, i32* %5
br label %15
15: ; preds = %26, %13
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = icmp ult i64 %17, 16777216
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load i32*, i32** %6
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
store i32 %25, i32* %23
br label %26
26: ; preds = %19
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = add nsw i32 %28, %27
store i32 %29, i32* %5
br label %15
30: ; preds = %15
%31 = call i64 (...) @wall_clock_time()
store i64 %31, i64* %3
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 4
%35 = load i64, i64* %3
%36 = load i64, i64* %2
%37 = sub nsw i64 %35, %36
%38 = sitofp i64 %37 to float
%39 = fdiv float %38, 1.000000e+06
%40 = fpext float %39 to double
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %34, double %40)
br label %42
42: ; preds = %30
%43 = load i32, i32* %4
%44 = mul nsw i32 %43, 2
store i32 %44, i32* %4
br label %9
45: ; preds = %9
%46 = load i32*, i32** %6
%47 = call i32 @free(i32* %46)
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str.1 = [26 x i8] c"stepsize: %3lu time:%lf\0A\00"
@str = [15 x i8] c"start testing!\00"
define i32 @main() {
%1 = tail call i32* @calloc(i32 16777216, i32 4)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %3
3: ; preds = %0, %52
%4 = phi i64 [ 1, %0 ], [ %61, %52 ]
%5 = phi i32 [ 1, %0 ], [ %60, %52 ]
%6 = tail call i64 (...) @wall_clock_time()
%7 = zext i32 %5 to i64
%8 = udiv i64 16777215, %7
%9 = add nuw nsw i64 %8, 1
%10 = icmp eq i32 %5, 1
br i1 %10, label %11, label %43
11: ; preds = %3
%12 = and i64 %9, 33554424
%13 = mul nuw nsw i64 %12, %7
br label %14
14: ; preds = %14, %11
%15 = phi i64 [ 0, %11 ], [ %39, %14 ]
%16 = mul nuw nsw i64 %15, %7
%17 = getelementptr inbounds i32, i32* %1, i64 %16
%18 = bitcast i32* %17 to <4 x i32>*
%19 = load <4 x i32>, <4 x i32>* %18
%20 = getelementptr inbounds i32, i32* %17, i64 4
%21 = bitcast i32* %20 to <4 x i32>*
%22 = load <4 x i32>, <4 x i32>* %21
%23 = add nsw <4 x i32> %19, <i32 1, i32 1, i32 1, i32 1>
%24 = add nsw <4 x i32> %22, <i32 1, i32 1, i32 1, i32 1>
%25 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> %23, <4 x i32>* %25
%26 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> %24, <4 x i32>* %26
%27 = or i64 %15, 8
%28 = mul nuw nsw i64 %27, %7
%29 = getelementptr inbounds i32, i32* %1, i64 %28
%30 = bitcast i32* %29 to <4 x i32>*
%31 = load <4 x i32>, <4 x i32>* %30
%32 = getelementptr inbounds i32, i32* %29, i64 4
%33 = bitcast i32* %32 to <4 x i32>*
%34 = load <4 x i32>, <4 x i32>* %33
%35 = add nsw <4 x i32> %31, <i32 1, i32 1, i32 1, i32 1>
%36 = add nsw <4 x i32> %34, <i32 1, i32 1, i32 1, i32 1>
%37 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> %35, <4 x i32>* %37
%38 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> %36, <4 x i32>* %38
%39 = add nuw nsw i64 %15, 16
%40 = icmp eq i64 %39, %12
br i1 %40, label %41, label %14
41: ; preds = %14
%42 = icmp eq i64 %9, %12
br i1 %42, label %52, label %43
43: ; preds = %3, %41
%44 = phi i64 [ 0, %3 ], [ %13, %41 ]
br label %45
45: ; preds = %43, %45
%46 = phi i64 [ %50, %45 ], [ %44, %43 ]
%47 = getelementptr inbounds i32, i32* %1, i64 %46
%48 = load i32, i32* %47
%49 = add nsw i32 %48, 1
store i32 %49, i32* %47
%50 = add nuw nsw i64 %46, %7
%51 = icmp ult i64 %50, 16777216
br i1 %51, label %45, label %52
52: ; preds = %45, %41
%53 = tail call i64 (...) @wall_clock_time()
%54 = shl nuw nsw i64 %4, 2
%55 = sub nsw i64 %53, %6
%56 = sitofp i64 %55 to float
%57 = fdiv float %56, 1.000000e+06
%58 = fpext float %57 to double
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %54, double %58)
%60 = shl nsw i32 %5, 1
%61 = zext i32 %60 to i64
%62 = icmp ult i32 %60, 256
br i1 %62, label %3, label %63
63: ; preds = %52
%64 = tail call i32 @free(i32* %1)
ret i32 0
}