#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int rand_int(int /*<<< orphan*/, int);
int strlen(char *);
void gen_rnd_word(char *word, int *ln) {
  FILE *f;
  int i = 0, ptr = 0, count = 0, rnd = 0;
  f = fopen("./res/vcwords.txt", "r");
  if (f == NULL) {
    printf("Wordlist (path: %s) is missing!\n", "./res/vcwords.txt");
    exit(EXIT_FAILURE);
  }
  while (fgets(word, 128, f)) {
    ++count;
  }
  rnd = rand_int(0, count);
  *ln = rnd;
  f = fopen("./res/vcwords.txt", "r");
  while (fgets(word, 128, f)) {
    ++ptr;
    if (ptr != rnd) {
      continue;
    }
    for (i = 0; i < strlen(word); i++) {
      if (word[i] == '\n') {
        word[i] = 0;
      }
    }
    printf("Chosen a word!\n");
    break;
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<gen_rnd_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xe5d(%rip),%rdi
lea    0xe68(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e1 <gen_rnd_word+0x71>
lea    0xe4f(%rip),%rdi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11e6 <gen_rnd_word+0x76>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1210 <gen_rnd_word+0xa0>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e6 <gen_rnd_word+0x76>
mov    -0x24(%rbp),%esi
xor    %edi,%edi
call   1070 <rand_int@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    0xdd3(%rip),%rdi
lea    0xdde(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12d8 <gen_rnd_word+0x168>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     1273 <gen_rnd_word+0x103>
jmp    123d <gen_rnd_word+0xcd>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    12ca <gen_rnd_word+0x15a>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    12b7 <gen_rnd_word+0x147>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12bc <gen_rnd_word+0x14c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    127a <gen_rnd_word+0x10a>
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_rnd_word>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe6c(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     126f <gen_rnd_word+0xef>
mov    %rax,%rbp
mov    $0xffffffff,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1070 <fgets@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    11c0 <gen_rnd_word+0x40>
xor    %edi,%edi
mov    %ebx,%esi
call   1080 <rand_int@plt>
mov    %eax,%ebp
mov    %eax,(%r14)
lea    0xe13(%rip),%rdi
lea    0xe1e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     125d <gen_rnd_word+0xdd>
add    $0xffffffff,%ebp
jne    1200 <gen_rnd_word+0x80>
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1251 <gen_rnd_word+0xd1>
xor    %ebx,%ebx
jmp    1243 <gen_rnd_word+0xc3>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1251 <gen_rnd_word+0xd1>
cmpb   $0xa,(%r15,%rbx,1)
jne    1230 <gen_rnd_word+0xb0>
movb   $0x0,(%r15,%rbx,1)
jmp    1230 <gen_rnd_word+0xb0>
lea    0xddd(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xd9e(%rip),%rdi
lea    0xd83(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"./res/vcwords.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"Wordlist (path: %s) is missing!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [16 x i8] c"Chosen a word!\0A\00"
define void @gen_rnd_word(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%10 = 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* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
br label %18
18: ; preds = %23, %17
%19 = load i8*, i8** %3
%20 = load i32*, i32** %5
%21 = call i64 @fgets(i8* %19, i32 128, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %18
26: ; preds = %18
%27 = load i32, i32* %8
%28 = call i32 @rand_int(i32 0, i32 %27)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = load i32*, i32** %4
store i32 %29, i32* %30
%31 = 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* %31, i32** %5
br label %32
32: ; preds = %43, %26
%33 = load i8*, i8** %3
%34 = load i32*, i32** %5
%35 = call i64 @fgets(i8* %33, i32 128, i32* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %69
37: ; preds = %32
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = load i32, i32* %9
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %37
br label %32
44: ; preds = %37
store i32 0, i32* %6
br label %45
45: ; preds = %64, %44
%46 = load i32, i32* %6
%47 = load i8*, i8** %3
%48 = call i32 @strlen(i8* %47)
%49 = icmp slt i32 %46, %48
br i1 %49, label %50, label %67
50: ; preds = %45
%51 = load i8*, i8** %3
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 10
br i1 %57, label %58, label %63
58: ; preds = %50
%59 = load i8*, i8** %3
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 0, i8* %62
br label %63
63: ; preds = %58, %50
br label %64
64: ; preds = %63
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %45
67: ; preds = %45
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %67, %32
%70 = load i32*, i32** %5
%71 = call i32 @fclose(i32* %70)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"./res/vcwords.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"Wordlist (path: %s) is missing!\0A\00"
@EXIT_FAILURE = global i32 0
@str = [15 x i8] c"Chosen a word!\00"
define void @gen_rnd_word(i8* %0, i32* nocapture writeonly %1) {
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2, %9
%10 = phi i32 [ %13, %9 ], [ 0, %2 ]
%11 = tail call i64 @fgets(i8* %0, i32 128, i32* %3)
%12 = icmp eq i64 %11, 0
%13 = add nuw nsw i32 %10, 1
br i1 %12, label %14, label %9
14: ; preds = %9
%15 = tail call i32 @rand_int(i32 0, i32 %10)
store i32 %15, i32* %1
%16 = 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))
br label %17
17: ; preds = %21, %14
%18 = phi i32 [ 0, %14 ], [ %22, %21 ]
%19 = tail call i64 @fgets(i8* %0, i32 128, i32* %16)
%20 = icmp eq i64 %19, 0
br i1 %20, label %40, label %21
21: ; preds = %17
%22 = add nuw nsw i32 %18, 1
%23 = icmp eq i32 %22, %15
br i1 %23, label %24, label %17
24: ; preds = %21
%25 = tail call i32 @strlen(i8* %0)
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %24, %33
%28 = phi i64 [ %34, %33 ], [ 0, %24 ]
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 10
br i1 %31, label %32, label %33
32: ; preds = %27
store i8 0, i8* %29
br label %33
33: ; preds = %27, %32
%34 = add nuw nsw i64 %28, 1
%35 = tail call i32 @strlen(i8* %0)
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %34, %36
br i1 %37, label %27, label %38
38: ; preds = %33, %24
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %17, %38
%41 = tail call i32 @fclose(i32* %16)
ret void
}