#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 {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
unsigned long gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int j;
  unsigned long i, ret = 0;
  struct timeval start, end;
  double s, e;
  unsigned long k;
  int *arr = NULL;
  if (argc != 2) {
    printf("one arg needed\n");
    return 1;
  } else {
    k = strtoul(argv[1], NULL, 0);
  }
  while (arr == NULL)
    arr = (int *)malloc(67108864 * sizeof(int));
  ret = gettimeofday(&start, NULL);
  if (ret != 0) {
    perror("start gettime error\n");
    return 1;
  }
  for (i = 0; i < 67108864; i += k)
    j = arr[i];
  ret = gettimeofday(&end, NULL);
  if (ret != 0) {
    perror("end gettime error\n");
    return 1;
  }
  s = (double)start.tv_sec + (double)start.tv_usec / 1000000.0;
  e = (double)end.tv_sec + (double)end.tv_usec / 1000000.0;
  printf("%lu\t%lf elapsed\n", k, e - s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x68(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119a <main+0x4a>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d6 <main+0x186>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %rax,-0x60(%rbp)
jmp    11b6 <main+0x66>
cmpq   $0x0,-0x68(%rbp)
jne    11d4 <main+0x84>
mov    $0x10000000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x68(%rbp)
jmp    11b6 <main+0x66>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1208 <main+0xb8>
lea    0xe21(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d6 <main+0x186>
movq   $0x0,-0x20(%rbp)
cmpq   $0x4000000,-0x20(%rbp)
04
jae    123d <main+0xed>
mov    -0x68(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x60(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1210 <main+0xc0>
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1271 <main+0x121>
lea    0xdcd(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d6 <main+0x186>
cvtsi2sdq -0x30(%rbp),%xmm0
cvtsi2sdq -0x38(%rbp),%xmm1
movsd  0xd7b(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdq -0x40(%rbp),%xmm0
cvtsi2sdq -0x48(%rbp),%xmm1
movsd  0xd5a(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x60(%rbp),%rsi
movsd  -0x58(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
lea    0xd78(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jne    11fe <main+0x9e>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %rax,%r14
mov    $0x10000000,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1180 <main+0x20>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %rax,%rax
jne    1219 <main+0xb9>
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %rax,%rax
jne    1222 <main+0xc2>
cvtsi2sdq 0x20(%rsp),%xmm1
cvtsi2sdq 0x18(%rsp),%xmm2
movsd  0xe37(%rip),%xmm3
divsd  %xmm3,%xmm2
cvtsi2sdq 0x10(%rsp),%xmm4
cvtsi2sdq 0x8(%rsp),%xmm0
addsd  %xmm1,%xmm2
divsd  %xmm3,%xmm0
addsd  %xmm4,%xmm0
subsd  %xmm2,%xmm0
lea    0xe3e(%rip),%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    120f <main+0xaf>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xde8(%rip),%rdi
jmp    1229 <main+0xc9>
lea    0xdf4(%rip),%rdi
call   1070 <perror@plt>
jmp    120a <main+0xaa>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [16 x i8] c"one arg needed\0A\00"
@.str.1 = [21 x i8] c"start gettime error\0A\00"
@.str.2 = [19 x i8] c"end gettime error\0A\00"
@.str.3 = [17 x i8] c"%lu\09%lf elapsed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca double
%12 = alloca double
%13 = alloca i64
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %8
store i32* null, i32** %14
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %78
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strtoul(i8* %22, i32* null, i32 0)
store i64 %23, i64* %13
br label %24
24: ; preds = %19
br label %25
25: ; preds = %28, %24
%26 = load i32*, i32** %14
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i64 @malloc(i32 268435456)
%30 = inttoptr i64 %29 to i32*
store i32* %30, i32** %14
br label %25
31: ; preds = %25
%32 = call i64 @gettimeofday(%struct.timeval* %9, i32* null)
store i64 %32, i64* %8
%33 = load i64, i64* %8
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %78
37: ; preds = %31
store i64 0, i64* %7
br label %38
38: ; preds = %46, %37
%39 = load i64, i64* %7
%40 = icmp ult i64 %39, 67108864
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = load i32*, i32** %14
%43 = load i64, i64* %7
%44 = getelementptr inbounds i32, i32* %42, i64 %43
%45 = load i32, i32* %44
store i32 %45, i32* %6
br label %46
46: ; preds = %41
%47 = load i64, i64* %13
%48 = load i64, i64* %7
%49 = add i64 %48, %47
store i64 %49, i64* %7
br label %38
50: ; preds = %38
%51 = call i64 @gettimeofday(%struct.timeval* %10, i32* null)
store i64 %51, i64* %8
%52 = load i64, i64* %8
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %78
56: ; preds = %50
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%58 = load i64, i64* %57
%59 = sitofp i64 %58 to double
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%61 = load i64, i64* %60
%62 = sitofp i64 %61 to double
%63 = fdiv double %62, 1.000000e+06
%64 = fadd double %59, %63
store double %64, double* %11
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%66 = load i64, i64* %65
%67 = sitofp i64 %66 to double
%68 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%69 = load i64, i64* %68
%70 = sitofp i64 %69 to double
%71 = fdiv double %70, 1.000000e+06
%72 = fadd double %67, %71
store double %72, double* %12
%73 = load i64, i64* %13
%74 = load double, double* %12
%75 = load double, double* %11
%76 = fsub double %74, %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %73, double %76)
store i32 0, i32* %3
br label %78
78: ; preds = %56, %54, %35, %17
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str.1 = [21 x i8] c"start gettime error\0A\00"
@.str.2 = [19 x i8] c"end gettime error\0A\00"
@.str.3 = [17 x i8] c"%lu\09%lf elapsed\0A\00"
@str = [15 x i8] c"one arg needed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %46
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strtoul(i8* nocapture %12, i32* null, i32 0)
br label %14
14: ; preds = %10, %14
%15 = tail call i64 @malloc(i32 268435456)
%16 = icmp eq i64 %15, 0
br i1 %16, label %14, label %17
17: ; preds = %14
%18 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i64 @gettimeofday(%struct.timeval* %4, i32* null)
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %25
23: ; preds = %17
%24 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %46
25: ; preds = %20
%26 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %46
27: ; preds = %20
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%29 = load i64, i64* %28
%30 = sitofp i64 %29 to double
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%32 = load i64, i64* %31
%33 = sitofp i64 %32 to double
%34 = fdiv double %33, 1.000000e+06
%35 = fadd double %34, %30
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%37 = load i64, i64* %36
%38 = sitofp i64 %37 to double
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%40 = load i64, i64* %39
%41 = sitofp i64 %40 to double
%42 = fdiv double %41, 1.000000e+06
%43 = fadd double %42, %38
%44 = fsub double %43, %35
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %13, double %44)
br label %46
46: ; preds = %27, %25, %23, %8
%47 = phi i32 [ 1, %8 ], [ 1, %23 ], [ 1, %25 ], [ 0, %27 ]
ret i32 %47
}