#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 */
typedef double clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int *calloc(int const, int);
double clock();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  const int ndata = 64 * 1024 * 1024;
  const int nloops = 1024;
  const int max_skip = 4096;
  int *data = calloc(ndata, sizeof(int));
  if (data == NULL) {
    exit(EXIT_FAILURE);
  }
  printf("# skip time efficiency\n");
  for (int skip = 1; skip <= max_skip; skip *= 2) {
    clock_t t = clock();
    for (int nl = 0; nl < nloops; nl++) {
      for (int nd = 0; nd < ndata; nd += skip) {
        data[nd]++;
      }
    }
    t = clock() - t;
    clock_t t1;
    if (skip == 1) {
      t1 = t;
    }
    printf("%d %lf %lf\n", skip, (double)t / CLOCKS_PER_SEC,
           (double)t1 / t / skip);
  }
  free(data);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4000000,-0x8(%rbp)
movl   $0x400,-0xc(%rbp)
movl   $0x1000,-0x10(%rbp)
mov    $0x4000000,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a0 <main+0x50>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x1000,-0x1c(%rbp)
jg     128f <main+0x13f>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x400,-0x2c(%rbp)
jge    1228 <main+0xd8>
movl   $0x0,-0x30(%rbp)
cmpl   $0x4000000,-0x30(%rbp)
jge    1215 <main+0xc5>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    11e9 <main+0x99>
jmp    121a <main+0xca>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d5 <main+0x85>
mov    $0x0,%al
call   1040 <clock@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    124d <main+0xfd>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x1c(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
mov    0x2d8c(%rip),%rax
divsd  (%rax),%xmm0
movsd  -0x38(%rbp),%xmm1
divsd  -0x28(%rbp),%xmm1
cvtsi2sdl -0x1c(%rbp),%xmm2
divsd  %xmm2,%xmm1
lea    0xd9e(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b5 <main+0x65>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x4000000,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
test   %rax,%rax
jne    1190 <main+0x30>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %rax,%r15
lea    0xe72(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%r12
add    $0x10,%r12
mov    $0x1,%ebp
mov    0x2e36(%rip),%r13
lea    0xe47(%rip),%r14
jmp    1201 <main+0xa1>
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
divsd  %xmm0,%xmm1
divsd  0x0(%r13),%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %ebp,%xmm2
divsd  %xmm2,%xmm1
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x2,%al
call   1060 <printf@plt>
add    %ebp,%ebp
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
cmp    $0x1001,%ebp
jae    1315 <main+0x1b5>
mov    %ebp,%ebx
xor    %eax,%eax
call   1050 <clock@plt>
movq   %xmm0,0x8(%rsp)
mov    %ebp,%ebp
mov    $0x3ffffff,%eax
xor    %edx,%edx
div    %ebx
add    $0x1,%rax
mov    %eax,%ecx
and    $0x7fffff8,%ecx
mov    %rcx,%r8
imul   %rbp,%r8
mov    %rbp,%rsi
shl    $0x5,%rsi
mov    %rbp,%rdi
shl    $0x6,%rdi
xor    %r9d,%r9d
pcmpeqd %xmm2,%xmm2
jmp    1261 <main+0x101>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r9d
cmp    $0x400,%r9d
je     12f0 <main+0x190>
cmp    $0x1,%ebp
jne    12c0 <main+0x160>
mov    %r12,%rdx
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movdqu -0x10(%rdx),%xmm0
movdqu (%rdx),%xmm1
psubd  %xmm2,%xmm0
psubd  %xmm2,%xmm1
movdqu %xmm0,-0x10(%rdx)
movdqu %xmm1,(%rdx)
movdqu -0x10(%rdx,%rsi,1),%xmm0
movdqu (%rdx,%rsi,1),%xmm1
psubd  %xmm2,%xmm0
psubd  %xmm2,%xmm1
movdqu %xmm0,-0x10(%rdx,%rsi,1)
movdqu %xmm1,(%rdx,%rsi,1)
add    $0x10,%rbx
add    %rdi,%rdx
cmp    %rcx,%rbx
jne    1270 <main+0x110>
mov    %r8,%rdx
cmp    %rcx,%rax
jne    12d0 <main+0x170>
jmp    1250 <main+0xf0>
xchg   %ax,%ax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
addl   $0x1,(%r15,%rdx,4)
add    %rbp,%rdx
cmp    $0x4000000,%rdx
jb     12d0 <main+0x170>
jmp    1250 <main+0xf0>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <clock@plt>
subsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm1
cmp    $0x1,%ebp
je     11c0 <main+0x60>
movsd  0x10(%rsp),%xmm1
jmp    11c0 <main+0x60>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [24 x i8] c"# skip time efficiency\0A\00"
@.str.1 = [12 x i8] c"%d %lf %lf\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
store i32 0, i32* %1
store i32 67108864, i32* %2
store i32 1024, i32* %3
store i32 4096, i32* %4
%11 = call i32* @calloc(i32 67108864, i32 4)
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %19
19: ; preds = %66, %17
%20 = load i32, i32* %6
%21 = icmp sle i32 %20, 4096
br i1 %21, label %22, label %69
22: ; preds = %19
%23 = call double (...) @clock()
store double %23, double* %7
store i32 0, i32* %8
br label %24
24: ; preds = %43, %22
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 1024
br i1 %26, label %27, label %46
27: ; preds = %24
store i32 0, i32* %9
br label %28
28: ; preds = %38, %27
%29 = load i32, i32* %9
%30 = icmp slt i32 %29, 67108864
br i1 %30, label %31, label %42
31: ; preds = %28
%32 = load i32*, i32** %5
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
store i32 %37, i32* %35
br label %38
38: ; preds = %31
%39 = load i32, i32* %6
%40 = load i32, i32* %9
%41 = add nsw i32 %40, %39
store i32 %41, i32* %9
br label %28
42: ; preds = %28
br label %43
43: ; preds = %42
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %24
46: ; preds = %24
%47 = call double (...) @clock()
%48 = load double, double* %7
%49 = fsub double %47, %48
store double %49, double* %7
%50 = load i32, i32* %6
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = load double, double* %7
store double %53, double* %10
br label %54
54: ; preds = %52, %46
%55 = load i32, i32* %6
%56 = load double, double* %7
%57 = load double, double* @CLOCKS_PER_SEC
%58 = fdiv double %56, %57
%59 = load double, double* %10
%60 = load double, double* %7
%61 = fdiv double %59, %60
%62 = load i32, i32* %6
%63 = sitofp i32 %62 to double
%64 = fdiv double %61, %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %55, double %58, double %64)
br label %66
66: ; preds = %54
%67 = load i32, i32* %6
%68 = mul nsw i32 %67, 2
store i32 %68, i32* %6
br label %19
69: ; preds = %19
%70 = load i32*, i32** %5
%71 = call i32 @free(i32* %70)
%72 = load i32, i32* @EXIT_SUCCESS
%73 = call i32 @exit(i32 %72)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"%d %lf %lf\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@EXIT_SUCCESS = global i32 0
@str = [23 x i8] c"# skip time efficiency\00"
define i32 @main() {
%1 = tail call i32* @calloc(i32 67108864, i32 4)
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @EXIT_FAILURE
%5 = tail call i32 @exit(i32 %4)
unreachable
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %12
8: ; preds = %55
%9 = tail call i32 @free(i32* %1)
%10 = load i32, i32* @EXIT_SUCCESS
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %6, %55
%13 = phi double [ undef, %6 ], [ %59, %55 ]
%14 = phi i32 [ 1, %6 ], [ %66, %55 ]
%15 = tail call double (...) @clock()
%16 = zext i32 %14 to i64
%17 = udiv i64 67108863, %16
%18 = add nuw nsw i64 %17, 1
%19 = icmp eq i32 %14, 1
%20 = and i64 %18, 134217720
%21 = mul nuw nsw i64 %20, %16
%22 = icmp eq i64 %18, %20
br label %23
23: ; preds = %12, %68
%24 = phi i32 [ 0, %12 ], [ %69, %68 ]
br i1 %19, label %25, label %53
25: ; preds = %23, %25
%26 = phi i64 [ %50, %25 ], [ 0, %23 ]
%27 = mul nuw nsw i64 %26, %16
%28 = getelementptr inbounds i32, i32* %1, i64 %27
%29 = bitcast i32* %28 to <4 x i32>*
%30 = load <4 x i32>, <4 x i32>* %29
%31 = getelementptr inbounds i32, i32* %28, i64 4
%32 = bitcast i32* %31 to <4 x i32>*
%33 = load <4 x i32>, <4 x i32>* %32
%34 = add nsw <4 x i32> %30, <i32 1, i32 1, i32 1, i32 1>
%35 = add nsw <4 x i32> %33, <i32 1, i32 1, i32 1, i32 1>
%36 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> %34, <4 x i32>* %36
%37 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> %35, <4 x i32>* %37
%38 = or i64 %26, 8
%39 = mul nuw nsw i64 %38, %16
%40 = getelementptr inbounds i32, i32* %1, i64 %39
%41 = bitcast i32* %40 to <4 x i32>*
%42 = load <4 x i32>, <4 x i32>* %41
%43 = getelementptr inbounds i32, i32* %40, i64 4
%44 = bitcast i32* %43 to <4 x i32>*
%45 = load <4 x i32>, <4 x i32>* %44
%46 = add nsw <4 x i32> %42, <i32 1, i32 1, i32 1, i32 1>
%47 = add nsw <4 x i32> %45, <i32 1, i32 1, i32 1, i32 1>
%48 = bitcast i32* %40 to <4 x i32>*
store <4 x i32> %46, <4 x i32>* %48
%49 = bitcast i32* %43 to <4 x i32>*
store <4 x i32> %47, <4 x i32>* %49
%50 = add nuw nsw i64 %26, 16
%51 = icmp eq i64 %50, %20
br i1 %51, label %52, label %25
52: ; preds = %25
br i1 %22, label %68, label %53
53: ; preds = %23, %52
%54 = phi i64 [ 0, %23 ], [ %21, %52 ]
br label %71
55: ; preds = %68
%56 = tail call double (...) @clock()
%57 = fsub double %56, %15
%58 = icmp eq i32 %14, 1
%59 = select i1 %58, double %57, double %13
%60 = load double, double* @CLOCKS_PER_SEC
%61 = fdiv double %57, %60
%62 = fdiv double %59, %57
%63 = sitofp i32 %14 to double
%64 = fdiv double %62, %63
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %14, double %61, double %64)
%66 = shl nsw i32 %14, 1
%67 = icmp ult i32 %66, 4097
br i1 %67, label %12, label %8
68: ; preds = %71, %52
%69 = add nuw nsw i32 %24, 1
%70 = icmp eq i32 %69, 1024
br i1 %70, label %55, label %23
71: ; preds = %53, %71
%72 = phi i64 [ %76, %71 ], [ %54, %53 ]
%73 = getelementptr inbounds i32, i32* %1, i64 %72
%74 = load i32, i32* %73
%75 = add nsw i32 %74, 1
store i32 %75, i32* %73
%76 = add nuw nsw i64 %72, %16
%77 = icmp ult i64 %76, 67108864
br i1 %77, label %71, label %68
}