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

/* Variables and functions */
int /*<<< orphan*/ bftmap_free(struct bftree *);
struct bftree *bftset_create();
int /*<<< orphan*/ bftset_del(struct bftree *, char *, int);
int /*<<< orphan*/ bftset_get(struct bftree *, char *, int);
int /*<<< orphan*/ bftset_put(struct bftree *, char *, int);
char *malloc(int);
int snprintf(char *, int, char *, int);
void bftset_example() {
  struct bftree *tree;
  int i, len;
  char buf[100];
  char *val;
  tree = bftset_create();
  for (i = 0; i < 10000; i++) {
    len = snprintf(buf, 100, "key%d", i);
    val = malloc(100);
    snprintf(val, 100, "val%d", i);
    bftset_put(tree, buf, len);
  }
  for (i = 0; i < 10000; i++) {
    len = snprintf(buf, 100, "key%d", i);
    bftset_del(tree, buf, len);
  }
  for (i = 0; i < 10000; i++) {
    len = snprintf(buf, 100, "key%d", i);
    bftset_get(tree, buf, len);
  }
  bftmap_free(tree);
}


x86 assembly (clang, -O0):
<bftset_example>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    $0x0,%al
call   1070 <bftset_create@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x2710,-0xc(%rbp)
jge    11ff <bftset_example+0x8f>
lea    -0x80(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x64,%esi
lea    0xe53(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x10(%rbp)
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x64,%esi
lea    0xe2a(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1060 <bftset_put@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118d <bftset_example+0x1d>
movl   $0x0,-0xc(%rbp)
cmpl   $0x2710,-0xc(%rbp)
jge    124c <bftset_example+0xdc>
lea    -0x80(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x64,%esi
lea    0xdda(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1050 <bftset_del@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1206 <bftset_example+0x96>
movl   $0x0,-0xc(%rbp)
cmpl   $0x2710,-0xc(%rbp)
jge    1299 <bftset_example+0x129>
lea    -0x80(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x64,%esi
lea    0xd8d(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1090 <bftset_get@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1253 <bftset_example+0xe3>
mov    -0x8(%rbp),%rdi
call   1030 <bftmap_free@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bftset_example>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <bftset_create@plt>
mov    %rax,%r13
lea    0xe6f(%rip),%r14
mov    %rsp,%r15
lea    0xe6b(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %eax,%ebx
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <bftset_put@plt>
add    $0x1,%ebp
cmp    $0x2710,%ebp
jne    11a0 <bftset_example+0x30>
xor    %ebp,%ebp
lea    0xe0f(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <bftset_del@plt>
add    $0x1,%ebp
cmp    $0x2710,%ebp
jne    1200 <bftset_example+0x90>
xor    %ebp,%ebp
lea    0xdcd(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1090 <bftset_get@plt>
add    $0x1,%ebp
cmp    $0x2710,%ebp
jne    1240 <bftset_example+0xd0>
mov    %r13,%rdi
call   1030 <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 }
@.str = [6 x i8] c"key%d\00"
@.str.1 = [6 x i8] c"val%d\00"
define void @bftset_example() {
%1 = alloca %struct.bftree*
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca i8*
%6 = call %struct.bftree* (...) @bftset_create()
store %struct.bftree* %6, %struct.bftree** %1
store i32 0, i32* %2
br label %7
7: ; preds = %22, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 10000
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* %2
%13 = call i32 @snprintf(i8* %11, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %3
%14 = call i8* @malloc(i32 100)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = load i32, i32* %2
%17 = call i32 @snprintf(i8* %15, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load %struct.bftree*, %struct.bftree** %1
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%20 = load i32, i32* %3
%21 = call i32 @bftset_put(%struct.bftree* %18, i8* %19, i32 %20)
br label %22
22: ; preds = %10
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %7
25: ; preds = %7
store i32 0, i32* %2
br label %26
26: ; preds = %37, %25
%27 = load i32, i32* %2
%28 = icmp slt i32 %27, 10000
br i1 %28, label %29, label %40
29: ; preds = %26
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%31 = load i32, i32* %2
%32 = call i32 @snprintf(i8* %30, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %31)
store i32 %32, i32* %3
%33 = load %struct.bftree*, %struct.bftree** %1
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%35 = load i32, i32* %3
%36 = call i32 @bftset_del(%struct.bftree* %33, i8* %34, i32 %35)
br label %37
37: ; preds = %29
%38 = load i32, i32* %2
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %26
40: ; preds = %26
store i32 0, i32* %2
br label %41
41: ; preds = %52, %40
%42 = load i32, i32* %2
%43 = icmp slt i32 %42, 10000
br i1 %43, label %44, label %55
44: ; preds = %41
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%46 = load i32, i32* %2
%47 = call i32 @snprintf(i8* %45, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %46)
store i32 %47, i32* %3
%48 = load %struct.bftree*, %struct.bftree** %1
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%50 = load i32, i32* %3
%51 = call i32 @bftset_get(%struct.bftree* %48, i8* %49, i32 %50)
br label %52
52: ; preds = %44
%53 = load i32, i32* %2
%54 = add nsw i32 %53, 1
store i32 %54, i32* %2
br label %41
55: ; preds = %41
%56 = load %struct.bftree*, %struct.bftree** %1
%57 = call i32 @bftmap_free(%struct.bftree* %56)
ret void
}

LLVM IR (-O2):
%struct.bftree = type { i32 }
@.str = [6 x i8] c"key%d\00"
@.str.1 = [6 x i8] c"val%d\00"
define void @bftset_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* (...) @bftset_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 @bftset_put(%struct.bftree* %3, i8* %2, i32 %6)
%10 = add nuw nsw i32 %5, 1
%11 = icmp eq i32 %10, 10000
br i1 %11, label %12, label %4
12: ; preds = %4, %12
%13 = phi i32 [ %16, %12 ], [ 0, %4 ]
%14 = call i32 @snprintf(i8* %2, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @bftset_del(%struct.bftree* %3, i8* %2, i32 %14)
%16 = add nuw nsw i32 %13, 1
%17 = icmp eq i32 %16, 10000
br i1 %17, label %18, label %12
18: ; preds = %12, %18
%19 = phi i32 [ %22, %18 ], [ 0, %12 ]
%20 = call i32 @snprintf(i8* %2, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32 @bftset_get(%struct.bftree* %3, i8* %2, i32 %20)
%22 = add nuw nsw i32 %19, 1
%23 = icmp eq i32 %22, 10000
br i1 %23, label %24, label %18
24: ; preds = %18
%25 = call i32 @bftmap_free(%struct.bftree* %3)
ret void
}