#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 bftree_iterator {
  int dummy;
};
struct bftree {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
struct bftree *bftmap_create();
int /*<<< orphan*/ bftmap_del(struct bftree *, char *, int);
int /*<<< orphan*/ bftmap_free(struct bftree *);
int /*<<< orphan*/ bftmap_get(struct bftree *, char *, int);
int /*<<< orphan*/ bftmap_put(struct bftree *, char *, int, char *);
int bftree_count(struct bftree *);
int /*<<< orphan*/ bftree_free_iterator(struct bftree_iterator *);
struct bftree_iterator *bftree_get_iterator(struct bftree *);
int /*<<< orphan*/ *bftree_next(struct bftree_iterator *);
char *malloc(int);
int snprintf(char *, int, char *, int);
void bftmap_example() {
  struct bftree *tree;
  int i, len;
  char buf[100];
  char *val;
  struct bftree_iterator *iter;
  int count;
  tree = bftmap_create();
  for (i = 0; i < 1000; i++) {
    len = snprintf(buf, 100, "key%d", i);
    val = malloc(100);
    snprintf(val, 100, "val%d", i);
    bftmap_put(tree, buf, len, val);
  }
  assert(bftree_count(tree) == 1000);
  count = 0;
  iter = bftree_get_iterator(tree);
  while (bftree_next(iter) != NULL)
    count++;
  bftree_free_iterator(iter);
  assert(count == 1000);
  for (i = 0; i < 10000; i++) {
    len = snprintf(buf, 100, "key%d", i);
    bftmap_del(tree, buf, len);
  }
  for (i = 0; i < 1000; i++) {
    len = snprintf(buf, 100, "key%d", i);
    bftmap_get(tree, buf, len);
  }
  bftmap_free(tree);
}


x86 assembly (clang, -O0):
<bftmap_example>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    $0x0,%al
call   10e0 <bftmap_create@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jge    1256 <bftmap_example+0x96>
lea    -0x80(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x64,%esi
lea    0xe03(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x10(%rbp)
mov    $0x64,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x64,%esi
lea    0xdda(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    -0x88(%rbp),%rcx
call   10d0 <bftmap_put@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11dd <bftmap_example+0x1d>
mov    -0x8(%rbp),%rdi
call   1060 <bftree_count@plt>
cmp    $0x3e8,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
movl   $0x0,-0x94(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <bftree_get_iterator@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rdi
call   1030 <bftree_next@plt>
cmp    $0x0,%rax
je     12b5 <bftmap_example+0xf5>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    128b <bftmap_example+0xcb>
mov    -0x90(%rbp),%rdi
call   1080 <bftree_free_iterator@plt>
cmpl   $0x3e8,-0x94(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x2710,-0xc(%rbp)
jge    1325 <bftmap_example+0x165>
lea    -0x80(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x64,%esi
lea    0xd01(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   10a0 <bftmap_del@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12df <bftmap_example+0x11f>
movl   $0x0,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jge    1372 <bftmap_example+0x1b2>
lea    -0x80(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x64,%esi
lea    0xcb4(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   10b0 <bftmap_get@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    132c <bftmap_example+0x16c>
mov    -0x8(%rbp),%rdi
call   1040 <bftmap_free@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bftmap_example>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
xor    %ebp,%ebp
xor    %eax,%eax
call   10e0 <bftmap_create@plt>
mov    %rax,%r13
mov    %rsp,%r15
lea    0xe22(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x64,%esi
lea    0xe01(%rip),%rdx
mov    %ebp,%ecx
call   1050 <snprintf@plt>
mov    %eax,%ebx
mov    $0x64,%edi
call   10c0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
mov    %ebp,%ecx
call   1050 <snprintf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %r14,%rcx
call   10d0 <bftmap_put@plt>
add    $0x1,%ebp
cmp    $0x3e8,%ebp
jne    11f0 <bftmap_example+0x30>
mov    %r13,%rdi
call   1060 <bftree_count@plt>
xor    %edi,%edi
cmp    $0x3e8,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r13,%rdi
call   1070 <bftree_get_iterator@plt>
mov    %rax,%rbx
mov    $0x3e9,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <bftree_next@plt>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    1270 <bftmap_example+0xb0>
mov    %rbx,%rdi
call   1080 <bftree_free_iterator@plt>
xor    %edi,%edi
test   %ebp,%ebp
sete   %dil
call   1090 <assert@plt>
xor    %ebp,%ebp
lea    0xd62(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1050 <snprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10a0 <bftmap_del@plt>
add    $0x1,%ebp
cmp    $0x2710,%ebp
jne    12b0 <bftmap_example+0xf0>
xor    %ebp,%ebp
lea    0xd1d(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1050 <snprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10b0 <bftmap_get@plt>
add    $0x1,%ebp
cmp    $0x3e8,%ebp
jne    12f0 <bftmap_example+0x130>
mov    %r13,%rdi
call   1040 <bftmap_free@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bftree = type { i32 }
%struct.bftree_iterator = type { i32 }
@.str = [6 x i8] c"key%d\00"
@.str.1 = [6 x i8] c"val%d\00"
define void @bftmap_example() {
%1 = alloca %struct.bftree*
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca i8*
%6 = alloca %struct.bftree_iterator*
%7 = alloca i32
%8 = call %struct.bftree* (...) @bftmap_create()
store %struct.bftree* %8, %struct.bftree** %1
store i32 0, i32* %2
br label %9
9: ; preds = %25, %0
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 1000
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* %2
%15 = call i32 @snprintf(i8* %13, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %3
%16 = call i8* @malloc(i32 100)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = load i32, i32* %2
%19 = call i32 @snprintf(i8* %17, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load %struct.bftree*, %struct.bftree** %1
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%22 = load i32, i32* %3
%23 = load i8*, i8** %5
%24 = call i32 @bftmap_put(%struct.bftree* %20, i8* %21, i32 %22, i8* %23)
br label %25
25: ; preds = %12
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %9
28: ; preds = %9
%29 = load %struct.bftree*, %struct.bftree** %1
%30 = call i32 @bftree_count(%struct.bftree* %29)
%31 = icmp eq i32 %30, 1000
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
store i32 0, i32* %7
%34 = load %struct.bftree*, %struct.bftree** %1
%35 = call %struct.bftree_iterator* @bftree_get_iterator(%struct.bftree* %34)
store %struct.bftree_iterator* %35, %struct.bftree_iterator** %6
br label %36
36: ; preds = %40, %28
%37 = load %struct.bftree_iterator*, %struct.bftree_iterator** %6
%38 = call i32* @bftree_next(%struct.bftree_iterator* %37)
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %36
43: ; preds = %36
%44 = load %struct.bftree_iterator*, %struct.bftree_iterator** %6
%45 = call i32 @bftree_free_iterator(%struct.bftree_iterator* %44)
%46 = load i32, i32* %7
%47 = icmp eq i32 %46, 1000
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
store i32 0, i32* %2
br label %50
50: ; preds = %61, %43
%51 = load i32, i32* %2
%52 = icmp slt i32 %51, 10000
br i1 %52, label %53, label %64
53: ; preds = %50
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%55 = load i32, i32* %2
%56 = call i32 @snprintf(i8* %54, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %55)
store i32 %56, i32* %3
%57 = load %struct.bftree*, %struct.bftree** %1
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%59 = load i32, i32* %3
%60 = call i32 @bftmap_del(%struct.bftree* %57, i8* %58, i32 %59)
br label %61
61: ; preds = %53
%62 = load i32, i32* %2
%63 = add nsw i32 %62, 1
store i32 %63, i32* %2
br label %50
64: ; preds = %50
store i32 0, i32* %2
br label %65
65: ; preds = %76, %64
%66 = load i32, i32* %2
%67 = icmp slt i32 %66, 1000
br i1 %67, label %68, label %79
68: ; preds = %65
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%70 = load i32, i32* %2
%71 = call i32 @snprintf(i8* %69, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %70)
store i32 %71, i32* %3
%72 = load %struct.bftree*, %struct.bftree** %1
%73 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%74 = load i32, i32* %3
%75 = call i32 @bftmap_get(%struct.bftree* %72, i8* %73, i32 %74)
br label %76
76: ; preds = %68
%77 = load i32, i32* %2
%78 = add nsw i32 %77, 1
store i32 %78, i32* %2
br label %65
79: ; preds = %65
%80 = load %struct.bftree*, %struct.bftree** %1
%81 = call i32 @bftmap_free(%struct.bftree* %80)
ret void
}

LLVM IR (-O2):
%struct.bftree = type { i32 }
%struct.bftree_iterator = type { i32 }
@.str = [6 x i8] c"key%d\00"
@.str.1 = [6 x i8] c"val%d\00"
define void @bftmap_example() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call %struct.bftree* (...) @bftmap_create()
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 0, %0 ], [ %10, %4 ]
%6 = call i32 @snprintf(i8* %2, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call dereferenceable_or_null(100) i8* @malloc(i32 100)
%8 = call i32 @snprintf(i8* %7, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%9 = call i32 @bftmap_put(%struct.bftree* %3, i8* %2, i32 %6, i8* %7)
%10 = add nuw nsw i32 %5, 1
%11 = icmp eq i32 %10, 1000
br i1 %11, label %12, label %4
12: ; preds = %4
%13 = call i32 @bftree_count(%struct.bftree* %3)
%14 = icmp eq i32 %13, 1000
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call %struct.bftree_iterator* @bftree_get_iterator(%struct.bftree* %3)
br label %18
18: ; preds = %18, %12
%19 = phi i32 [ 0, %12 ], [ %22, %18 ]
%20 = call i32* @bftree_next(%struct.bftree_iterator* %17)
%21 = icmp eq i32* %20, null
%22 = add nuw nsw i32 %19, 1
br i1 %21, label %23, label %18
23: ; preds = %18
%24 = call i32 @bftree_free_iterator(%struct.bftree_iterator* %17)
%25 = icmp eq i32 %19, 1000
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
br label %28
28: ; preds = %23, %28
%29 = phi i32 [ 0, %23 ], [ %32, %28 ]
%30 = call i32 @snprintf(i8* %2, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = call i32 @bftmap_del(%struct.bftree* %3, i8* %2, i32 %30)
%32 = add nuw nsw i32 %29, 1
%33 = icmp eq i32 %32, 10000
br i1 %33, label %34, label %28
34: ; preds = %28, %34
%35 = phi i32 [ %38, %34 ], [ 0, %28 ]
%36 = call i32 @snprintf(i8* %2, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = call i32 @bftmap_get(%struct.bftree* %3, i8* %2, i32 %36)
%38 = add nuw nsw i32 %35, 1
%39 = icmp eq i32 %38, 1000
br i1 %39, label %40, label %34
40: ; preds = %34
%41 = call i32 @bftmap_free(%struct.bftree* %3)
ret void
}