#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 EOF;
int /*<<< orphan*/ err(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ insert_word(unsigned char *, char *);
void load_words(unsigned char filter[], char *filename) {
  FILE *dict = fopen(filename, "r");
  char buf[32];
  int c, pos = 0;
  if (!dict)
    err("unable to open dictionary \"%s\"\n", filename);
  while ((c = getc(dict)) != EOF) {
    if (c != '\n') {
      if (pos > 32 - 2) {
        buf[32 - 1] = 0;
        err("word \"%s\" exceeds buffer length\n", buf);
      } else {
        buf[pos++] = c;
      }
    } else {
      buf[pos] = 0;
      insert_word(filter, buf);
      pos = 0;
    }
  }
  fclose(dict);
}


x86 assembly (clang, -O0):
<load_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x48(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1196 <load_words+0x46>
mov    -0x10(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1050 <err@plt>
jmp    119b <load_words+0x4b>
mov    -0x18(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x44(%rbp)
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%eax
je     1220 <load_words+0xd0>
cmpl   $0xa,-0x44(%rbp)
je     11fe <load_words+0xae>
cmpl   $0x1e,-0x48(%rbp)
jle    11e3 <load_words+0x93>
movb   $0x0,-0x21(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1050 <err@plt>
jmp    11f9 <load_words+0xa9>
mov    -0x44(%rbp),%eax
mov    %al,%cl
mov    -0x48(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x48(%rbp)
cltq
mov    %cl,-0x40(%rbp,%rax,1)
jmp    121b <load_words+0xcb>
movslq -0x48(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1040 <insert_word@plt>
movl   $0x0,-0x48(%rbp)
jmp    119b <load_words+0x4b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_words>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe95(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118a <load_words+0x3a>
lea    0xe80(%rip),%rdi
mov    %r15,%rsi
call   1050 <err@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    0x2e4f(%rip),%r13
cmp    0x0(%r13),%eax
jne    11b6 <load_words+0x66>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    %rsp,%r15
lea    0xe60(%rip),%r12
jmp    11f2 <load_words+0xa2>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <insert_word@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1070 <getc@plt>
cmp    0x0(%r13),%eax
je     119f <load_words+0x4f>
cmp    $0xa,%eax
je     11d0 <load_words+0x80>
cmp    $0x1f,%ebp
jl     1210 <load_words+0xc0>
movb   $0x0,0x1f(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <err@plt>
jmp    11e4 <load_words+0x94>
xchg   %ax,%ax
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%rsp,%rcx,1)
jmp    11e4 <load_words+0x94>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [32 x i8] c"unable to open dictionary \22%s\22\0A\00"
@EOF = global i32 0
@.str.2 = [33 x i8] c"word \22%s\22 exceeds buffer length\0A\00"
define void @load_words(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [32 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
store i32 0, i32* %8
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @err(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %2
br label %17
17: ; preds = %47, %16
%18 = load i32*, i32** %5
%19 = call i32 @getc(i32* %18)
store i32 %19, i32* %7
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %48
22: ; preds = %17
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 10
br i1 %24, label %25, label %40
25: ; preds = %22
%26 = load i32, i32* %8
%27 = icmp sgt i32 %26, 30
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 31
store i8 0, i8* %29
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%31 = call i32 @err(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %39
32: ; preds = %25
%33 = load i32, i32* %7
%34 = trunc i32 %33 to i8
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %37
store i8 %34, i8* %38
br label %39
39: ; preds = %32, %28
br label %47
40: ; preds = %22
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %3
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%46 = call i32 @insert_word(i8* %44, i8* %45)
store i32 0, i32* %8
br label %47
47: ; preds = %40, %39
br label %17
48: ; preds = %17
%49 = load i32*, i32** %5
%50 = call i32 @fclose(i32* %49)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [32 x i8] c"unable to open dictionary \22%s\22\0A\00"
@EOF = global i32 0
@.str.2 = [33 x i8] c"word \22%s\22 exceeds buffer length\0A\00"
define void @load_words(i8* %0, i8* %1) {
%3 = alloca [32 x i8]
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = icmp eq i32* %4, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @err(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %9
9: ; preds = %7, %2
%10 = call i32 @getc(i32* %4)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %37, label %13
13: ; preds = %9
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 31
br label %15
15: ; preds = %13, %32
%16 = phi i32 [ %10, %13 ], [ %34, %32 ]
%17 = phi i32 [ 0, %13 ], [ %33, %32 ]
%18 = icmp eq i32 %16, 10
br i1 %18, label %28, label %19
19: ; preds = %15
%20 = icmp sgt i32 %17, 30
br i1 %20, label %21, label %23
21: ; preds = %19
store i8 0, i8* %14
%22 = call i32 @err(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %32
23: ; preds = %19
%24 = trunc i32 %16 to i8
%25 = add nsw i32 %17, 1
%26 = sext i32 %17 to i64
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %26
store i8 %24, i8* %27
br label %32
28: ; preds = %15
%29 = sext i32 %17 to i64
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %29
store i8 0, i8* %30
%31 = call i32 @insert_word(i8* %0, i8* %5)
br label %32
32: ; preds = %21, %23, %28
%33 = phi i32 [ %17, %21 ], [ %25, %23 ], [ 0, %28 ]
%34 = call i32 @getc(i32* %4)
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %15
37: ; preds = %32, %9
%38 = call i32 @fclose(i32* %4)
ret void
}