#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 /*<<< orphan*/ RandomAccess_LCG(unsigned long, int, char *, double *, int *,
                                    int);
void *atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ print_help_msg();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  unsigned long totalMemSize = 0;
  char *outFileName = "gupsout";
  int numThreads = 1;
  double GUPS;
  int faillure;
  if (argc != 2 && argc != 3 && argc != 4) {
    fprintf(stderr, "Error: invalid input parameters\n");
    print_help_msg();
    exit(-8);
  }
  totalMemSize = atoi(argv[1]);
  totalMemSize <<= 20;
  printf("$$ Get total memory size:%lu MB\n", totalMemSize >> 20);
  if (argc == 3) {
    numThreads = atoi(argv[2]);
    printf("$$ Get num of threads:%d\n", numThreads);
  }
  if (argc == 4) {
    outFileName = argv[3];
    printf("$$ Get Out File Name:%s\n", outFileName);
  }
  RandomAccess_LCG(totalMemSize, 1, outFileName, &GUPS, &faillure, numThreads);
  if (!faillure) {
    printf("$$ Run RandomAccess Successfully, GUPS=%.6f\n", GUPS);
  } else {
    fprintf(stderr, "## Run RandomAccess Failed\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe7b(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d4 <main+0x74>
cmpl   $0x3,-0x8(%rbp)
je     11d4 <main+0x74>
cmpl   $0x4,-0x8(%rbp)
je     11d4 <main+0x74>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1060 <print_help_msg@plt>
mov    $0xfffffff8,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
shr    $0x14,%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
jne    1232 <main+0xd2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x4,-0x8(%rbp)
jne    125a <main+0xfa>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%r9d
mov    $0x1,%esi
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r8
call   1050 <RandomAccess_LCG@plt>
cmpl   $0x0,-0x34(%rbp)
jne    129a <main+0x13a>
movsd  -0x30(%rbp),%xmm0
lea    0xdef(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12af <main+0x14f>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    -0x2(%rbx),%eax
cmp    $0x3,%eax
jae    1255 <main+0xf5>
mov    %rsi,%r12
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %rax,%r13
movabs $0xfffffffffff,%rsi
and    %rax,%rsi
shl    $0x14,%r13
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%r14d
cmp    $0x4,%ebx
je     11e0 <main+0x80>
lea    0xe45(%rip),%r15
cmp    $0x3,%ebx
jne    11f6 <main+0x96>
mov    0x10(%r12),%rdi
call   1070 <atoi@plt>
mov    %rax,%r14
lea    0xe76(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11f6 <main+0x96>
mov    0x18(%r12),%r15
lea    0xe78(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r14d,%r9d
call   1050 <RandomAccess_LCG@plt>
cmpl   $0x0,0x4(%rsp)
je     1231 <main+0xd1>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1245 <main+0xe5>
movsd  0x8(%rsp),%xmm0
lea    0xe3f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1060 <print_help_msg@plt>
mov    $0xfffffff8,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"gupsout\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Error: invalid input parameters\0A\00"
@.str.2 = [33 x i8] c"$$ Get total memory size:%lu MB\0A\00"
@.str.3 = [26 x i8] c"$$ Get num of threads:%d\0A\00"
@.str.4 = [25 x i8] c"$$ Get Out File Name:%s\0A\00"
@.str.5 = [45 x i8] c"$$ Run RandomAccess Successfully, GUPS=%.6f\0A\00"
@.str.6 = [28 x i8] c"## Run RandomAccess Failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 1, i32* %8
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %24
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 4
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 (...) @print_help_msg()
%23 = call i32 @exit(i32 -8)
unreachable
24: ; preds = %16, %13, %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i8* @atoi(i8* %27)
%29 = ptrtoint i8* %28 to i64
store i64 %29, i64* %6
%30 = load i64, i64* %6
%31 = shl i64 %30, 20
store i64 %31, i64* %6
%32 = load i64, i64* %6
%33 = lshr i64 %32, 20
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i64 %33)
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 3
br i1 %36, label %37, label %45
37: ; preds = %24
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i8* @atoi(i8* %40)
%42 = ptrtoint i8* %41 to i32
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %37, %24
%46 = load i32, i32* %4
%47 = icmp eq i32 %46, 4
br i1 %47, label %48, label %54
48: ; preds = %45
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
store i8* %51, i8** %7
%52 = load i8*, i8** %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %52)
br label %54
54: ; preds = %48, %45
%55 = load i64, i64* %6
%56 = load i8*, i8** %7
%57 = load i32, i32* %8
%58 = call i32 @RandomAccess_LCG(i64 %55, i32 1, i8* %56, double* %9, i32* %10, i32 %57)
%59 = load i32, i32* %10
%60 = icmp ne i32 %59, 0
br i1 %60, label %64, label %61
61: ; preds = %54
%62 = load double, double* %9
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), double %62)
br label %67
64: ; preds = %54
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
br label %67
67: ; preds = %64, %61
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str = [8 x i8] c"gupsout\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Error: invalid input parameters\0A\00"
@.str.2 = [33 x i8] c"$$ Get total memory size:%lu MB\0A\00"
@.str.3 = [26 x i8] c"$$ Get num of threads:%d\0A\00"
@.str.4 = [25 x i8] c"$$ Get Out File Name:%s\0A\00"
@.str.5 = [45 x i8] c"$$ Run RandomAccess Successfully, GUPS=%.6f\0A\00"
@.str.6 = [28 x i8] c"## Run RandomAccess Failed\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = alloca i32
%5 = bitcast double* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = add i32 %0, -2
%8 = icmp ult i32 %7, 3
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 (...) @print_help_msg()
%13 = tail call i32 @exit(i32 -8)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i8* @atoi(i8* %16)
%18 = ptrtoint i8* %17 to i64
%19 = shl i64 %18, 20
%20 = and i64 %18, 17592186044415
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i64 %20)
switch i32 %0, label %33 [
i32 3, label %22
i32 4, label %29
]
22: ; preds = %14
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i8* @atoi(i8* %24)
%26 = ptrtoint i8* %25 to i64
%27 = trunc i64 %26 to i32
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br label %33
29: ; preds = %14
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %14, %22, %29
%34 = phi i32 [ 1, %29 ], [ %27, %22 ], [ 1, %14 ]
%35 = phi i8* [ %31, %29 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %22 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %14 ]
%36 = call i32 @RandomAccess_LCG(i64 %19, i32 1, i8* %35, double* %3, i32* %4, i32 %34)
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = load double, double* %3
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), double %40)
br label %45
42: ; preds = %33
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
br label %45
45: ; preds = %42, %39
ret i32 0
}