#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 */
int atoi(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
unsigned long long kernel_cpu_bound(int, unsigned int);
unsigned long long kernel_mem_bound(unsigned int *, int, unsigned int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sqrt(int);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  unsigned long long nll;
  unsigned int *big_array;
  struct timeval start, end;
  unsigned int sqrt_mem_size;
  int trials;
  if (argc < 2) {
    printf("Invalid parameters, USAGE: %s [mem|cpu] [trials, default=100]\n",
           argv[0]);
    return 0;
  }
  if (argc == 3) {
    trials = atoi(argv[2]);
    if (trials < 1) {
      printf("Invalid number of trials = %d\n", trials);
      return -1;
    }
  } else {
    trials = 100;
  }
  sqrt_mem_size =
      (unsigned int)sqrt(sizeof(int) * (((1024 * 1024) / sizeof(int)) * 8));
  big_array = (int *)malloc(sizeof(int) * sqrt_mem_size * sqrt_mem_size);
  gettimeofday(&start, NULL);
  if (strcmp(argv[1], "cpu") == 0)
    nll = kernel_cpu_bound(trials, sqrt_mem_size);
  else if (strcmp(argv[1], "mem") == 0)
    nll = kernel_mem_bound(big_array, trials, sqrt_mem_size);
  else
    printf("Invalid parameters, USAGE: %s [mem|cpu]\n", argv[0]);
  gettimeofday(&end, NULL);
  printf("%f\n",
         (((double)end.tv_sec + ((double)end.tv_usec / 1000000.0)) -
          ((double)start.tv_sec + ((double)start.tv_usec / 1000000.0))));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1321 <main+0x1a1>
cmpl   $0x3,-0x8(%rbp)
jne    1207 <main+0x87>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x1,-0x48(%rbp)
jge    1202 <main+0x82>
mov    -0x48(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1321 <main+0x1a1>
jmp    120e <main+0x8e>
movl   $0x64,-0x48(%rbp)
mov    $0x800000,%edi
call   10a0 <sqrt@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
shl    $0x2,%rax
mov    -0x44(%rbp),%ecx
imul   %rcx,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe16(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1273 <main+0xf3>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%esi
call   1070 <kernel_cpu_bound@plt>
mov    %rax,-0x18(%rbp)
jmp    12c3 <main+0x143>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde8(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12a9 <main+0x129>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%esi
mov    -0x44(%rbp),%edx
call   1060 <kernel_mem_bound@plt>
mov    %rax,-0x18(%rbp)
jmp    12be <main+0x13e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c3 <main+0x143>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cvtsi2sdq -0x38(%rbp),%xmm0
cvtsi2sdq -0x40(%rbp),%xmm1
movsd  0xd1c(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsi2sdq -0x28(%rbp),%xmm1
cvtsi2sdq -0x30(%rbp),%xmm2
movsd  0xd00(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
lea    0xd84(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     11aa <main+0x2a>
mov    (%rbx),%rsi
lea    0xe6c(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12b0 <main+0x130>
mov    $0x64,%r14d
cmp    $0x3,%edi
jne    11c5 <main+0x45>
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    1237 <main+0xb7>
mov    $0x800000,%edi
call   10a0 <sqrt@plt>
mov    %rax,%rbp
mov    %ebp,%edi
imul   %ebp,%edi
shl    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rbx),%rdi
lea    0xe6d(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     122b <main+0xab>
mov    0x8(%rbx),%rdi
lea    0xe5c(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     124f <main+0xcf>
mov    (%rbx),%rsi
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    125c <main+0xdc>
mov    %r14d,%edi
mov    %ebp,%esi
call   1070 <kernel_cpu_bound@plt>
jmp    125c <main+0xdc>
lea    0xe09(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
jmp    12b0 <main+0x130>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1060 <kernel_mem_bound@plt>
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
cvtsi2sdq 0x10(%rsp),%xmm1
cvtsi2sdq 0x8(%rsp),%xmm0
movsd  0xd80(%rip),%xmm2
divsd  %xmm2,%xmm0
cvtsi2sdq 0x20(%rsp),%xmm3
cvtsi2sdq 0x18(%rsp),%xmm4
addsd  %xmm1,%xmm0
divsd  %xmm2,%xmm4
addsd  %xmm3,%xmm4
subsd  %xmm4,%xmm0
lea    0xdee(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [63 x i8] c"Invalid parameters, USAGE: %s [mem|cpu] [trials, default=100]\0A\00"
@.str.1 = [31 x i8] c"Invalid number of trials = %d\0A\00"
@.str.2 = [4 x i8] c"cpu\00"
@.str.3 = [4 x i8] c"mem\00"
@.str.4 = [41 x i8] c"Invalid parameters, USAGE: %s [mem|cpu]\0A\00"
@.str.5 = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32*
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 0, i32* %3
br label %93
19: ; preds = %2
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 3
br i1 %21, label %22, label %33
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %11
%27 = load i32, i32* %11
%28 = icmp slt i32 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* %11
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %30)
store i32 -1, i32* %3
br label %93
32: ; preds = %22
br label %34
33: ; preds = %19
store i32 100, i32* %11
br label %34
34: ; preds = %33, %32
%35 = call i64 @sqrt(i32 8388608)
%36 = trunc i64 %35 to i32
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = zext i32 %37 to i64
%39 = mul i64 4, %38
%40 = load i32, i32* %10
%41 = zext i32 %40 to i64
%42 = mul i64 %39, %41
%43 = trunc i64 %42 to i32
%44 = call i64 @malloc(i32 %43)
%45 = inttoptr i64 %44 to i32*
store i32* %45, i32** %7
%46 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %34
%53 = load i32, i32* %11
%54 = load i32, i32* %10
%55 = call i64 @kernel_cpu_bound(i32 %53, i32 %54)
store i64 %55, i64* %6
br label %73
56: ; preds = %34
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %56
%63 = load i32*, i32** %7
%64 = load i32, i32* %11
%65 = load i32, i32* %10
%66 = call i64 @kernel_mem_bound(i32* %63, i32 %64, i32 %65)
store i64 %66, i64* %6
br label %72
67: ; preds = %56
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 0
%70 = load i8*, i8** %69
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %67, %62
br label %73
73: ; preds = %72, %52
%74 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%75 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%76 = load i64, i64* %75
%77 = sitofp i64 %76 to double
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%79 = load i64, i64* %78
%80 = sitofp i64 %79 to double
%81 = fdiv double %80, 1.000000e+06
%82 = fadd double %77, %81
%83 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%84 = load i64, i64* %83
%85 = sitofp i64 %84 to double
%86 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%87 = load i64, i64* %86
%88 = sitofp i64 %87 to double
%89 = fdiv double %88, 1.000000e+06
%90 = fadd double %85, %89
%91 = fsub double %82, %90
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double %91)
store i32 0, i32* %3
br label %93
93: ; preds = %73, %29, %14
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [63 x i8] c"Invalid parameters, USAGE: %s [mem|cpu] [trials, default=100]\0A\00"
@.str.1 = [31 x i8] c"Invalid number of trials = %d\0A\00"
@.str.2 = [4 x i8] c"cpu\00"
@.str.3 = [4 x i8] c"mem\00"
@.str.4 = [41 x i8] c"Invalid parameters, USAGE: %s [mem|cpu]\0A\00"
@.str.5 = [4 x i8] c"%f\0A\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 slt i32 %0, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %66
11: ; preds = %2
%12 = icmp eq i32 %0, 3
br i1 %12, label %13, label %20
13: ; preds = %11
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %66
20: ; preds = %11, %13
%21 = phi i32 [ %16, %13 ], [ 100, %11 ]
%22 = tail call i64 @sqrt(i32 8388608)
%23 = trunc i64 %22 to i32
%24 = and i64 %22, 4294967295
%25 = shl nuw nsw i64 %24, 2
%26 = mul i64 %25, %24
%27 = trunc i64 %26 to i32
%28 = tail call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i32*
%30 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = tail call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %20
%36 = tail call i64 @kernel_cpu_bound(i32 %21, i32 %23)
br label %46
37: ; preds = %20
%38 = load i8*, i8** %31
%39 = tail call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = tail call i64 @kernel_mem_bound(i32* %29, i32 %21, i32 %23)
br label %46
43: ; preds = %37
%44 = load i8*, i8** %1
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %41, %43, %35
%47 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%49 = load i64, i64* %48
%50 = sitofp i64 %49 to double
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%52 = load i64, i64* %51
%53 = sitofp i64 %52 to double
%54 = fdiv double %53, 1.000000e+06
%55 = fadd double %54, %50
%56 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%57 = load i64, i64* %56
%58 = sitofp i64 %57 to double
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%60 = load i64, i64* %59
%61 = sitofp i64 %60 to double
%62 = fdiv double %61, 1.000000e+06
%63 = fadd double %62, %58
%64 = fsub double %55, %63
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double %64)
br label %66
66: ; preds = %46, %18, %8
%67 = phi i32 [ 0, %8 ], [ -1, %18 ], [ 0, %46 ]
ret i32 %67
}