#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 */
struct wordlist {
  int dummy;
};
struct bitfield {
  int dummy;
};
typedef int /*<<< orphan*/ UChar;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ add_word(struct wordlist **, int /*<<< orphan*/ *,
                            struct bitfield *, int, int, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int strlen(char *);
void load_words(struct wordlist **words, UChar *alphabet,
                struct bitfield *masterbits, int maxlen, int minlen,
                const char *filename) {
  FILE *dict;
  char line[128];
  dict = fopen(filename, "r");
  if (dict == NULL) {
    fprintf(stderr, "Cannot open %s for reading.\n", filename);
    exit(99);
  }
  while (fgets(line, 128, dict) != NULL) {
    char *l = line + strlen(line) - 1;
    while ((l > line) && ((*l == '\r') || (*l == '\n'))) {
      *l = '\0';
      l--;
    }
    if (line[0])
      add_word(words, alphabet, masterbits, maxlen, minlen, line);
  }
  fclose(dict);
}


x86 assembly (clang, -O0):
<load_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d4 <load_words+0x64>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe3d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x63,%edi
call   1090 <exit@plt>
jmp    11d9 <load_words+0x69>
lea    -0xb0(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12ed <load_words+0x17d>
lea    -0xb0(%rbp),%rax
mov    %rax,-0xc0(%rbp)
lea    -0xb0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0xc0(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rcx
lea    -0xb0(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0xc1(%rbp)
jbe    1288 <load_words+0x118>
mov    -0xb8(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0xc2(%rbp)
je     127c <load_words+0x10c>
mov    -0xb8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0xc2(%rbp)
mov    -0xc2(%rbp),%al
mov    %al,-0xc1(%rbp)
mov    -0xc1(%rbp),%al
test   $0x1,%al
jne    129b <load_words+0x12b>
jmp    12bc <load_words+0x14c>
mov    -0xb8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0xb8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0xb8(%rbp)
jmp    122c <load_words+0xbc>
cmpb   $0x0,-0xb0(%rbp)
je     12e8 <load_words+0x178>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    -0xb0(%rbp),%r9
call   1070 <add_word@plt>
jmp    11d9 <load_words+0x69>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_words>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %r9,%r14
mov    %r8d,0xc(%rsp)
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0xe64(%rip),%rsi
mov    %r9,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     124c <load_words+0xdc>
mov    %rax,%rbp
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1232 <load_words+0xc2>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
add    %rsp,%rax
add    $0xf,%rax
jmp    11f7 <load_words+0x87>
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %r14,%rax
jbe    1210 <load_words+0xa0>
movzbl (%rax),%ecx
cmp    $0xd,%cl
je     11f0 <load_words+0x80>
cmp    $0xa,%cl
je     11f0 <load_words+0x80>
nopl   0x0(%rax)
cmpb   $0x0,0x10(%rsp)
je     11c0 <load_words+0x50>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    0xc(%rsp),%r8d
mov    %r14,%r9
call   1070 <add_word@plt>
jmp    11c0 <load_words+0x50>
mov    %rbp,%rdi
call   1030 <fclose@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x63,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.wordlist = type { i32 }
%struct.bitfield = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Cannot open %s for reading.\0A\00"
define void @load_words(%struct.wordlist** %0, i32* %1, %struct.bitfield* %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca %struct.wordlist**
%8 = alloca i32*
%9 = alloca %struct.bitfield*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca [128 x i8]
%15 = alloca i8*
store %struct.wordlist** %0, %struct.wordlist*** %7
store i32* %1, i32** %8
store %struct.bitfield* %2, %struct.bitfield** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i8* %5, i8** %12
%16 = load i8*, i8** %12
%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 i32*, i32** %13
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %6
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %12
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 99)
unreachable
25: ; preds = %6
br label %26
26: ; preds = %72, %25
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%28 = load i32*, i32** %13
%29 = call i32* @fgets(i8* %27, i32 128, i32* %28)
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %73
31: ; preds = %26
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = getelementptr inbounds i8, i8* %36, i64 -1
store i8* %37, i8** %15
br label %38
38: ; preds = %56, %31
%39 = load i8*, i8** %15
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%41 = icmp ugt i8* %39, %40
br i1 %41, label %42, label %54
42: ; preds = %38
%43 = load i8*, i8** %15
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 13
br i1 %46, label %52, label %47
47: ; preds = %42
%48 = load i8*, i8** %15
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 10
br label %52
52: ; preds = %47, %42
%53 = phi i1 [ true, %42 ], [ %51, %47 ]
br label %54
54: ; preds = %52, %38
%55 = phi i1 [ false, %38 ], [ %53, %52 ]
br i1 %55, label %56, label %60
56: ; preds = %54
%57 = load i8*, i8** %15
store i8 0, i8* %57
%58 = load i8*, i8** %15
%59 = getelementptr inbounds i8, i8* %58, i32 -1
store i8* %59, i8** %15
br label %38
60: ; preds = %54
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%62 = load i8, i8* %61
%63 = icmp ne i8 %62, 0
br i1 %63, label %64, label %72
64: ; preds = %60
%65 = load %struct.wordlist**, %struct.wordlist*** %7
%66 = load i32*, i32** %8
%67 = load %struct.bitfield*, %struct.bitfield** %9
%68 = load i32, i32* %10
%69 = load i32, i32* %11
%70 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%71 = call i32 @add_word(%struct.wordlist** %65, i32* %66, %struct.bitfield* %67, i32 %68, i32 %69, i8* %70)
br label %72
72: ; preds = %64, %60
br label %26
73: ; preds = %26
%74 = load i32*, i32** %13
%75 = call i32 @fclose(i32* %74)
ret void
}

LLVM IR (-O2):
%struct.wordlist = type { i32 }
%struct.bitfield = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Cannot open %s for reading.\0A\00"
define void @load_words(%struct.wordlist** %0, i32* %1, %struct.bitfield* %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca [128 x i8]
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%9 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = call i32* @fgets(i8* %8, i32 128, i32* %9)
%13 = icmp eq i32* %12, null
br i1 %13, label %38, label %18
14: ; preds = %6
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%17 = tail call i32 @exit(i32 99)
unreachable
18: ; preds = %11, %35
%19 = call i32 @strlen(i8* %8)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 -1
%23 = icmp ugt i8* %22, %8
br i1 %23, label %24, label %30
24: ; preds = %18, %27
%25 = phi i8* [ %28, %27 ], [ %22, %18 ]
%26 = load i8, i8* %25
switch i8 %26, label %30 [
i8 13, label %27
i8 10, label %27
]
27: ; preds = %24, %24
store i8 0, i8* %25
%28 = getelementptr inbounds i8, i8* %25, i64 -1
%29 = icmp ugt i8* %28, %8
br i1 %29, label %24, label %30
30: ; preds = %27, %24, %18
%31 = load i8, i8* %8
%32 = icmp eq i8 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 @add_word(%struct.wordlist** %0, i32* %1, %struct.bitfield* %2, i32 %3, i32 %4, i8* %8)
br label %35
35: ; preds = %33, %30
%36 = call i32* @fgets(i8* %8, i32 128, i32* %9)
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %18
38: ; preds = %35, %11
%39 = call i32 @fclose(i32* %9)
ret void
}