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

/* Variables and functions */
int /*<<< orphan*/ list_append(struct List *, int /*<<< orphan*/);
int /*<<< orphan*/ listnode_alloc(scalar_t__);
char trienode_key(struct TrieNode *);
struct TrieNode *trienode_next(struct TrieNode *);
struct TrieNode *trienode_sibling(struct TrieNode *);
scalar_t__ trienode_values(struct TrieNode *);
void trie_search_star(struct TrieNode *node, char *keys, unsigned short idx,
                      unsigned short max, struct List *result) {
  struct TrieNode *next;
  int next_idx = idx + 1;
  if (next_idx == max) {
    if (trienode_values(node))
      list_append(result, listnode_alloc(trienode_values(node)));
  } else {
    for (next = node; next; next = trienode_next(next), next_idx++) {
      if (trienode_key(next) != keys[next_idx])
        break;
      if (next_idx == max - 1) {
        if (trienode_values(next))
          list_append(result, listnode_alloc(trienode_values(next)));
        break;
      }
    }
  }
  if (trienode_next(node))
    trie_search_star(trienode_next(node), keys, idx, max, result);
  if (trienode_sibling(node))
    trie_search_star(trienode_sibling(node), keys, idx, max, result);
}


x86 assembly (clang, -O0):
<trie_search_star>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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)
movzwl -0x12(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
movzwl -0x14(%rbp),%ecx
cmp    %ecx,%eax
jne    11e7 <trie_search_star+0x77>
mov    -0x8(%rbp),%rdi
call   1040 <trienode_values@plt>
cmp    $0x0,%rax
je     11e2 <trie_search_star+0x72>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <trienode_values@plt>
mov    %rax,%rdi
call   1030 <listnode_alloc@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1090 <list_append@plt>
jmp    1292 <trie_search_star+0x122>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     128d <trie_search_star+0x11d>
mov    -0x28(%rbp),%rdi
call   1080 <trienode_key@plt>
movsbl %al,%eax
mov    -0x10(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     121f <trie_search_star+0xaf>
jmp    128d <trie_search_star+0x11d>
mov    -0x2c(%rbp),%eax
movzwl -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    126d <trie_search_star+0xfd>
mov    -0x28(%rbp),%rdi
call   1040 <trienode_values@plt>
cmp    $0x0,%rax
je     1268 <trie_search_star+0xf8>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <trienode_values@plt>
mov    %rax,%rdi
call   1030 <listnode_alloc@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1090 <list_append@plt>
jmp    128d <trie_search_star+0x11d>
jmp    1272 <trie_search_star+0x102>
mov    -0x28(%rbp),%rdi
call   1060 <trienode_next@plt>
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ef <trie_search_star+0x7f>
jmp    1292 <trie_search_star+0x122>
mov    -0x8(%rbp),%rdi
call   1060 <trienode_next@plt>
cmp    $0x0,%rax
je     12cc <trie_search_star+0x15c>
mov    -0x8(%rbp),%rdi
call   1060 <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   1070 <trie_search_star@plt>
mov    -0x8(%rbp),%rdi
call   1050 <trienode_sibling@plt>
cmp    $0x0,%rax
je     1306 <trie_search_star+0x196>
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   1070 <trie_search_star@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trie_search_star>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x10(%rsp)
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%r13
lea    -0x1(%rcx),%ebp
mov    %edx,%eax
mov    %rax,0x18(%rsp)
movzwl %r14w,%eax
mov    %eax,0xc(%rsp)
add    $0x1,%r14d
mov    %rcx,0x20(%rsp)
movzwl %cx,%eax
mov    %eax,0x8(%rsp)
cmp    0x20(%rsp),%r14d
jne    11f0 <trie_search_star+0x80>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
call   1040 <trienode_values@plt>
test   %rax,%rax
je     1250 <trie_search_star+0xe0>
mov    %r13,%rdi
call   1040 <trienode_values@plt>
mov    %rax,%rdi
call   1030 <listnode_alloc@plt>
mov    0x10(%rsp),%rdi
mov    %eax,%esi
call   1090 <list_append@plt>
jmp    1250 <trie_search_star+0xe0>
nop
mov    0x18(%rsp),%r15
mov    %r13,%rbx
test   %r13,%r13
je     1250 <trie_search_star+0xe0>
nopl   (%rax)
mov    %rbx,%rdi
call   1080 <trienode_key@plt>
cmp    0x1(%r12,%r15,1),%al
jne    1250 <trie_search_star+0xe0>
add    $0x1,%r15
cmp    %r15,%rbp
je     1230 <trie_search_star+0xc0>
mov    %rbx,%rdi
call   1060 <trienode_next@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1200 <trie_search_star+0x90>
jmp    1250 <trie_search_star+0xe0>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <trienode_values@plt>
test   %rax,%rax
je     1250 <trie_search_star+0xe0>
mov    %rbx,%rdi
jmp    11d4 <trie_search_star+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
call   1060 <trienode_next@plt>
test   %rax,%rax
je     127d <trie_search_star+0x10d>
mov    %r13,%rdi
call   1060 <trienode_next@plt>
mov    %rax,%rdi
mov    %r12,%rsi
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0x10(%rsp),%r8
call   1070 <trie_search_star@plt>
mov    %r13,%rdi
call   1050 <trienode_sibling@plt>
test   %rax,%rax
je     12a5 <trie_search_star+0x135>
mov    %r13,%rdi
call   1050 <trienode_sibling@plt>
mov    %rax,%r13
cmp    0x20(%rsp),%r14d
jne    11f0 <trie_search_star+0x80>
jmp    11c0 <trie_search_star+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TrieNode = type { i32 }
%struct.List = type { i32 }
define void @trie_search_star(%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 i32
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
%13 = load i16, i16* %8
%14 = zext i16 %13 to i32
%15 = add nsw i32 %14, 1
store i32 %15, i32* %12
%16 = load i32, i32* %12
%17 = load i16, i16* %9
%18 = zext i16 %17 to i32
%19 = icmp eq i32 %16, %18
br i1 %19, label %20, label %31
20: ; preds = %5
%21 = load %struct.TrieNode*, %struct.TrieNode** %6
%22 = call i64 @trienode_values(%struct.TrieNode* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load %struct.List*, %struct.List** %10
%26 = load %struct.TrieNode*, %struct.TrieNode** %6
%27 = call i64 @trienode_values(%struct.TrieNode* %26)
%28 = call i32 @listnode_alloc(i64 %27)
%29 = call i32 @list_append(%struct.List* %25, i32 %28)
br label %30
30: ; preds = %24, %20
br label %72
31: ; preds = %5
%32 = load %struct.TrieNode*, %struct.TrieNode** %6
store %struct.TrieNode* %32, %struct.TrieNode** %11
br label %33
33: ; preds = %66, %31
%34 = load %struct.TrieNode*, %struct.TrieNode** %11
%35 = icmp ne %struct.TrieNode* %34, null
br i1 %35, label %36, label %71
36: ; preds = %33
%37 = load %struct.TrieNode*, %struct.TrieNode** %11
%38 = call signext i8 @trienode_key(%struct.TrieNode* %37)
%39 = sext i8 %38 to i32
%40 = load i8*, i8** %7
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %39, %45
br i1 %46, label %47, label %48
47: ; preds = %36
br label %71
48: ; preds = %36
%49 = load i32, i32* %12
%50 = load i16, i16* %9
%51 = zext i16 %50 to i32
%52 = sub nsw i32 %51, 1
%53 = icmp eq i32 %49, %52
br i1 %53, label %54, label %65
54: ; preds = %48
%55 = load %struct.TrieNode*, %struct.TrieNode** %11
%56 = call i64 @trienode_values(%struct.TrieNode* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %54
%59 = load %struct.List*, %struct.List** %10
%60 = load %struct.TrieNode*, %struct.TrieNode** %11
%61 = call i64 @trienode_values(%struct.TrieNode* %60)
%62 = call i32 @listnode_alloc(i64 %61)
%63 = call i32 @list_append(%struct.List* %59, i32 %62)
br label %64
64: ; preds = %58, %54
br label %71
65: ; preds = %48
br label %66
66: ; preds = %65
%67 = load %struct.TrieNode*, %struct.TrieNode** %11
%68 = call %struct.TrieNode* @trienode_next(%struct.TrieNode* %67)
store %struct.TrieNode* %68, %struct.TrieNode** %11
%69 = load i32, i32* %12
%70 = add nsw i32 %69, 1
store i32 %70, i32* %12
br label %33
71: ; preds = %64, %47, %33
br label %72
72: ; preds = %71, %30
%73 = load %struct.TrieNode*, %struct.TrieNode** %6
%74 = call %struct.TrieNode* @trienode_next(%struct.TrieNode* %73)
%75 = icmp ne %struct.TrieNode* %74, null
br i1 %75, label %76, label %83
76: ; preds = %72
%77 = load %struct.TrieNode*, %struct.TrieNode** %6
%78 = call %struct.TrieNode* @trienode_next(%struct.TrieNode* %77)
%79 = load i8*, i8** %7
%80 = load i16, i16* %8
%81 = load i16, i16* %9
%82 = load %struct.List*, %struct.List** %10
br label %83
83: ; preds = %76, %72
%84 = load %struct.TrieNode*, %struct.TrieNode** %6
%85 = call %struct.TrieNode* @trienode_sibling(%struct.TrieNode* %84)
%86 = icmp ne %struct.TrieNode* %85, null
br i1 %86, label %87, label %94
87: ; preds = %83
%88 = load %struct.TrieNode*, %struct.TrieNode** %6
%89 = call %struct.TrieNode* @trienode_sibling(%struct.TrieNode* %88)
%90 = load i8*, i8** %7
%91 = load i16, i16* %8
%92 = load i16, i16* %9
%93 = load %struct.List*, %struct.List** %10
br label %94
94: ; preds = %87, %83
ret void
}

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