#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 fsm_trie_handle {
  int dummy;
};
struct fsm {
  int dummy;
};

/* Variables and functions */
char *file_to_mem(char *);
int /*<<< orphan*/ fsm_trie_add_word(struct fsm_trie_handle *, char *);
struct fsm *fsm_trie_done(struct fsm_trie_handle *);
struct fsm_trie_handle *fsm_trie_init();
scalar_t__ strlen(char *);
int /*<<< orphan*/ xxfree(char *);
struct fsm *fsm_read_text_file(char *filename) {
  struct fsm_trie_handle *th;
  char *text, *textp1, *textp2;
  int lastword;
  text = file_to_mem(filename);
  if (text == NULL) {
    return NULL;
  }
  textp1 = text;
  th = fsm_trie_init();
  for (lastword = 0; lastword == 0; textp1 = textp2 + 1) {
    for (textp2 = textp1; *textp2 != '\n' && *textp2 != '\0'; textp2++) {
    }
    if (*textp2 == '\0') {
      lastword = 1;
      if (textp2 == textp1)
        break;
    }
    *textp2 = '\0';
    if (strlen(textp1) > 0)
      fsm_trie_add_word(th, textp1);
  }
  xxfree(text);
  return (fsm_trie_done(th));
}


x86 assembly (clang, -O0):
<fsm_read_text_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <file_to_mem@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1191 <fsm_read_text_file+0x31>
movq   $0x0,-0x8(%rbp)
jmp    128a <fsm_read_text_file+0x12a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1070 <fsm_trie_init@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    1274 <fsm_read_text_file+0x114>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x35(%rbp)
je     11e2 <fsm_read_text_file+0x82>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    11f2 <fsm_read_text_file+0x92>
jmp    1208 <fsm_read_text_file+0xa8>
jmp    11f7 <fsm_read_text_file+0x97>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11bd <fsm_read_text_file+0x5d>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1237 <fsm_read_text_file+0xd7>
movl   $0x1,-0x34(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1232 <fsm_read_text_file+0xd2>
jmp    1274 <fsm_read_text_file+0x114>
jmp    1237 <fsm_read_text_file+0xd7>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    125e <fsm_read_text_file+0xfe>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <fsm_trie_add_word@plt>
jmp    1263 <fsm_read_text_file+0x103>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11ab <fsm_read_text_file+0x4b>
mov    -0x20(%rbp),%rdi
call   1080 <xxfree@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fsm_trie_done@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsm_read_text_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
call   1050 <file_to_mem@plt>
test   %rax,%rax
je     120a <fsm_read_text_file+0xaa>
mov    %rax,%r14
xor    %eax,%eax
call   1070 <fsm_trie_init@plt>
mov    %rax,%r15
mov    %r14,%r12
jmp    119c <fsm_read_text_file+0x3c>
nopl   0x0(%rax,%rax,1)
add    %rbx,%r12
add    $0x1,%r12
test   %bpl,%bpl
je     11f2 <fsm_read_text_file+0x92>
xor    %ebx,%ebx
xchg   %ax,%ax
movzbl (%r12,%rbx,1),%eax
test   %al,%al
je     11c0 <fsm_read_text_file+0x60>
cmp    $0xa,%al
je     11d0 <fsm_read_text_file+0x70>
add    $0x1,%rbx
jmp    11a0 <fsm_read_text_file+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %rbx,%rbx
je     11f2 <fsm_read_text_file+0x92>
xor    %ebp,%ebp
jmp    11d3 <fsm_read_text_file+0x73>
nopl   0x0(%rax)
mov    $0x1,%bpl
movb   $0x0,(%r12,%rbx,1)
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    1190 <fsm_read_text_file+0x30>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fsm_trie_add_word@plt>
jmp    1190 <fsm_read_text_file+0x30>
mov    %r14,%rdi
call   1080 <xxfree@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fsm_trie_done@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.fsm = type { i32 }
%struct.fsm_trie_handle = type { i32 }
define %struct.fsm* @fsm_read_text_file(i8* %0) {
%2 = alloca %struct.fsm*
%3 = alloca i8*
%4 = alloca %struct.fsm_trie_handle*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i8* @file_to_mem(i8* %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
store %struct.fsm* null, %struct.fsm** %2
br label %67
14: ; preds = %1
%15 = load i8*, i8** %5
store i8* %15, i8** %6
%16 = call %struct.fsm_trie_handle* (...) @fsm_trie_init()
store %struct.fsm_trie_handle* %16, %struct.fsm_trie_handle** %4
store i32 0, i32* %8
br label %17
17: ; preds = %59, %14
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %62
20: ; preds = %17
%21 = load i8*, i8** %6
store i8* %21, i8** %7
br label %22
22: ; preds = %35, %20
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 10
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br label %32
32: ; preds = %27, %22
%33 = phi i1 [ false, %22 ], [ %31, %27 ]
br i1 %33, label %34, label %38
34: ; preds = %32
br label %35
35: ; preds = %34
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %7
br label %22
38: ; preds = %32
%39 = load i8*, i8** %7
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %38
store i32 1, i32* %8
%44 = load i8*, i8** %7
%45 = load i8*, i8** %6
%46 = icmp eq i8* %44, %45
br i1 %46, label %47, label %48
47: ; preds = %43
br label %62
48: ; preds = %43
br label %49
49: ; preds = %48, %38
%50 = load i8*, i8** %7
store i8 0, i8* %50
%51 = load i8*, i8** %6
%52 = call i64 @strlen(i8* %51)
%53 = icmp sgt i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = load %struct.fsm_trie_handle*, %struct.fsm_trie_handle** %4
%56 = load i8*, i8** %6
%57 = call i32 @fsm_trie_add_word(%struct.fsm_trie_handle* %55, i8* %56)
br label %58
58: ; preds = %54, %49
br label %59
59: ; preds = %58
%60 = load i8*, i8** %7
%61 = getelementptr inbounds i8, i8* %60, i64 1
store i8* %61, i8** %6
br label %17
62: ; preds = %47, %17
%63 = load i8*, i8** %5
%64 = call i32 @xxfree(i8* %63)
%65 = load %struct.fsm_trie_handle*, %struct.fsm_trie_handle** %4
%66 = call %struct.fsm* @fsm_trie_done(%struct.fsm_trie_handle* %65)
store %struct.fsm* %66, %struct.fsm** %2
br label %67
67: ; preds = %62, %13
%68 = load %struct.fsm*, %struct.fsm** %2
ret %struct.fsm* %68
}

LLVM IR (-O2):
%struct.fsm = type { i32 }
%struct.fsm_trie_handle = type { i32 }
define %struct.fsm* @fsm_read_text_file(i8* %0) {
%2 = tail call i8* @file_to_mem(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %26, label %4
4: ; preds = %1
%5 = tail call %struct.fsm_trie_handle* (...) @fsm_trie_init()
br label %6
6: ; preds = %4, %21
%7 = phi i8* [ %2, %4 ], [ %22, %21 ]
br label %8
8: ; preds = %6, %11
%9 = phi i8* [ %12, %11 ], [ %7, %6 ]
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 0, label %13
i8 10, label %15
]
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
br label %8
13: ; preds = %8
%14 = icmp eq i8* %9, %7
br i1 %14, label %23, label %15
15: ; preds = %8, %13
%16 = phi i1 [ false, %13 ], [ true, %8 ]
store i8 0, i8* %9
%17 = tail call i64 @strlen(i8* %7)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i32 @fsm_trie_add_word(%struct.fsm_trie_handle* %5, i8* %7)
br label %21
21: ; preds = %15, %19
%22 = getelementptr inbounds i8, i8* %9, i64 1
br i1 %16, label %6, label %23
23: ; preds = %13, %21
%24 = tail call i32 @xxfree(i8* %2)
%25 = tail call %struct.fsm* @fsm_trie_done(%struct.fsm_trie_handle* %5)
br label %26
26: ; preds = %1, %23
%27 = phi %struct.fsm* [ %25, %23 ], [ null, %1 ]
ret %struct.fsm* %27
}