#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int random();
void chooseWord(char **hWord, int *pWordLength) {
  FILE *pInputFile;
  int numWords;
  int chosen;
  int i = 0;
  pInputFile = fopen("../data/words.txt", "r");
  if (NULL == pInputFile) {
    printf("ERROR: File not found!\n");
    exit(EXIT_FAILURE);
  }
  fscanf(pInputFile, "%i\n", &numWords);
  chosen = 1 + (random() % numWords);
  for (i = 0; i < chosen; i++) {
    fscanf(pInputFile, "%i ", pWordLength);
    *hWord = (char *)malloc(sizeof(char) * *pWordLength);
    fscanf(pInputFile, "%s\n", *hWord);
    if (i != chosen - 1) {
      free((void *)*hWord);
    }
  }
  fclose(pInputFile);
}


x86 assembly (clang, -O0):
<chooseWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe62(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11d4 <chooseWord+0x54>
lea    0xe53(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe4d(%rip),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    $0x0,%al
call   1070 <random@plt>
cltd
idivl  -0x1c(%rbp)
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1289 <chooseWord+0x109>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1276 <chooseWord+0xf6>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
jmp    127b <chooseWord+0xfb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1202 <chooseWord+0x82>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chooseWord>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe68(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1246 <chooseWord+0xc6>
mov    %rax,%rbx
lea    0xe5d(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fscanf@plt>
xor    %eax,%eax
call   1070 <random@plt>
cltd
idivl  0x4(%rsp)
test   %edx,%edx
js     122f <chooseWord+0xaf>
mov    %edx,%ebp
add    $0x1,%ebp
lea    0xe36(%rip),%r12
lea    0xe33(%rip),%r13
jmp    11f5 <chooseWord+0x75>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
je     122f <chooseWord+0xaf>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    (%r15),%edi
call   1080 <malloc@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
cmp    $0x1,%ebp
je     11f0 <chooseWord+0x70>
mov    (%r14),%rdi
call   1030 <free@plt>
jmp    11f0 <chooseWord+0x70>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd3(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"../data/words.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"ERROR: File not found!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%i\0A\00"
@.str.4 = [4 x i8] c"%i \00"
@.str.5 = [4 x i8] c"%s\0A\00"
define void @chooseWord(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %3
store i32* %1, i32** %4
store i32 0, i32* %8
%9 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* null, %10
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32*, i32** %5
%18 = call i32 (i32*, i8*, ...) @fscanf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%19 = call i32 (...) @random()
%20 = load i32, i32* %6
%21 = srem i32 %19, %20
%22 = add nsw i32 1, %21
store i32 %22, i32* %7
store i32 0, i32* %8
br label %23
23: ; preds = %52, %16
%24 = load i32, i32* %8
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %55
27: ; preds = %23
%28 = load i32*, i32** %5
%29 = load i32*, i32** %4
%30 = call i32 (i32*, i8*, ...) @fscanf(i32* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %29)
%31 = load i32*, i32** %4
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = mul i64 1, %33
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
%38 = load i8**, i8*** %3
store i8* %37, i8** %38
%39 = load i32*, i32** %5
%40 = load i8**, i8*** %3
%41 = load i8*, i8** %40
%42 = call i32 (i32*, i8*, ...) @fscanf(i32* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = load i32, i32* %8
%44 = load i32, i32* %7
%45 = sub nsw i32 %44, 1
%46 = icmp ne i32 %43, %45
br i1 %46, label %47, label %51
47: ; preds = %27
%48 = load i8**, i8*** %3
%49 = load i8*, i8** %48
%50 = call i32 @free(i8* %49)
br label %51
51: ; preds = %47, %27
br label %52
52: ; preds = %51
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %23
55: ; preds = %23
%56 = load i32*, i32** %5
%57 = call i32 @fclose(i32* %56)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"../data/words.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%i\0A\00"
@.str.4 = [4 x i8] c"%i \00"
@.str.5 = [4 x i8] c"%s\0A\00"
@str = [23 x i8] c"ERROR: File not found!\00"
define void @chooseWord(i8** nocapture %0, i32* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = call i32 (i32*, i8*, ...) @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%13 = call i32 (...) @random()
%14 = load i32, i32* %3
%15 = srem i32 %13, %14
%16 = icmp slt i32 %15, 0
br i1 %16, label %31, label %17
17: ; preds = %11, %28
%18 = phi i32 [ %29, %28 ], [ 0, %11 ]
%19 = call i32 (i32*, i8*, ...) @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%20 = load i32, i32* %1
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %0
%23 = call i32 (i32*, i8*, ...) @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%24 = icmp eq i32 %18, %15
br i1 %24, label %28, label %25
25: ; preds = %17
%26 = load i8*, i8** %0
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %17, %25
%29 = add nuw i32 %18, 1
%30 = icmp eq i32 %18, %15
br i1 %30, label %31, label %17
31: ; preds = %28, %11
%32 = call i32 @fclose(i32* %5)
ret void
}