#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 scalar_t__ int16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fwrite(scalar_t__ *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rand();
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int i;
  int16_t *userkey;
  FILE *out;
  if (argc != 2) {
    printf("usage: %s <output-file>\n", argv[0]);
    return 1;
  }
  out = fopen(argv[1], "w");
  if (out == NULL) {
    fprintf(stderr, "Error opening %s for writing\n", argv[1]);
    return 1;
  }
  userkey = (int16_t *)malloc(sizeof(int16_t) * 8);
  if (userkey == NULL) {
    fprintf(stderr, "Error allocating userkey\n");
    return 1;
  }
  srand(3899);
  for (i = 0; i < 8; i++) {
    userkey[i] = (int16_t)rand();
  }
  if (fwrite(userkey, sizeof(int16_t), 8, out) != 8) {
    fprintf(stderr, "Error writing user key to %s\n", argv[1]);
    return 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   $0x2,-0x8(%rbp)
je     11af <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c7 <main+0x157>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11fd <main+0x8d>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c7 <main+0x157>
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1239 <main+0xc9>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c7 <main+0x157>
mov    $0xf3b,%edi
call   1040 <srand@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    1278 <main+0x108>
mov    $0x0,%al
call   1090 <rand@plt>
movslq %eax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    124a <main+0xda>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x8,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
cmp    $0x8,%eax
je     12c0 <main+0x150>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c7 <main+0x157>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x2,%edi
jne    1258 <main+0xe8>
mov    0x8(%r15),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1269 <main+0xf9>
mov    %rax,%r14
mov    $0x40,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1286 <main+0x116>
mov    %rax,%rbx
mov    $0xf3b,%edi
call   1040 <srand@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1090 <rand@plt>
cltq
mov    %rax,(%rbx)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
mov    %rax,0x8(%rbx)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
mov    %rax,0x10(%rbx)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
mov    %rax,0x18(%rbx)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
mov    %rax,0x20(%rbx)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
mov    %rax,0x28(%rbx)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
mov    %rax,0x30(%rbx)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
mov    %rax,0x38(%rbx)
mov    %rbx,%rdi
mov    $0x8,%esi
mov    $0x8,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
cmp    $0x8,%eax
je     12a2 <main+0x132>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xdfd(%rip),%rsi
jmp    127d <main+0x10d>
mov    (%r15),%rsi
lea    0xd9e(%rip),%rdi
call   1030 <printf@plt>
jmp    129d <main+0x12d>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xd9e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    129d <main+0x12d>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"usage: %s <output-file>\0A\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Error opening %s for writing\0A\00"
@.str.3 = [26 x i8] c"Error allocating userkey\0A\00"
@.str.4 = [30 x i8] c"Error writing user key to %s\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 i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %64
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %8
%21 = load i32*, i32** %8
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 1, i32* %3
br label %64
29: ; preds = %16
%30 = call i64 @malloc(i32 64)
%31 = inttoptr i64 %30 to i64*
store i64* %31, i64** %7
%32 = load i64*, i64** %7
%33 = icmp eq i64* %32, null
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %64
37: ; preds = %29
%38 = call i32 @srand(i32 3899)
store i32 0, i32* %6
br label %39
39: ; preds = %49, %37
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 8
br i1 %41, label %42, label %52
42: ; preds = %39
%43 = call i32 (...) @rand()
%44 = sext i32 %43 to i64
%45 = load i64*, i64** %7
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i64, i64* %45, i64 %47
store i64 %44, i64* %48
br label %49
49: ; preds = %42
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %39
52: ; preds = %39
%53 = load i64*, i64** %7
%54 = load i32*, i32** %8
%55 = call i32 @fwrite(i64* %53, i32 8, i32 8, i32* %54)
%56 = icmp ne i32 %55, 8
br i1 %56, label %57, label %63
57: ; preds = %52
%58 = load i32, i32* @stderr
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %61)
store i32 1, i32* %3
br label %64
63: ; preds = %52
store i32 0, i32* %3
br label %64
64: ; preds = %63, %57, %34, %23, %11
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [25 x i8] c"usage: %s <output-file>\0A\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Error opening %s for writing\0A\00"
@.str.3 = [26 x i8] c"Error allocating userkey\0A\00"
@.str.4 = [30 x i8] c"Error writing user key to %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %54
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %8
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %54
16: ; preds = %7
%17 = tail call i64 @malloc(i32 64)
%18 = inttoptr i64 %17 to i64*
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %54
23: ; preds = %16
%24 = tail call i32 @srand(i32 3899)
%25 = tail call i32 (...) @rand()
%26 = sext i32 %25 to i64
store i64 %26, i64* %18
%27 = tail call i32 (...) @rand()
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i64, i64* %18, i64 1
store i64 %28, i64* %29
%30 = tail call i32 (...) @rand()
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i64, i64* %18, i64 2
store i64 %31, i64* %32
%33 = tail call i32 (...) @rand()
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i64, i64* %18, i64 3
store i64 %34, i64* %35
%36 = tail call i32 (...) @rand()
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i64, i64* %18, i64 4
store i64 %37, i64* %38
%39 = tail call i32 (...) @rand()
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i64, i64* %18, i64 5
store i64 %40, i64* %41
%42 = tail call i32 (...) @rand()
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i64, i64* %18, i64 6
store i64 %43, i64* %44
%45 = tail call i32 (...) @rand()
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i64, i64* %18, i64 7
store i64 %46, i64* %47
%48 = tail call i32 @fwrite(i64* %18, i32 8, i32 8, i32* %10)
%49 = icmp eq i32 %48, 8
br i1 %49, label %54, label %50
50: ; preds = %23
%51 = load i32, i32* @stderr
%52 = load i8*, i8** %8
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %52)
br label %54
54: ; preds = %23, %50, %20, %12, %4
%55 = phi i32 [ 1, %4 ], [ 1, %12 ], [ 1, %20 ], [ 1, %50 ], [ 0, %23 ]
ret i32 %55
}