#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 TrieNode {
  int dummy;
};
struct ListNode {
  int dummy;
};
struct List {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ list_append(struct List *, struct ListNode *);
struct ListNode *listnode_alloc(int /*<<< orphan*/);
scalar_t__ tolower(char);
int /*<<< orphan*/ trie_search_star(struct TrieNode *, char *, unsigned short,
                                    unsigned short, struct List *);
scalar_t__ trienode_key(struct TrieNode *);
struct TrieNode *trienode_next(struct TrieNode *);
struct TrieNode *trienode_sibling(struct TrieNode *);
int /*<<< orphan*/ trienode_values(struct TrieNode *);
void trie_search1(struct TrieNode *node, char *keys, unsigned short idx,
                  unsigned short max, struct List *result) {
  if (!node)
    return;
  assert(idx < max);
  if (keys[idx] == '*')
    trie_search_star(node, keys, idx, max, result);
  else if (keys[idx] == '?') {
    idx++;
    if (idx == max) {
      struct TrieNode *sibling;
      for (sibling = node; sibling; sibling = trienode_sibling(sibling)) {
        struct ListNode *value = listnode_alloc(trienode_values(sibling));
        list_append(result, value);
      }
    } else {
      struct TrieNode *sibling;
      for (sibling = node; sibling; sibling = trienode_sibling(sibling))
        trie_search1(trienode_next(sibling), keys, idx, max, result);
    }
  } else if (trienode_key(node) == tolower(keys[idx])) {
    idx++;
    if (idx == max) {
      struct ListNode *value = listnode_alloc(trienode_values(node));
      list_append(result, value);
    } else
      trie_search1(trienode_next(node), keys, idx, max, result);
  } else
    trie_search1(trienode_sibling(node), keys, idx, max, result);
}


x86 assembly (clang, -O0):
<trie_search1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %cx,%ax
mov    %dx,%cx
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %cx,-0x12(%rbp)
mov    %ax,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11d2 <trie_search1+0x32>
jmp    13c1 <trie_search1+0x221>
movzwl -0x12(%rbp),%eax
movzwl -0x14(%rbp),%ecx
cmp    %ecx,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rax
movzwl -0x12(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2a,%eax
jne    1222 <trie_search1+0x82>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x12(%rbp),%cx
mov    -0x14(%rbp),%ax
mov    -0x20(%rbp),%r8
movzwl %cx,%edx
movzwl %ax,%ecx
call   10a0 <trie_search_star@plt>
jmp    13c1 <trie_search1+0x221>
mov    -0x10(%rbp),%rax
movzwl -0x12(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3f,%eax
jne    12f4 <trie_search1+0x154>
mov    -0x12(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
movzwl -0x14(%rbp),%ecx
cmp    %ecx,%eax
jne    129e <trie_search1+0xfe>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1299 <trie_search1+0xf9>
mov    -0x28(%rbp),%rdi
call   1040 <trienode_values@plt>
mov    %eax,%edi
call   1030 <listnode_alloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10c0 <list_append@plt>
mov    -0x28(%rbp),%rdi
call   1050 <trienode_sibling@plt>
mov    %rax,-0x28(%rbp)
jmp    125b <trie_search1+0xbb>
jmp    12ef <trie_search1+0x14f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12ea <trie_search1+0x14a>
mov    -0x38(%rbp),%rdi
call   1070 <trienode_next@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x12(%rbp),%cx
mov    -0x14(%rbp),%ax
mov    -0x20(%rbp),%r8
movzwl %cx,%edx
movzwl %ax,%ecx
call   1060 <trie_search1@plt>
mov    -0x38(%rbp),%rdi
call   1050 <trienode_sibling@plt>
mov    %rax,-0x38(%rbp)
jmp    12a6 <trie_search1+0x106>
jmp    12ef <trie_search1+0x14f>
jmp    13bc <trie_search1+0x21c>
mov    -0x8(%rbp),%rdi
call   10b0 <trienode_key@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movzwl -0x12(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1090 <tolower@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
jne    1390 <trie_search1+0x1f0>
mov    -0x12(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
movzwl -0x14(%rbp),%ecx
cmp    %ecx,%eax
jne    1364 <trie_search1+0x1c4>
mov    -0x8(%rbp),%rdi
call   1040 <trienode_values@plt>
mov    %eax,%edi
call   1030 <listnode_alloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10c0 <list_append@plt>
jmp    138b <trie_search1+0x1eb>
mov    -0x8(%rbp),%rdi
call   1070 <trienode_next@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x12(%rbp),%cx
mov    -0x14(%rbp),%ax
mov    -0x20(%rbp),%r8
movzwl %cx,%edx
movzwl %ax,%ecx
call   1060 <trie_search1@plt>
jmp    13b7 <trie_search1+0x217>
mov    -0x8(%rbp),%rdi
call   1050 <trienode_sibling@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x12(%rbp),%cx
mov    -0x14(%rbp),%ax
mov    -0x20(%rbp),%r8
movzwl %cx,%edx
movzwl %ax,%ecx
call   1060 <trie_search1@plt>
jmp    13bc <trie_search1+0x21c>
jmp    13c1 <trie_search1+0x221>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trie_search1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,0x4(%rsp)
test   %rdi,%rdi
je     12fb <trie_search1+0x15b>
mov    %r8,%r14
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %ebp,%ebp
cmp    0x4(%rsp),%r12w
setb   %bpl
movzwl %r12w,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
call   1080 <assert@plt>
movzbl (%r15,%r12,1),%eax
cmp    $0x3f,%al
je     1259 <trie_search1+0xb9>
cmp    $0x2a,%al
je     129c <trie_search1+0xfc>
mov    %rbx,%rdi
call   10b0 <trienode_key@plt>
mov    %rax,%r13
movsbl (%r15,%r12,1),%edi
call   1090 <tolower@plt>
cmp    %rax,%r13
je     1230 <trie_search1+0x90>
mov    %rbx,%rdi
call   1050 <trienode_sibling@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11e0 <trie_search1+0x40>
jmp    12fb <trie_search1+0x15b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12d
cmp    0x4(%rsp),%r12w
je     130a <trie_search1+0x16a>
mov    %rbx,%rdi
call   1070 <trienode_next@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c4 <trie_search1+0x24>
jmp    12fb <trie_search1+0x15b>
add    $0x1,%r12d
mov    0x4(%rsp),%eax
cmp    %ax,%r12w
jne    12c0 <trie_search1+0x120>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <trienode_values@plt>
mov    %eax,%edi
call   1030 <listnode_alloc@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   10c0 <list_append@plt>
mov    %rbx,%rdi
call   1050 <trienode_sibling@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1270 <trie_search1+0xd0>
jmp    12fb <trie_search1+0x15b>
movzwl 0x4(%rsp),%ecx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
mov    %r14,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <trie_search_star@plt>
movzwl %r12w,%r12d
movzwl %ax,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <trienode_next@plt>
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    %r14,%r8
call   1060 <trie_search1@plt>
mov    %rbx,%rdi
call   1050 <trienode_sibling@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12d0 <trie_search1+0x130>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1040 <trienode_values@plt>
mov    %eax,%edi
call   1030 <listnode_alloc@plt>
mov    %r14,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10c0 <list_append@plt>

LLVM IR (-O0):
%struct.TrieNode = type { i32 }
%struct.List = type { i32 }
%struct.ListNode = type { i32 }
define void @trie_search1(%struct.TrieNode* %0, i8* %1, i16 zeroext %2, i16 zeroext %3, %struct.List* %4) {
%6 = alloca %struct.TrieNode*
%7 = alloca i8*
%8 = alloca i16
%9 = alloca i16
%10 = alloca %struct.List*
%11 = alloca %struct.TrieNode*
%12 = alloca %struct.ListNode*
%13 = alloca %struct.TrieNode*
%14 = alloca %struct.ListNode*
store %struct.TrieNode* %0, %struct.TrieNode** %6
store i8* %1, i8** %7
store i16 %2, i16* %8
store i16 %3, i16* %9
store %struct.List* %4, %struct.List** %10
%15 = load %struct.TrieNode*, %struct.TrieNode** %6
%16 = icmp ne %struct.TrieNode* %15, null
br i1 %16, label %18, label %17
17: ; preds = %5
br label %131
18: ; preds = %5
%19 = load i16, i16* %8
%20 = zext i16 %19 to i32
%21 = load i16, i16* %9
%22 = zext i16 %21 to i32
%23 = icmp slt i32 %20, %22
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i8*, i8** %7
%27 = load i16, i16* %8
%28 = zext i16 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 42
br i1 %32, label %33, label %40
33: ; preds = %18
%34 = load %struct.TrieNode*, %struct.TrieNode** %6
%35 = load i8*, i8** %7
%36 = load i16, i16* %8
%37 = load i16, i16* %9
%38 = load %struct.List*, %struct.List** %10
%39 = call i32 @trie_search_star(%struct.TrieNode* %34, i8* %35, i16 zeroext %36, i16 zeroext %37, %struct.List* %38)
br label %131
40: ; preds = %18
%41 = load i8*, i8** %7
%42 = load i16, i16* %8
%43 = zext i16 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 63
br i1 %47, label %48, label %89
48: ; preds = %40
%49 = load i16, i16* %8
%50 = add i16 %49, 1
store i16 %50, i16* %8
%51 = load i16, i16* %8
%52 = zext i16 %51 to i32
%53 = load i16, i16* %9
%54 = zext i16 %53 to i32
%55 = icmp eq i32 %52, %54
br i1 %55, label %56, label %72
56: ; preds = %48
%57 = load %struct.TrieNode*, %struct.TrieNode** %6
store %struct.TrieNode* %57, %struct.TrieNode** %11
br label %58
58: ; preds = %68, %56
%59 = load %struct.TrieNode*, %struct.TrieNode** %11
%60 = icmp ne %struct.TrieNode* %59, null
br i1 %60, label %61, label %71
61: ; preds = %58
%62 = load %struct.TrieNode*, %struct.TrieNode** %11
%63 = call i32 @trienode_values(%struct.TrieNode* %62)
%64 = call %struct.ListNode* @listnode_alloc(i32 %63)
store %struct.ListNode* %64, %struct.ListNode** %12
%65 = load %struct.List*, %struct.List** %10
%66 = load %struct.ListNode*, %struct.ListNode** %12
%67 = call i32 @list_append(%struct.List* %65, %struct.ListNode* %66)
br label %68
68: ; preds = %61
%69 = load %struct.TrieNode*, %struct.TrieNode** %11
%70 = call %struct.TrieNode* @trienode_sibling(%struct.TrieNode* %69)
store %struct.TrieNode* %70, %struct.TrieNode** %11
br label %58
71: ; preds = %58
br label %88
72: ; preds = %48
%73 = load %struct.TrieNode*, %struct.TrieNode** %6
store %struct.TrieNode* %73, %struct.TrieNode** %13
br label %74
74: ; preds = %84, %72
%75 = load %struct.TrieNode*, %struct.TrieNode** %13
%76 = icmp ne %struct.TrieNode* %75, null
br i1 %76, label %77, label %87
77: ; preds = %74
%78 = load %struct.TrieNode*, %struct.TrieNode** %13
%79 = call %struct.TrieNode* @trienode_next(%struct.TrieNode* %78)
%80 = load i8*, i8** %7
%81 = load i16, i16* %8
%82 = load i16, i16* %9
%83 = load %struct.List*, %struct.List** %10
br label %84
84: ; preds = %77
%85 = load %struct.TrieNode*, %struct.TrieNode** %13
%86 = call %struct.TrieNode* @trienode_sibling(%struct.TrieNode* %85)
store %struct.TrieNode* %86, %struct.TrieNode** %13
br label %74
87: ; preds = %74
br label %88
88: ; preds = %87, %71
br label %130
89: ; preds = %40
%90 = load %struct.TrieNode*, %struct.TrieNode** %6
%91 = call i64 @trienode_key(%struct.TrieNode* %90)
%92 = load i8*, i8** %7
%93 = load i16, i16* %8
%94 = zext i16 %93 to i64
%95 = getelementptr inbounds i8, i8* %92, i64 %94
%96 = load i8, i8* %95
%97 = call i64 @tolower(i8 signext %96)
%98 = icmp eq i64 %91, %97
br i1 %98, label %99, label %122
99: ; preds = %89
%100 = load i16, i16* %8
%101 = add i16 %100, 1
store i16 %101, i16* %8
%102 = load i16, i16* %8
%103 = zext i16 %102 to i32
%104 = load i16, i16* %9
%105 = zext i16 %104 to i32
%106 = icmp eq i32 %103, %105
br i1 %106, label %107, label %114
107: ; preds = %99
%108 = load %struct.TrieNode*, %struct.TrieNode** %6
%109 = call i32 @trienode_values(%struct.TrieNode* %108)
%110 = call %struct.ListNode* @listnode_alloc(i32 %109)
store %struct.ListNode* %110, %struct.ListNode** %14
%111 = load %struct.List*, %struct.List** %10
%112 = load %struct.ListNode*, %struct.ListNode** %14
%113 = call i32 @list_append(%struct.List* %111, %struct.ListNode* %112)
br label %121
114: ; preds = %99
%115 = load %struct.TrieNode*, %struct.TrieNode** %6
%116 = call %struct.TrieNode* @trienode_next(%struct.TrieNode* %115)
%117 = load i8*, i8** %7
%118 = load i16, i16* %8
%119 = load i16, i16* %9
%120 = load %struct.List*, %struct.List** %10
br label %121
121: ; preds = %114, %107
br label %129
122: ; preds = %89
%123 = load %struct.TrieNode*, %struct.TrieNode** %6
%124 = call %struct.TrieNode* @trienode_sibling(%struct.TrieNode* %123)
%125 = load i8*, i8** %7
%126 = load i16, i16* %8
%127 = load i16, i16* %9
%128 = load %struct.List*, %struct.List** %10
br label %129
129: ; preds = %122, %121
br label %130
130: ; preds = %129, %88
br label %131
131: ; preds = %17, %130, %33
ret void
}

LLVM IR (-O2):
%struct.TrieNode = type { i32 }
%struct.List = type { i32 }
%struct.ListNode = type { i32 }
define void @trie_search1(%struct.TrieNode* %0, i8* %1, i16 zeroext %2, i16 zeroext %3, %struct.List* %4) {
%6 = icmp eq %struct.TrieNode* %0, null
br i1 %6, label %53, label %7
7: ; preds = %5, %47
%8 = phi i16 [ %41, %47 ], [ %2, %5 ]
%9 = phi %struct.TrieNode* [ %48, %47 ], [ %0, %5 ]
%10 = icmp ult i16 %8, %3
%11 = zext i1 %10 to i32
%12 = zext i16 %8 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
br label %14
14: ; preds = %7, %50
%15 = phi %struct.TrieNode* [ %9, %7 ], [ %51, %50 ]
%16 = tail call i32 @assert(i32 %11)
%17 = load i8, i8* %13
switch i8 %17, label %35 [
i8 42, label %18
i8 63, label %20
]
18: ; preds = %14
%19 = tail call i32 @trie_search_star(%struct.TrieNode* %15, i8* %1, i16 zeroext %8, i16 zeroext %3, %struct.List* %4)
br label %53
20: ; preds = %14
%21 = add i16 %8, 1
%22 = icmp eq i16 %21, %3
br i1 %22, label %23, label %30
23: ; preds = %20, %23
%24 = phi %struct.TrieNode* [ %28, %23 ], [ %15, %20 ]
%25 = tail call i32 @trienode_values(%struct.TrieNode* %24)
%26 = tail call %struct.ListNode* @listnode_alloc(i32 %25)
%27 = tail call i32 @list_append(%struct.List* %4, %struct.ListNode* %26)
%28 = tail call %struct.TrieNode* @trienode_sibling(%struct.TrieNode* %24)
%29 = icmp eq %struct.TrieNode* %28, null
br i1 %29, label %53, label %23
30: ; preds = %20, %30
%31 = phi %struct.TrieNode* [ %33, %30 ], [ %15, %20 ]
%32 = tail call %struct.TrieNode* @trienode_next(%struct.TrieNode* %31)
tail call void @trie_search1(%struct.TrieNode* %32, i8* %1, i16 zeroext %21, i16 zeroext %3, %struct.List* %4)
%33 = tail call %struct.TrieNode* @trienode_sibling(%struct.TrieNode* %31)
%34 = icmp eq %struct.TrieNode* %33, null
br i1 %34, label %53, label %30
35: ; preds = %14
%36 = tail call i64 @trienode_key(%struct.TrieNode* %15)
%37 = load i8, i8* %13
%38 = tail call i64 @tolower(i8 signext %37)
%39 = icmp eq i64 %36, %38
br i1 %39, label %40, label %50
40: ; preds = %35
%41 = add i16 %8, 1
%42 = icmp eq i16 %41, %3
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = tail call i32 @trienode_values(%struct.TrieNode* %15)
%45 = tail call %struct.ListNode* @listnode_alloc(i32 %44)
%46 = tail call i32 @list_append(%struct.List* %4, %struct.ListNode* %45)
br label %53
47: ; preds = %40
%48 = tail call %struct.TrieNode* @trienode_next(%struct.TrieNode* %15)
%49 = icmp eq %struct.TrieNode* %48, null
br i1 %49, label %53, label %7
50: ; preds = %35
%51 = tail call %struct.TrieNode* @trienode_sibling(%struct.TrieNode* %15)
%52 = icmp eq %struct.TrieNode* %51, null
br i1 %52, label %53, label %14
53: ; preds = %47, %50, %30, %23, %5, %43, %18
ret void
}