#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 */

/* Variables and functions */
int /*<<< orphan*/ look_for_match(int *, unsigned char const **,
                                  unsigned char const *, size_t *);
int /*<<< orphan*/ skip_packed_integer(unsigned char const *, size_t *);
int /*<<< orphan*/ unpack_integer(unsigned char const *, unsigned long *,
                                  size_t *);
unsigned long int search_packed_trie(const unsigned char *word,
                                     const unsigned char *trie,
                                     const size_t index) {
  unsigned long int value;
  size_t i;
  int is_match;
  i = index;
  unpack_integer(trie, &value, &i);
  if (word[0] == '\0') {
    return value;
  } else {
    while ((trie[i] & 0x7F) < word[0]) {
      while ((trie[i] & 0x80) == 0)
        i++;
      i++;
      unpack_integer(trie, &value, &i);
      if (value == 0)
        return 0;
      i += value;
    }
    look_for_match(&is_match, &word, trie, &i);
    if (is_match) {
      skip_packed_integer(trie, &i);
      return search_packed_trie(word, trie, i);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<search_packed_trie>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <unpack_integer@plt>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    118a <search_packed_trie+0x4a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1276 <search_packed_trie+0x136>
jmp    118f <search_packed_trie+0x4f>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0x7f,%eax
mov    -0x10(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jge    1223 <search_packed_trie+0xe3>
jmp    11b2 <search_packed_trie+0x72>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    11dd <search_packed_trie+0x9d>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11b2 <search_packed_trie+0x72>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <unpack_integer@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1212 <search_packed_trie+0xd2>
movq   $0x0,-0x8(%rbp)
jmp    1276 <search_packed_trie+0x136>
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    118f <search_packed_trie+0x4f>
mov    -0x18(%rbp),%rdx
lea    -0x34(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x30(%rbp),%rcx
call   1060 <look_for_match@plt>
cmpl   $0x0,-0x34(%rbp)
je     1269 <search_packed_trie+0x129>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <skip_packed_integer@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <search_packed_trie@plt>
mov    %rax,-0x8(%rbp)
jmp    1276 <search_packed_trie+0x136>
jmp    126e <search_packed_trie+0x12e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_packed_trie>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rdi,0x18(%rsp)
mov    %rdx,(%rsp)
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1030 <unpack_integer@plt>
mov    (%r14),%sil
test   %sil,%sil
je     1235 <search_packed_trie+0xf5>
mov    (%rsp),%rax
mov    (%rbx,%rax,1),%dl
mov    %edx,%ecx
and    $0x7f,%cl
cmp    %sil,%cl
jae    11f8 <search_packed_trie+0xb8>
lea    0x8(%rsp),%r12
mov    %rsp,%r13
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %dl,%dl
js     11c0 <search_packed_trie+0x80>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x1(%rax),%rcx
cmpb   $0x0,0x1(%rbx,%rax,1)
mov    %rcx,%rax
jns    11b0 <search_packed_trie+0x70>
jmp    11c3 <search_packed_trie+0x83>
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <unpack_integer@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     123f <search_packed_trie+0xff>
add    (%rsp),%rax
mov    %rax,(%rsp)
mov    (%rbx,%rax,1),%dl
mov    %edx,%ecx
and    $0x7f,%cl
cmp    (%r14),%cl
jb     11a0 <search_packed_trie+0x60>
lea    0x14(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %rsp,%rcx
mov    %rbx,%rdx
call   1060 <look_for_match@plt>
cmpl   $0x0,0x14(%rsp)
je     123c <search_packed_trie+0xfc>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <skip_packed_integer@plt>
mov    0x18(%rsp),%rdi
mov    (%rsp),%rdx
mov    %rbx,%rsi
call   1050 <search_packed_trie@plt>
mov    %rax,%r15
jmp    123f <search_packed_trie+0xff>
mov    0x8(%rsp),%r15
jmp    123f <search_packed_trie+0xff>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @search_packed_trie(i8* %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%11 = load i64, i64* %7
store i64 %11, i64* %9
%12 = load i8*, i8** %6
%13 = call i32 @unpack_integer(i8* %12, i64* %8, i64* %9)
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %3
%20 = load i64, i64* %8
store i64 %20, i64* %4
br label %72
21: ; preds = %3
br label %22
22: ; preds = %54, %21
%23 = load i8*, i8** %6
%24 = load i64, i64* %9
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = and i32 %27, 127
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp slt i32 %28, %32
br i1 %33, label %34, label %58
34: ; preds = %22
br label %35
35: ; preds = %43, %34
%36 = load i8*, i8** %6
%37 = load i64, i64* %9
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = and i32 %40, 128
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %35
%44 = load i64, i64* %9
%45 = add i64 %44, 1
store i64 %45, i64* %9
br label %35
46: ; preds = %35
%47 = load i64, i64* %9
%48 = add i64 %47, 1
store i64 %48, i64* %9
%49 = load i8*, i8** %6
%50 = call i32 @unpack_integer(i8* %49, i64* %8, i64* %9)
%51 = load i64, i64* %8
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %46
store i64 0, i64* %4
br label %72
54: ; preds = %46
%55 = load i64, i64* %8
%56 = load i64, i64* %9
%57 = add i64 %56, %55
store i64 %57, i64* %9
br label %22
58: ; preds = %22
%59 = load i8*, i8** %6
%60 = call i32 @look_for_match(i32* %10, i8** %5, i8* %59, i64* %9)
%61 = load i32, i32* %10
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %70
63: ; preds = %58
%64 = load i8*, i8** %6
%65 = call i32 @skip_packed_integer(i8* %64, i64* %9)
%66 = load i8*, i8** %5
%67 = load i8*, i8** %6
%68 = load i64, i64* %9
%69 = call i64 @search_packed_trie(i8* %66, i8* %67, i64 %68)
store i64 %69, i64* %4
br label %72
70: ; preds = %58
br label %71
71: ; preds = %70
store i64 0, i64* %4
br label %72
72: ; preds = %71, %63, %53, %19
%73 = load i64, i64* %4
ret i64 %73
}

LLVM IR (-O2):
define i64 @search_packed_trie(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %4
%8 = bitcast i64* %5 to i8*
%9 = bitcast i64* %6 to i8*
%10 = bitcast i32* %7 to i8*
store i64 %2, i64* %6
%11 = call i32 @unpack_integer(i8* %1, i64* %5, i64* %6)
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %3
%15 = load i64, i64* %6
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = and i8 %17, 127
%19 = icmp ult i8 %18, %12
br i1 %19, label %22, label %46
20: ; preds = %3
%21 = load i64, i64* %5
br label %55
22: ; preds = %14, %38
%23 = phi i8 [ %42, %38 ], [ %17, %14 ]
%24 = phi i64 [ %40, %38 ], [ %15, %14 ]
%25 = icmp sgt i8 %23, -1
br i1 %25, label %26, label %32
26: ; preds = %22, %26
%27 = phi i64 [ %28, %26 ], [ %24, %22 ]
%28 = add i64 %27, 1
%29 = getelementptr inbounds i8, i8* %1, i64 %28
%30 = load i8, i8* %29
%31 = icmp sgt i8 %30, -1
br i1 %31, label %26, label %32
32: ; preds = %26, %22
%33 = phi i64 [ %24, %22 ], [ %28, %26 ]
%34 = add i64 %33, 1
store i64 %34, i64* %6
%35 = call i32 @unpack_integer(i8* %1, i64* %5, i64* %6)
%36 = load i64, i64* %5
%37 = icmp eq i64 %36, 0
br i1 %37, label %55, label %38
38: ; preds = %32
%39 = load i64, i64* %6
%40 = add i64 %39, %36
store i64 %40, i64* %6
%41 = getelementptr inbounds i8, i8* %1, i64 %40
%42 = load i8, i8* %41
%43 = and i8 %42, 127
%44 = load i8, i8* %0
%45 = icmp ult i8 %43, %44
br i1 %45, label %22, label %46
46: ; preds = %38, %14
%47 = call i32 @look_for_match(i32* %7, i8** %4, i8* %1, i64* %6)
%48 = load i32, i32* %7
%49 = icmp eq i32 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %46
%51 = call i32 @skip_packed_integer(i8* %1, i64* %6)
%52 = load i8*, i8** %4
%53 = load i64, i64* %6
%54 = call i64 @search_packed_trie(i8* %52, i8* %1, i64 %53)
br label %55
55: ; preds = %32, %46, %50, %20
%56 = phi i64 [ %21, %20 ], [ %54, %50 ], [ 0, %46 ], [ 0, %32 ]
ret i64 %56
}