#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int rand();
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *getWord(char *filename, int wordCount, char *buffer) {
  FILE *fp;
  char line[100];
  int index, count;
  index = rand() % wordCount;
  if ((fp = fopen(filename, "r"))) {
    count = 0;
    while (count <= index && fgets(line, 100, fp)) {
      if (strlen(line) <= 1)
        continue;
      line[strlen(line) - 1] = '\0';
      ++count;
    }
  } else {
    printf("Missing file %s\n", filename);
    exit(1);
  }
  fclose(fp);
  strcpy(buffer, line);
  return buffer;
}


x86 assembly (clang, -O0):
<getWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x94(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     126a <getWord+0xea>
movl   $0x0,-0x98(%rbp)
mov    -0x98(%rbp),%ecx
xor    %eax,%eax
cmp    -0x94(%rbp),%ecx
mov    %al,-0x99(%rbp)
jg     120b <getWord+0x8b>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x99(%rbp)
mov    -0x99(%rbp),%al
test   $0x1,%al
jne    121e <getWord+0x9e>
jmp    1265 <getWord+0xe5>
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jg     1238 <getWord+0xb8>
jmp    11cf <getWord+0x4f>
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x90(%rbp,%rax,1)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    11cf <getWord+0x4f>
jmp    1284 <getWord+0x104>
mov    -0x8(%rbp),%rsi
lea    0xd8d(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getWord>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%rbx
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %eax,%ebp
lea    0xe5b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     122e <getWord+0xae>
mov    %rax,%r15
mov    %ebp,%eax
cltd
idiv   %r12d
mov    $0xffffffff,%r12d
test   %edx,%edx
cmovns %edx,%r12d
js     120b <getWord+0x8b>
xor    %ebp,%ebp
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     120b <getWord+0x8b>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     11d0 <getWord+0x50>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0x1(%rbp),%eax
cmp    %r12d,%ebp
mov    %eax,%ebp
jne    11d0 <getWord+0x50>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdcd(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [17 x i8] c"Missing file %s\0A\00"
define i8* @getWord(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [100 x i8]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = call i32 (...) @rand()
%12 = load i32, i32* %5
%13 = srem i32 %11, %12
store i32 %13, i32* %9
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %43
17: ; preds = %3
store i32 0, i32* %10
br label %18
18: ; preds = %34, %33, %17
%19 = load i32, i32* %10
%20 = load i32, i32* %9
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%24 = load i32*, i32** %7
%25 = call i64 @fgets(i8* %23, i32 100, i32* %24)
%26 = icmp ne i64 %25, 0
br label %27
27: ; preds = %22, %18
%28 = phi i1 [ false, %18 ], [ %26, %22 ]
br i1 %28, label %29, label %42
29: ; preds = %27
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = icmp sle i32 %31, 1
br i1 %32, label %33, label %34
33: ; preds = %29
br label %18
34: ; preds = %29
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %38
store i8 0, i8* %39
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %18
42: ; preds = %27
br label %47
43: ; preds = %3
%44 = load i8*, i8** %4
%45 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %42
%48 = load i32*, i32** %7
%49 = call i32 @fclose(i32* %48)
%50 = load i8*, i8** %6
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%52 = call i32 @strcpy(i8* %50, i8* %51)
%53 = load i8*, i8** %6
ret i8* %53
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [17 x i8] c"Missing file %s\0A\00"
define i8* @getWord(i8* %0, i32 %1, i8* returned %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = tail call i32 (...) @rand()
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %28, label %9
9: ; preds = %3
%10 = srem i32 %6, %1
%11 = call i32 @llvm.smax.i32(i32 %10, i32 -1)
%12 = icmp slt i32 %10, 0
br i1 %12, label %31, label %13
13: ; preds = %9, %21
%14 = phi i32 [ %26, %21 ], [ 0, %9 ]
br label %15
15: ; preds = %13, %18
%16 = call i64 @fgets(i8* %5, i32 100, i32* %7)
%17 = icmp eq i64 %16, 0
br i1 %17, label %31, label %18
18: ; preds = %15
%19 = call i32 @strlen(i8* %5)
%20 = icmp slt i32 %19, 2
br i1 %20, label %15, label %21
21: ; preds = %18
%22 = call i32 @strlen(i8* %5)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %24
store i8 0, i8* %25
%26 = add nuw i32 %14, 1
%27 = icmp eq i32 %14, %11
br i1 %27, label %31, label %13
28: ; preds = %3
%29 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %21, %15, %9
%32 = call i32 @fclose(i32* %7)
%33 = call i32 @strcpy(i8* %2, i8* %5)
ret i8* %2
}