#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, char *);
int genKey();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int diceNumList[7776];
  char diceWordList[5][11];
  int i, x, c, keyVal, words;
  i = x = c = keyVal = 0;
  FILE *infile = NULL;
  infile = fopen(argv[1], "r");
  sscanf(argv[2], "%d", &words);
  if (infile == NULL || words <= 0) {
    printf("Usage: ./diceware <input file.txt> <# of words to generate>\n");
    return (1);
  }
  for (i = 0; i < 7776; i++) {
    fscanf(infile, "%d %s", &diceNumList[i], (char *)&diceWordList[i]);
  }
  srand(time(NULL));
  printf("Number of words requested was %d\n", words);
  printf("Passphrase: ");
  for (c = 0; c < words; c++) {
    keyVal = genKey();
    for (x = 0; x < 7776; x++) {
      if (diceNumList[x] == keyVal) {
        printf(" %s ", diceWordList[x]);
      }
    }
  }
  printf("\n");
  fclose(infile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x79f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x79e0(%rbp)
movl   $0x0,-0x79dc(%rbp)
movl   $0x0,-0x79d8(%rbp)
movl   $0x0,-0x79d4(%rbp)
movq   $0x0,-0x79f0(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe25(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x79f0(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0c(%rip),%rsi
lea    -0x79e4(%rbp),%rdx
call   1080 <sscanf@plt>
cmpq   $0x0,-0x79f0(%rbp)
je     121d <main+0x9d>
cmpl   $0x0,-0x79e4(%rbp)
jg     1237 <main+0xb7>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a7 <main+0x227>
movl   $0x0,-0x79d4(%rbp)
cmpl   $0x1e60,-0x79d4(%rbp)
jge    12a2 <main+0x122>
mov    -0x79f0(%rbp),%rdi
movslq -0x79d4(%rbp),%rax
lea    -0x7990(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
movslq -0x79d4(%rbp),%rax
lea    -0x79d0(%rbp),%rcx
imul   $0xb,%rax,%rax
add    %rax,%rcx
lea    0xdb9(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x79d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x79d4(%rbp)
jmp    1241 <main+0xc1>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x79e4(%rbp),%esi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x79dc(%rbp)
mov    -0x79dc(%rbp),%eax
cmp    -0x79e4(%rbp),%eax
jge    1386 <main+0x206>
mov    $0x0,%al
call   1090 <genKey@plt>
mov    %eax,-0x79e0(%rbp)
movl   $0x0,-0x79d8(%rbp)
cmpl   $0x1e60,-0x79d8(%rbp)
jge    136d <main+0x1ed>
movslq -0x79d8(%rbp),%rax
mov    -0x7990(%rbp,%rax,4),%eax
cmp    -0x79e0(%rbp),%eax
jne    1354 <main+0x1d4>
movslq -0x79d8(%rbp),%rax
lea    -0x79d0(%rbp),%rsi
imul   $0xb,%rax,%rax
add    %rax,%rsi
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1359 <main+0x1d9>
mov    -0x79d8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x79d8(%rbp)
jmp    1307 <main+0x187>
jmp    1372 <main+0x1f2>
mov    -0x79dc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x79dc(%rbp)
jmp    12de <main+0x15e>
lea    0xcb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x79f0(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x79f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x79d8,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe41(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe30(%rip),%rsi
lea    0xc(%rsp),%rdx
call   10a0 <sscanf@plt>
test   %r15,%r15
je     12b7 <main+0x117>
cmpl   $0x0,0xc(%rsp)
jle    12b7 <main+0x117>
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
lea    0xe07(%rip),%r14
xchg   %ax,%ax
lea    (%rsp,%rbp,1),%rdx
add    $0x50,%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rcx
call   1070 <fscanf@plt>
add    $0x4,%rbp
add    $0xb,%rbx
cmp    $0x7980,%rbp
jne    1200 <main+0x60>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
mov    0xc(%rsp),%esi
lea    0xdcb(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xddf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    12ca <main+0x12a>
lea    0xdd7(%rip),%r12
xor    %r14d,%r14d
jmp    127b <main+0xdb>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
cmp    0xc(%rsp),%r14d
jge    12ca <main+0x12a>
xor    %eax,%eax
call   10b0 <genKey@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
xor    %r13d,%r13d
jmp    12a1 <main+0x101>
xchg   %ax,%ax
add    $0x1,%r13
add    $0xb,%rbx
cmp    $0x1e60,%r13
je     1270 <main+0xd0>
cmp    %ebp,0x50(%rsp,%r13,4)
jne    1290 <main+0xf0>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1290 <main+0xf0>
lea    0xd81(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    12de <main+0x13e>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x79d8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [61 x i8] c"Usage: ./diceware <input file.txt> <# of words to generate>\0A\00"
@.str.3 = [6 x i8] c"%d %s\00"
@.str.4 = [34 x i8] c"Number of words requested was %d\0A\00"
@.str.5 = [13 x i8] c"Passphrase: \00"
@.str.6 = [5 x i8] c" %s \00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [7776 x i32]
%7 = alloca [5 x [11 x i8]]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
store i32 0, i32* %10
store i32 0, i32* %9
store i32 0, i32* %8
store i32* null, i32** %13
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %13
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %12)
%22 = load i32*, i32** %13
%23 = icmp eq i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %2
%25 = load i32, i32* %12
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24, %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %86
29: ; preds = %24
store i32 0, i32* %8
br label %30
30: ; preds = %43, %29
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 7776
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load i32*, i32** %13
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [7776 x i32], [7776 x i32]* %6, i64 0, i64 %36
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [5 x [11 x i8]], [5 x [11 x i8]]* %7, i64 0, i64 %39
%41 = bitcast [11 x i8]* %40 to i8*
%42 = call i32 @fscanf(i32* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %37, i8* %41)
br label %43
43: ; preds = %33
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %30
46: ; preds = %30
%47 = call i32 @time(i32* null)
%48 = call i32 @srand(i32 %47)
%49 = load i32, i32* %12
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %10
br label %52
52: ; preds = %79, %46
%53 = load i32, i32* %10
%54 = load i32, i32* %12
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %82
56: ; preds = %52
%57 = call i32 (...) @genKey()
store i32 %57, i32* %11
store i32 0, i32* %9
br label %58
58: ; preds = %75, %56
%59 = load i32, i32* %9
%60 = icmp slt i32 %59, 7776
br i1 %60, label %61, label %78
61: ; preds = %58
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [7776 x i32], [7776 x i32]* %6, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = load i32, i32* %11
%67 = icmp eq i32 %65, %66
br i1 %67, label %68, label %74
68: ; preds = %61
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [5 x [11 x i8]], [5 x [11 x i8]]* %7, i64 0, i64 %70
%72 = getelementptr inbounds [11 x i8], [11 x i8]* %71, i64 0, i64 0
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %68, %61
br label %75
75: ; preds = %74
%76 = load i32, i32* %9
%77 = add nsw i32 %76, 1
store i32 %77, i32* %9
br label %58
78: ; preds = %58
br label %79
79: ; preds = %78
%80 = load i32, i32* %10
%81 = add nsw i32 %80, 1
store i32 %81, i32* %10
br label %52
82: ; preds = %52
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%84 = load i32*, i32** %13
%85 = call i32 @fclose(i32* %84)
store i32 0, i32* %3
br label %86
86: ; preds = %82, %27
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [6 x i8] c"%d %s\00"
@.str.4 = [34 x i8] c"Number of words requested was %d\0A\00"
@.str.5 = [13 x i8] c"Passphrase: \00"
@.str.6 = [5 x i8] c" %s \00"
@str = [60 x i8] c"Usage: ./diceware <input file.txt> <# of words to generate>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [7776 x i32]
%4 = alloca [5 x [11 x i8]]
%5 = alloca i32
%6 = bitcast [7776 x i32]* %3 to i8*
%7 = getelementptr inbounds [5 x [11 x i8]], [5 x [11 x i8]]* %4, i64 0, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%15 = icmp eq i32* %11, null
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 1
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
br label %57
21: ; preds = %2, %21
%22 = phi i64 [ %26, %21 ], [ 0, %2 ]
%23 = getelementptr inbounds [7776 x i32], [7776 x i32]* %3, i64 0, i64 %22
%24 = getelementptr inbounds [5 x [11 x i8]], [5 x [11 x i8]]* %4, i64 0, i64 %22, i64 0
%25 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %23, i8* %24)
%26 = add nuw nsw i64 %22, 1
%27 = icmp eq i64 %26, 7776
br i1 %27, label %28, label %21
28: ; preds = %21
%29 = call i32 @time(i32* null)
%30 = call i32 @srand(i32 %29)
%31 = load i32, i32* %5
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* %5
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %54
36: ; preds = %28, %50
%37 = phi i32 [ %51, %50 ], [ 0, %28 ]
%38 = call i32 (...) @genKey()
br label %39
39: ; preds = %36, %47
%40 = phi i64 [ 0, %36 ], [ %48, %47 ]
%41 = getelementptr inbounds [7776 x i32], [7776 x i32]* %3, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = icmp eq i32 %42, %38
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = getelementptr inbounds [5 x [11 x i8]], [5 x [11 x i8]]* %4, i64 0, i64 %40, i64 0
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %39, %44
%48 = add nuw nsw i64 %40, 1
%49 = icmp eq i64 %48, 7776
br i1 %49, label %50, label %39
50: ; preds = %47
%51 = add nuw nsw i32 %37, 1
%52 = load i32, i32* %5
%53 = icmp slt i32 %51, %52
br i1 %53, label %36, label %54
54: ; preds = %50, %28
%55 = call i32 @putchar(i32 10)
%56 = call i32 @fclose(i32* %11)
br label %57
57: ; preds = %54, %19
%58 = phi i32 [ 1, %19 ], [ 0, %54 ]
ret i32 %58
}