#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 */
struct timeval {
  double tv_sec;
  double tv_usec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, int, double, int);
int /*<<< orphan*/ stderr;
int main(void) {
  struct timeval t1, t2;
  double timeuse;
  int i, j;
  int sizes[18];
  FILE *fp;
  for (i = 0; i < 18; i++) {
    sizes[i] = (1 << i) << 10;
  }
  if ((fp = fopen("./63.dat", "w+")) == NULL) {
    fprintf(stderr, "Create data file failed.\n");
    return -1;
  }
  for (i = 0; i < 18; i++) {
    int size = sizes[i];
    char *data = (char *)malloc(size * sizeof(char));
    memset(data, 1, size);
    int result = 0;
    gettimeofday(&t1, NULL);
    for (j = 0; j < (1 << 25); j++) {
      result += data[((long long)63 * (j % size)) % size];
    }
    gettimeofday(&t2, NULL);
    timeuse = t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec) / 1000000.0;
    printf("%dK, %fsecs, result:%d\n", size / 1024, timeuse, result);
    fprintf(fp, "%d %f\n", size / 1024, timeuse);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x12,-0x34(%rbp)
jge    11b8 <main+0x48>
mov    -0x34(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
shl    $0xa,%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x80(%rbp,%rax,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1189 <main+0x19>
lea    0xe49(%rip),%rdi
lea    0xe4b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmp    $0x0,%rax
jne    1200 <main+0x90>
mov    0x2dfd(%rip),%rax
movslq (%rax),%rdi
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1372 <main+0x202>
movl   $0x0,-0x34(%rbp)
cmpl   $0x12,-0x34(%rbp)
jge    135f <main+0x1ef>
movslq -0x34(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%eax
mov    %eax,-0x8c(%rbp)
movslq -0x8c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdi
mov    -0x8c(%rbp),%edx
mov    $0x1,%esi
call   1060 <memset@plt>
movl   $0x0,-0x9c(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x38(%rbp)
cmpl   $0x2000000,-0x38(%rbp)
jge    12ca <main+0x15a>
mov    -0x98(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x38(%rbp),%eax
cltd
idivl  -0x8c(%rbp)
movslq %edx,%rax
imul   $0x3f,%rax,%rax
movslq -0x8c(%rbp),%rcx
cqto
idiv   %rcx
mov    -0xa8(%rbp),%rax
movsbl (%rax,%rdx,1),%eax
add    -0x9c(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    126d <main+0xfd>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movsd  0xd0d(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8c(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
movsd  -0x30(%rbp),%xmm0
mov    -0x9c(%rbp),%edx
lea    0xd0c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x88(%rbp),%rdi
mov    -0x8c(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
movsd  -0x30(%rbp),%xmm0
lea    0xcfc(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1207 <main+0x97>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
movaps 0xe68(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe6c(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe70(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe74(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movabs $0x800000004000000,%rax
mov    %rax,0x80(%rsp)
lea    0xe6e(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1344 <main+0x1c4>
mov    $0x400,%r12d
xor    %r13d,%r13d
nopl   (%rax)
movslq %r12d,%r14
mov    %r14d,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
call   1060 <memset@plt>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
xor    %ebp,%ebp
xor    %ecx,%ecx
jmp    1247 <main+0xc7>
cqto
idiv   %r14
movsbl (%r15,%rdx,1),%eax
add    %eax,%ebp
add    $0x1,%ecx
cmp    $0x2000000,%ecx
je     12b0 <main+0x130>
mov    %ecx,%eax
cltd
idiv   %r14d
mov    %rdx,%rax
shl    $0x6,%rax
sub    %rdx,%rax
mov    %rax,%rdx
or     %r14,%rdx
shr    $0x20,%rdx
je     1270 <main+0xf0>
cqto
idiv   %r14
jmp    1275 <main+0xf5>
nopw   0x0(%rax,%rax,1)
xor    %edx,%edx
div    %r12d
movsbl (%r15,%rdx,1),%eax
add    %eax,%ebp
add    $0x1,%ecx
mov    %ecx,%eax
cltd
idiv   %r12d
mov    %rdx,%rax
shl    $0x6,%rax
sub    %rdx,%rax
mov    %rax,%rdx
or     %r14,%rdx
shr    $0x20,%rdx
jne    1230 <main+0xb0>
xor    %edx,%edx
div    %r12d
jmp    1235 <main+0xb5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movapd 0x20(%rsp),%xmm0
subpd  0x30(%rsp),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
divsd  0xd68(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
movapd %xmm1,0x10(%rsp)
lea    0x3ff(%r12),%ebx
test   %r12d,%r12d
cmovns %r12d,%ebx
sar    $0xa,%ebx
lea    0xd6f(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
lea    0xd72(%rip),%rsi
mov    %ebx,%edx
movaps 0x10(%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
add    $0x1,%r13
cmp    $0x12,%r13
je     1336 <main+0x1b6>
mov    0x40(%rsp,%r13,4),%r12d
jmp    1200 <main+0x80>
mov    0x8(%rsp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1369 <main+0x1e9>
mov    0x2c95(%rip),%rax
movslq (%rax),%rcx
lea    0xcff(%rip),%rdi
mov    $0x19,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    $0xffffffff,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [9 x i8] c"./63.dat\00"
@.str.1 = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Create data file failed.\0A\00"
@.str.3 = [24 x i8] c"%dK, %fsecs, result:%d\0A\00"
@.str.4 = [7 x i8] c"%d %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca [18 x i32]
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
br label %12
12: ; preds = %22, %0
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 18
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i32, i32* %5
%17 = shl i32 1, %16
%18 = shl i32 %17, 10
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [18 x i32], [18 x i32]* %7, i64 0, i64 %20
store i32 %18, i32* %21
br label %22
22: ; preds = %15
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %12
25: ; preds = %12
%26 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %8
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = sext i32 %29 to i64
%31 = inttoptr i64 %30 to i32*
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %103
33: ; preds = %25
store i32 0, i32* %5
br label %34
34: ; preds = %97, %33
%35 = load i32, i32* %5
%36 = icmp slt i32 %35, 18
br i1 %36, label %37, label %100
37: ; preds = %34
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [18 x i32], [18 x i32]* %7, i64 0, i64 %39
%41 = load i32, i32* %40
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = mul i64 %43, 1
%45 = trunc i64 %44 to i32
%46 = call i64 @malloc(i32 %45)
%47 = inttoptr i64 %46 to i8*
store i8* %47, i8** %10
%48 = load i8*, i8** %10
%49 = load i32, i32* %9
%50 = call i32 @memset(i8* %48, i32 1, i32 %49)
store i32 0, i32* %11
%51 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
store i32 0, i32* %6
br label %52
52: ; preds = %70, %37
%53 = load i32, i32* %6
%54 = icmp slt i32 %53, 33554432
br i1 %54, label %55, label %73
55: ; preds = %52
%56 = load i8*, i8** %10
%57 = load i32, i32* %6
%58 = load i32, i32* %9
%59 = srem i32 %57, %58
%60 = sext i32 %59 to i64
%61 = mul nsw i64 63, %60
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = srem i64 %61, %63
%65 = getelementptr inbounds i8, i8* %56, i64 %64
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = load i32, i32* %11
%69 = add nsw i32 %68, %67
store i32 %69, i32* %11
br label %70
70: ; preds = %55
%71 = load i32, i32* %6
%72 = add nsw i32 %71, 1
store i32 %72, i32* %6
br label %52
73: ; preds = %52
%74 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%75 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%76 = load double, double* %75
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%78 = load double, double* %77
%79 = fsub double %76, %78
%80 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%81 = load double, double* %80
%82 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%83 = load double, double* %82
%84 = fsub double %81, %83
%85 = fdiv double %84, 1.000000e+06
%86 = fadd double %79, %85
store double %86, double* %4
%87 = load i32, i32* %9
%88 = sdiv i32 %87, 1024
%89 = load double, double* %4
%90 = load i32, i32* %11
%91 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %88, double %89, i32 %90)
%92 = load i32*, i32** %8
%93 = load i32, i32* %9
%94 = sdiv i32 %93, 1024
%95 = load double, double* %4
%96 = call i32 (i32*, i8*, ...) @fprintf(i32* %92, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %94, double %95)
br label %97
97: ; preds = %73
%98 = load i32, i32* %5
%99 = add nsw i32 %98, 1
store i32 %99, i32* %5
br label %34
100: ; preds = %34
%101 = load i32*, i32** %8
%102 = call i32 @fclose(i32* %101)
store i32 0, i32* %1
br label %103
103: ; preds = %100, %28
%104 = load i32, i32* %1
ret i32 %104
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [9 x i8] c"./63.dat\00"
@.str.1 = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Create data file failed.\0A\00"
@.str.3 = [24 x i8] c"%dK, %fsecs, result:%d\0A\00"
@.str.4 = [7 x i8] c"%d %f\0A\00"
define i32 @main() {
%1 = alloca <2 x double>
%2 = bitcast <2 x double>* %1 to %struct.timeval*
%3 = alloca <2 x double>
%4 = bitcast <2 x double>* %3 to %struct.timeval*
%5 = alloca [18 x i32]
%6 = bitcast <2 x double>* %1 to i8*
%7 = bitcast <2 x double>* %3 to i8*
%8 = bitcast [18 x i32]* %5 to i8*
%9 = bitcast [18 x i32]* %5 to <4 x i32>*
store <4 x i32> <i32 1024, i32 2048, i32 4096, i32 8192>, <4 x i32>* %9
%10 = getelementptr inbounds [18 x i32], [18 x i32]* %5, i64 0, i64 4
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 16384, i32 32768, i32 65536, i32 131072>, <4 x i32>* %11
%12 = getelementptr inbounds [18 x i32], [18 x i32]* %5, i64 0, i64 8
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> <i32 262144, i32 524288, i32 1048576, i32 2097152>, <4 x i32>* %13
%14 = getelementptr inbounds [18 x i32], [18 x i32]* %5, i64 0, i64 12
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 4194304, i32 8388608, i32 16777216, i32 33554432>, <4 x i32>* %15
%16 = getelementptr inbounds [18 x i32], [18 x i32]* %5, i64 0, i64 16
store i32 67108864, i32* %16
%17 = getelementptr inbounds [18 x i32], [18 x i32]* %5, i64 0, i64 17
store i32 134217728, i32* %17
%18 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %0
%21 = load i32, i32* @stderr
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i32*
%24 = tail call i64 @fwrite(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 25, i64 1, i32* %23)
br label %74
25: ; preds = %0, %69
%26 = phi i32 [ %71, %69 ], [ 1024, %0 ]
%27 = phi i64 [ %67, %69 ], [ 0, %0 ]
%28 = sext i32 %26 to i64
%29 = tail call i64 @malloc(i32 %26)
%30 = inttoptr i64 %29 to i8*
%31 = tail call i32 @memset(i8* %30, i32 1, i32 %26)
%32 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %33
33: ; preds = %33, %25
%34 = phi i32 [ 0, %25 ], [ %52, %33 ]
%35 = phi i32 [ 0, %25 ], [ %53, %33 ]
%36 = srem i32 %35, %26
%37 = zext i32 %36 to i64
%38 = mul nuw nsw i64 %37, 63
%39 = srem i64 %38, %28
%40 = getelementptr inbounds i8, i8* %30, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = add nsw i32 %34, %42
%44 = or i32 %35, 1
%45 = srem i32 %44, %26
%46 = zext i32 %45 to i64
%47 = mul nuw nsw i64 %46, 63
%48 = srem i64 %47, %28
%49 = getelementptr inbounds i8, i8* %30, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = add nsw i32 %43, %51
%53 = add nuw nsw i32 %35, 2
%54 = icmp eq i32 %53, 33554432
br i1 %54, label %55, label %33
55: ; preds = %33
%56 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%57 = load <2 x double>, <2 x double>* %3
%58 = load <2 x double>, <2 x double>* %1
%59 = fsub <2 x double> %57, %58
%60 = extractelement <2 x double> %59, i64 1
%61 = fdiv double %60, 1.000000e+06
%62 = extractelement <2 x double> %59, i64 0
%63 = fadd double %62, %61
%64 = sdiv i32 %26, 1024
%65 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %64, double %63, i32 %52)
%66 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %64, double %63)
%67 = add nuw nsw i64 %27, 1
%68 = icmp eq i64 %67, 18
br i1 %68, label %72, label %69
69: ; preds = %55
%70 = getelementptr inbounds [18 x i32], [18 x i32]* %5, i64 0, i64 %67
%71 = load i32, i32* %70
br label %25
72: ; preds = %55
%73 = tail call i32 @fclose(i32* %18)
br label %74
74: ; preds = %72, %20
%75 = phi i32 [ -1, %20 ], [ 0, %72 ]
ret i32 %75
}