#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 *);
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);
  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    $0x1,%esi
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r8
call   1050 <RandomAccess_LCG@plt>
cmpl   $0x0,-0x34(%rbp)
jne    1296 <main+0x136>
movsd  -0x30(%rbp),%xmm0
lea    0xdf3(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12ab <main+0x14b>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%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   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    -0x2(%rbx),%eax
cmp    $0x3,%eax
jae    1242 <main+0xe2>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %rax,%r12
movabs $0xfffffffffff,%rsi
and    %rax,%rsi
shl    $0x14,%r12
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x4,%ebx
je     11d3 <main+0x73>
lea    0xe4d(%rip),%r14
cmp    $0x3,%ebx
jne    11e8 <main+0x88>
mov    0x10(%r15),%rdi
call   1070 <atoi@plt>
lea    0xe82(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11e8 <main+0x88>
mov    0x18(%r15),%r14
lea    0xe86(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
call   1050 <RandomAccess_LCG@plt>
cmpl   $0x0,0xc(%rsp)
je     1220 <main+0xc0>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1234 <main+0xd4>
movsd  0x10(%rsp),%xmm0
lea    0xe50(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%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 = call i32 @RandomAccess_LCG(i64 %55, i32 1, i8* %56, double* %9, i32* %10)
%58 = load i32, i32* %10
%59 = icmp ne i32 %58, 0
br i1 %59, label %63, label %60
60: ; preds = %54
%61 = load double, double* %9
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), double %61)
br label %66
63: ; preds = %54
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
br label %66
66: ; preds = %63, %60
%67 = load i32, i32* %3
ret i32 %67
}

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 = %22, %14, %29
%34 = 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 ]
%35 = call i32 @RandomAccess_LCG(i64 %19, i32 1, i8* %34, double* %3, i32* %4)
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load double, double* %3
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), double %39)
br label %44
41: ; preds = %33
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %41, %38
ret i32 0
}