#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 */
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int atoi(char *);
int *calloc(int, int);
int /*<<< orphan*/ dtp_get_cpu();
int /*<<< orphan*/ dtp_set_cpu(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc != 3) {
    fprintf(stderr, "usage: %s <cpu> <memory>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  int i, j;
  int cpu = atoi(argv[1]);
  srand(time(NULL));
  uint64_t memory = atoi(argv[2]);
  memory = memory * 1024 * 1024 / 4;
  int *x = calloc(sizeof(int), memory);
  dtp_set_cpu(cpu);
  dtp_get_cpu();
  while (1) {
    for (i = 0; i < memory; i++) {
      if (i != 0)
        x[i] = rand();
      else
        x[i] = rand() * x[i - 1];
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11da <main+0x4a>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
mov    $0x4,%edi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   10a0 <dtp_set_cpu@plt>
mov    $0x0,%al
call   1050 <dtp_get_cpu@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12ac <main+0x11c>
cmpl   $0x0,-0x14(%rbp)
je     1274 <main+0xe4>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1299 <main+0x109>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
imul   (%rax,%rcx,4),%edx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    129e <main+0x10e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1245 <main+0xb5>
jmp    123e <main+0xae>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1237 <main+0xa7>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r12d
mov    %eax,%r15d
shl    $0x12,%r15d
mov    $0x4,%edi
mov    %r15d,%esi
call   1040 <calloc@plt>
mov    %rax,%r13
mov    %r14d,%edi
call   10a0 <dtp_set_cpu@plt>
xor    %eax,%eax
call   1050 <dtp_get_cpu@plt>
cmp    $0x2,%r15d
mov    $0x1,%ebp
cmovge %r15d,%ebp
test   %r12d,%r12d
jle    1200 <main+0x70>
xor    %eax,%eax
call   10b0 <rand@plt>
imul   -0x4(%r13),%eax
mov    %eax,0x0(%r13)
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <rand@plt>
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1220 <main+0x90>
jmp    1200 <main+0x70>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdb6(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"usage: %s <cpu> <memory>\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %8
%26 = call i32 @time(i32* null)
%27 = call i32 @srand(i32 %26)
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = mul nsw i32 %32, 1024
%34 = mul nsw i32 %33, 1024
%35 = sdiv i32 %34, 4
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = call i32* @calloc(i32 4, i32 %36)
store i32* %37, i32** %10
%38 = load i32, i32* %8
%39 = call i32 @dtp_set_cpu(i32 %38)
%40 = call i32 (...) @dtp_get_cpu()
br label %41
41: ; preds = %21, %72
store i32 0, i32* %6
br label %42
42: ; preds = %69, %41
%43 = load i32, i32* %6
%44 = load i32, i32* %9
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %72
46: ; preds = %42
%47 = load i32, i32* %6
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %46
%50 = call i32 (...) @rand()
%51 = load i32*, i32** %10
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
store i32 %50, i32* %54
br label %68
55: ; preds = %46
%56 = call i32 (...) @rand()
%57 = load i32*, i32** %10
%58 = load i32, i32* %6
%59 = sub nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %57, i64 %60
%62 = load i32, i32* %61
%63 = mul nsw i32 %56, %62
%64 = load i32*, i32** %10
%65 = load i32, i32* %6
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
store i32 %63, i32* %67
br label %68
68: ; preds = %55, %49
br label %69
69: ; preds = %68
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
store i32 %71, i32* %6
br label %42
72: ; preds = %42
br label %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"usage: %s <cpu> <memory>\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = tail call i32 @time(i32* null)
%15 = tail call i32 @srand(i32 %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = shl nsw i32 %18, 18
%20 = tail call i32* @calloc(i32 4, i32 %19)
%21 = tail call i32 @dtp_set_cpu(i32 %13)
%22 = tail call i32 (...) @dtp_get_cpu()
%23 = icmp sgt i32 %18, 0
%24 = getelementptr inbounds i32, i32* %20, i64 -1
%25 = call i32 @llvm.smax.i32(i32 %19, i32 1)
%26 = zext i32 %25 to i64
br label %27
27: ; preds = %28, %10
br i1 %23, label %29, label %28
28: ; preds = %33, %27
br label %27
29: ; preds = %27
%30 = tail call i32 (...) @rand()
%31 = load i32, i32* %24
%32 = mul nsw i32 %31, %30
store i32 %32, i32* %20
br label %33
33: ; preds = %29, %33
%34 = phi i64 [ 1, %29 ], [ %37, %33 ]
%35 = tail call i32 (...) @rand()
%36 = getelementptr inbounds i32, i32* %20, i64 %34
store i32 %35, i32* %36
%37 = add nuw nsw i64 %34, 1
%38 = icmp eq i64 %37, %26
br i1 %38, label %28, label %33
}