#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;
};

/* Variables and functions */
int /*<<< orphan*/ fsm_trie_end_word(struct fsm_trie_handle *);
int /*<<< orphan*/ fsm_trie_symbol(struct fsm_trie_handle *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int utf8skip(char *);
int /*<<< orphan*/ xxfree(char *);
char *xxstrdup(char *);
void fsm_trie_add_word(struct fsm_trie_handle *th, char *word) {
  int i, len;
  char *wcopy;
  wcopy = xxstrdup(word);
  len = strlen(wcopy);
  for (i = 0; *word != '\0' && i < len; word = word + utf8skip(word) + 1, i++) {
    strncpy(wcopy, word, utf8skip(word) + 1);
    *(wcopy + utf8skip(word) + 1) = '\0';
    fsm_trie_symbol(th, wcopy, wcopy);
  }
  xxfree(wcopy);
  fsm_trie_end_word(th);
}


x86 assembly (clang, -O0):
<fsm_trie_add_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <xxstrdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     11c1 <fsm_trie_add_word+0x51>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11d1 <fsm_trie_add_word+0x61>
jmp    125f <fsm_trie_add_word+0xef>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <utf8skip@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <utf8skip@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <fsm_trie_symbol@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <utf8skip@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a0 <fsm_trie_add_word+0x30>
mov    -0x20(%rbp),%rdi
call   1080 <xxfree@plt>
mov    -0x8(%rbp),%rdi
call   1070 <fsm_trie_end_word@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsm_trie_add_word>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1090 <xxstrdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <strlen@plt>
cmpb   $0x0,(%rbx)
je     1206 <fsm_trie_add_word+0x96>
mov    %eax,%r12d
test   %eax,%eax
jle    1206 <fsm_trie_add_word+0x96>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <utf8skip@plt>
lea    0x1(%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <utf8skip@plt>
cltq
movb   $0x0,0x1(%r15,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r15,%rdx
call   1060 <fsm_trie_symbol@plt>
mov    %rbx,%rdi
call   1040 <utf8skip@plt>
cltq
cmpb   $0x0,0x1(%rbx,%rax,1)
je     1206 <fsm_trie_add_word+0x96>
add    %rax,%rbx
add    $0x1,%rbx
lea    0x1(%rbp),%eax
cmp    %r12d,%ebp
mov    %eax,%ebp
jl     11b0 <fsm_trie_add_word+0x40>
mov    %r15,%rdi
call   1080 <xxfree@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fsm_trie_end_word@plt>

LLVM IR (-O0):
%struct.fsm_trie_handle = type { i32 }
define void @fsm_trie_add_word(%struct.fsm_trie_handle* %0, i8* %1) {
%3 = alloca %struct.fsm_trie_handle*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store %struct.fsm_trie_handle* %0, %struct.fsm_trie_handle** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i8* @xxstrdup(i8* %8)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %6
store i32 0, i32* %5
br label %12
12: ; preds = %40, %2
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br label %21
21: ; preds = %17, %12
%22 = phi i1 [ false, %12 ], [ %20, %17 ]
br i1 %22, label %23, label %49
23: ; preds = %21
%24 = load i8*, i8** %7
%25 = load i8*, i8** %4
%26 = load i8*, i8** %4
%27 = call i32 @utf8skip(i8* %26)
%28 = add nsw i32 %27, 1
%29 = call i32 @strncpy(i8* %24, i8* %25, i32 %28)
%30 = load i8*, i8** %7
%31 = load i8*, i8** %4
%32 = call i32 @utf8skip(i8* %31)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8 0, i8* %35
%36 = load %struct.fsm_trie_handle*, %struct.fsm_trie_handle** %3
%37 = load i8*, i8** %7
%38 = load i8*, i8** %7
%39 = call i32 @fsm_trie_symbol(%struct.fsm_trie_handle* %36, i8* %37, i8* %38)
br label %40
40: ; preds = %23
%41 = load i8*, i8** %4
%42 = load i8*, i8** %4
%43 = call i32 @utf8skip(i8* %42)
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
%46 = getelementptr inbounds i8, i8* %45, i64 1
store i8* %46, i8** %4
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %12
49: ; preds = %21
%50 = load i8*, i8** %7
%51 = call i32 @xxfree(i8* %50)
%52 = load %struct.fsm_trie_handle*, %struct.fsm_trie_handle** %3
%53 = call i32 @fsm_trie_end_word(%struct.fsm_trie_handle* %52)
ret void
}

LLVM IR (-O2):
%struct.fsm_trie_handle = type { i32 }
define void @fsm_trie_add_word(%struct.fsm_trie_handle* %0, i8* %1) {
%3 = tail call i8* @xxstrdup(i8* %1)
%4 = tail call i32 @strlen(i8* %3)
%5 = load i8, i8* %1
%6 = icmp ne i8 %5, 0
%7 = icmp sgt i32 %4, 0
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %9, label %30
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %3, i64 1
br label %11
11: ; preds = %9, %11
%12 = phi i8* [ %24, %11 ], [ %1, %9 ]
%13 = phi i32 [ %25, %11 ], [ 0, %9 ]
%14 = tail call i32 @utf8skip(i8* %12)
%15 = add nsw i32 %14, 1
%16 = tail call i32 @strncpy(i8* %3, i8* %12, i32 %15)
%17 = tail call i32 @utf8skip(i8* %12)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %10, i64 %18
store i8 0, i8* %19
%20 = tail call i32 @fsm_trie_symbol(%struct.fsm_trie_handle* %0, i8* %3, i8* %3)
%21 = tail call i32 @utf8skip(i8* %12)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %12, i64 1
%24 = getelementptr inbounds i8, i8* %23, i64 %22
%25 = add nuw nsw i32 %13, 1
%26 = load i8, i8* %24
%27 = icmp ne i8 %26, 0
%28 = icmp slt i32 %25, %4
%29 = select i1 %27, i1 %28, i1 false
br i1 %29, label %11, label %30
30: ; preds = %11, %2
%31 = tail call i32 @xxfree(i8* %3)
%32 = tail call i32 @fsm_trie_end_word(%struct.fsm_trie_handle* %0)
ret void
}