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

/* Variables and functions */
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
struct trie *trie_create();
int /*<<< orphan*/ trie_destroy(struct trie *);
void *trie_insert(struct trie *, char *, int *);
int *trie_lookup(struct trie *, char *);
int *trie_lookup_prefix(struct trie *, char *, int *);
int main(int argc, char *argv[]) {
  int *a, *b, *c, *d;
  a = malloc(sizeof(int));
  *a = 1;
  b = malloc(sizeof(int));
  *b = 2;
  c = malloc(sizeof(int));
  *c = 3;
  d = malloc(sizeof(int));
  *d = 4;
  struct trie *test_trie = trie_create();
  printf("created new trie at %p\n", test_trie);
  void *inserted = trie_insert(test_trie, "aa", a);
  printf("inserted %d at %p\n", *a, inserted);
  int *trie_value = trie_lookup(test_trie, "aa");
  printf("lookup got %d\n", *trie_value);
  inserted = trie_insert(test_trie, "ab", b);
  printf("inserted %d at %p\n", *a, inserted);
  trie_value = trie_lookup(test_trie, "ab");
  printf("lookup got %d\n", *trie_value);
  inserted = trie_insert(test_trie, "ccz", c);
  printf("inserted %d at %p\n", *a, inserted);
  trie_value = trie_lookup(test_trie, "ccz");
  printf("lookup got %d\n", *trie_value);
  trie_value = trie_lookup_prefix(test_trie, "c", NULL);
  printf("prefix lookup got %d\n", *trie_value);
  trie_value = trie_lookup_prefix(test_trie, "a", d);
  printf("ambiguous prefix lookup got %d\n", *trie_value);
  trie_destroy(test_trie);
  printf("freed trie\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x2,(%rax)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x3,(%rax)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movl   $0x4,(%rax)
mov    $0x0,%al
call   1060 <trie_create@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe06(%rip),%rsi
call   1080 <trie_insert@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x40(%rbp),%rdx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1050 <trie_lookup@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdc4(%rip),%rsi
call   1080 <trie_insert@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x40(%rbp),%rdx
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    0xd98(%rip),%rsi
call   1050 <trie_lookup@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%esi
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd6f(%rip),%rsi
call   1080 <trie_insert@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x40(%rbp),%rdx
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    0xd43(%rip),%rsi
call   1050 <trie_lookup@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%esi
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    0xd1f(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <trie_lookup_prefix@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%esi
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xcd3(%rip),%rsi
call   1030 <trie_lookup_prefix@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%esi
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1090 <trie_destroy@plt>
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
movl   $0x1,(%rax)
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
movl   $0x2,(%rax)
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,0x8(%rsp)
movl   $0x3,(%rax)
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,0x10(%rsp)
movl   $0x4,(%rax)
xor    %eax,%eax
call   1070 <trie_create@plt>
mov    %rax,%rbx
lea    0xe11(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe18(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1090 <trie_insert@plt>
mov    (%r15),%esi
lea    0xe03(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <trie_lookup@plt>
mov    (%rax),%esi
lea    0xe0f(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xde4(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1090 <trie_insert@plt>
mov    (%r15),%esi
mov    %r14,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <trie_lookup@plt>
mov    (%rax),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdab(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    0x8(%rsp),%rdx
call   1090 <trie_insert@plt>
mov    (%r15),%esi
mov    %r14,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <trie_lookup@plt>
mov    (%rax),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd71(%rip),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1030 <trie_lookup_prefix@plt>
mov    (%rax),%esi
lea    0xd6a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd34(%rip),%rsi
mov    %rbx,%rdi
mov    0x10(%rsp),%rdx
call   1030 <trie_lookup_prefix@plt>
mov    (%rax),%esi
lea    0xd3c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   10a0 <trie_destroy@plt>
lea    0xd46(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.trie = type { i32 }
@.str = [24 x i8] c"created new trie at %p\0A\00"
@.str.1 = [3 x i8] c"aa\00"
@.str.2 = [19 x i8] c"inserted %d at %p\0A\00"
@.str.3 = [15 x i8] c"lookup got %d\0A\00"
@.str.4 = [3 x i8] c"ab\00"
@.str.5 = [4 x i8] c"ccz\00"
@.str.6 = [2 x i8] c"c\00"
@.str.7 = [22 x i8] c"prefix lookup got %d\0A\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [32 x i8] c"ambiguous prefix lookup got %d\0A\00"
@.str.10 = [12 x i8] c"freed trie\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca %struct.trie*
%11 = alloca i8*
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32* @malloc(i32 4)
store i32* %13, i32** %6
%14 = load i32*, i32** %6
store i32 1, i32* %14
%15 = call i32* @malloc(i32 4)
store i32* %15, i32** %7
%16 = load i32*, i32** %7
store i32 2, i32* %16
%17 = call i32* @malloc(i32 4)
store i32* %17, i32** %8
%18 = load i32*, i32** %8
store i32 3, i32* %18
%19 = call i32* @malloc(i32 4)
store i32* %19, i32** %9
%20 = load i32*, i32** %9
store i32 4, i32* %20
%21 = call %struct.trie* (...) @trie_create()
store %struct.trie* %21, %struct.trie** %10
%22 = load %struct.trie*, %struct.trie** %10
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %struct.trie* %22)
%24 = load %struct.trie*, %struct.trie** %10
%25 = load i32*, i32** %6
%26 = call i8* @trie_insert(%struct.trie* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %25)
store i8* %26, i8** %11
%27 = load i32*, i32** %6
%28 = load i32, i32* %27
%29 = load i8*, i8** %11
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %28, i8* %29)
%31 = load %struct.trie*, %struct.trie** %10
%32 = call i32* @trie_lookup(%struct.trie* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %12
%33 = load i32*, i32** %12
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = load %struct.trie*, %struct.trie** %10
%37 = load i32*, i32** %7
%38 = call i8* @trie_insert(%struct.trie* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %37)
store i8* %38, i8** %11
%39 = load i32*, i32** %6
%40 = load i32, i32* %39
%41 = load i8*, i8** %11
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %40, i8* %41)
%43 = load %struct.trie*, %struct.trie** %10
%44 = call i32* @trie_lookup(%struct.trie* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %44, i32** %12
%45 = load i32*, i32** %12
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = load %struct.trie*, %struct.trie** %10
%49 = load i32*, i32** %8
%50 = call i8* @trie_insert(%struct.trie* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %49)
store i8* %50, i8** %11
%51 = load i32*, i32** %6
%52 = load i32, i32* %51
%53 = load i8*, i8** %11
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %52, i8* %53)
%55 = load %struct.trie*, %struct.trie** %10
%56 = call i32* @trie_lookup(%struct.trie* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32* %56, i32** %12
%57 = load i32*, i32** %12
%58 = load i32, i32* %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %58)
%60 = load %struct.trie*, %struct.trie** %10
%61 = call i32* @trie_lookup_prefix(%struct.trie* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32* null)
store i32* %61, i32** %12
%62 = load i32*, i32** %12
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %63)
%65 = load %struct.trie*, %struct.trie** %10
%66 = load i32*, i32** %9
%67 = call i32* @trie_lookup_prefix(%struct.trie* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32* %66)
store i32* %67, i32** %12
%68 = load i32*, i32** %12
%69 = load i32, i32* %68
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %69)
%71 = load %struct.trie*, %struct.trie** %10
%72 = call i32 @trie_destroy(%struct.trie* %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.trie = type { i32 }
@.str = [24 x i8] c"created new trie at %p\0A\00"
@.str.1 = [3 x i8] c"aa\00"
@.str.2 = [19 x i8] c"inserted %d at %p\0A\00"
@.str.3 = [15 x i8] c"lookup got %d\0A\00"
@.str.4 = [3 x i8] c"ab\00"
@.str.5 = [4 x i8] c"ccz\00"
@.str.6 = [2 x i8] c"c\00"
@.str.7 = [22 x i8] c"prefix lookup got %d\0A\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [32 x i8] c"ambiguous prefix lookup got %d\0A\00"
@str = [11 x i8] c"freed trie\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @malloc(i32 4)
store i32 1, i32* %3
%4 = tail call i32* @malloc(i32 4)
store i32 2, i32* %4
%5 = tail call i32* @malloc(i32 4)
store i32 3, i32* %5
%6 = tail call i32* @malloc(i32 4)
store i32 4, i32* %6
%7 = tail call %struct.trie* (...) @trie_create()
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %struct.trie* %7)
%9 = tail call i8* @trie_insert(%struct.trie* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = load i32, i32* %3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %10, i8* %9)
%12 = tail call i32* @trie_lookup(%struct.trie* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = tail call i8* @trie_insert(%struct.trie* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%16 = load i32, i32* %3
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %16, i8* %15)
%18 = tail call i32* @trie_lookup(%struct.trie* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%19 = load i32, i32* %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = tail call i8* @trie_insert(%struct.trie* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %5)
%22 = load i32, i32* %3
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %22, i8* %21)
%24 = tail call i32* @trie_lookup(%struct.trie* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%25 = load i32, i32* %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = tail call i32* @trie_lookup_prefix(%struct.trie* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32* null)
%28 = load i32, i32* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %28)
%30 = tail call i32* @trie_lookup_prefix(%struct.trie* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32* %6)
%31 = load i32, i32* %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %31)
%33 = tail call i32 @trie_destroy(%struct.trie* %7)
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
ret i32 0
}