main(argc, argv) int argc;
char **argv;
{
  char test[4096];
  int ret;
  init_dbz_channel();
  ret = add_mid("<tttt.eeee.ssss.tttt>", "THIS_IS_1ST_PATH");
  if (ret)
    printf("add 1st mid OK\n");
  else
    printf("add 1st mid failed\n");
  ret = add_mid("<bbbb.cccc.dddd.eeee>", "THIS_IS_2ND_PATH");
  if (ret)
    printf("add 2st mid OK\n");
  else
    printf("add 2st mid failed\n");
  ret = query_mid("<tttt.eeee.ssss.tttt>", test);
  if (ret)
    printf("query 1st ok : '%s'\n", test);
  else
    printf("query 1st failed\n");
  ret = query_mid("<bbbb.cccc.dddd.eeee>", test);
  if (ret)
    printf("query 2nd ok : '%s'\n", test);
  else
    printf("query 2nd failed\n");
  ret = query_mid("<no.such.item>", test);
  if (ret)
    printf("query no_such_item found ??? : '%s'\n", test);
  else
    printf("query no_such_item not found\n");
  close_dbz_channel();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <init_dbz_channel@plt>
lea    0xe89(%rip),%rdi
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1070 <add_mid@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
je     11ab <main+0x5b>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b9 <main+0x69>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8b(%rip),%rdi
lea    0xe9a(%rip),%rsi
mov    $0x0,%al
call   1070 <add_mid@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
je     11f4 <main+0xa4>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1202 <main+0xb2>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1010(%rbp),%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1030 <query_mid@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
je     1244 <main+0xf4>
lea    -0x1010(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1252 <main+0x102>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1010(%rbp),%rsi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <query_mid@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
je     1294 <main+0x144>
lea    -0x1010(%rbp),%rsi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a2 <main+0x152>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1010(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <query_mid@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
je     12e4 <main+0x194>
lea    -0x1010(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12f2 <main+0x1a2>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <close_dbz_channel@plt>
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1000,%rsp
xor    %eax,%eax
call   1070 <init_dbz_channel@plt>
lea    0xe8a(%rip),%rbx
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <add_mid@plt>
test   %eax,%eax
lea    0xf1c(%rip),%rax
lea    0xf89(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
lea    0xe80(%rip),%rdi
lea    0xe8f(%rip),%rsi
xor    %eax,%eax
call   1080 <add_mid@plt>
test   %eax,%eax
lea    0xf01(%rip),%rax
lea    0xf4c(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <query_mid@plt>
test   %eax,%eax
je     11f2 <main+0x92>
lea    0xe68(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11fe <main+0x9e>
lea    0xed9(%rip),%rdi
call   1040 <puts@plt>
lea    0xe22(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <query_mid@plt>
test   %eax,%eax
je     1226 <main+0xc6>
lea    0xe49(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1232 <main+0xd2>
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
lea    0xe3f(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <query_mid@plt>
test   %eax,%eax
je     125a <main+0xfa>
lea    0xe39(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1266 <main+0x106>
lea    0xe93(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <close_dbz_channel@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"<tttt.eeee.ssss.tttt>\00"
@.str.1 = [17 x i8] c"THIS_IS_1ST_PATH\00"
@.str.2 = [16 x i8] c"add 1st mid OK\0A\00"
@.str.3 = [20 x i8] c"add 1st mid failed\0A\00"
@.str.4 = [22 x i8] c"<bbbb.cccc.dddd.eeee>\00"
@.str.5 = [17 x i8] c"THIS_IS_2ND_PATH\00"
@.str.6 = [16 x i8] c"add 2st mid OK\0A\00"
@.str.7 = [20 x i8] c"add 2st mid failed\0A\00"
@.str.8 = [21 x i8] c"query 1st ok : '%s'\0A\00"
@.str.9 = [18 x i8] c"query 1st failed\0A\00"
@.str.10 = [21 x i8] c"query 2nd ok : '%s'\0A\00"
@.str.11 = [18 x i8] c"query 2nd failed\0A\00"
@.str.12 = [15 x i8] c"<no.such.item>\00"
@.str.13 = [37 x i8] c"query no_such_item found ??? : '%s'\0A\00"
@.str.14 = [30 x i8] c"query no_such_item not found\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @init_dbz_channel()
%9 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @add_mid to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
%17 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @add_mid to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %24
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%26 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @query_mid to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %30)
br label %34
32: ; preds = %24
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%36 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @query_mid to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %35)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i8* %40)
br label %44
42: ; preds = %34
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
br label %44
44: ; preds = %42, %39
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%46 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @query_mid to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i8* %45)
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i8* %50)
br label %54
52: ; preds = %44
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.14, i64 0, i64 0))
br label %54
54: ; preds = %52, %49
%55 = call i32 (...) @close_dbz_channel()
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [22 x i8] c"<tttt.eeee.ssss.tttt>\00"
@.str.1 = [17 x i8] c"THIS_IS_1ST_PATH\00"
@.str.4 = [22 x i8] c"<bbbb.cccc.dddd.eeee>\00"
@.str.5 = [17 x i8] c"THIS_IS_2ND_PATH\00"
@.str.8 = [21 x i8] c"query 1st ok : '%s'\0A\00"
@.str.10 = [21 x i8] c"query 2nd ok : '%s'\0A\00"
@.str.12 = [15 x i8] c"<no.such.item>\00"
@.str.13 = [37 x i8] c"query no_such_item found ??? : '%s'\0A\00"
@str = [19 x i8] c"add 1st mid failed\00"
@str.15 = [19 x i8] c"add 2st mid failed\00"
@str.16 = [17 x i8] c"query 1st failed\00"
@str.17 = [17 x i8] c"query 2nd failed\00"
@str.18 = [29 x i8] c"query no_such_item not found\00"
@str.19 = [15 x i8] c"add 2st mid OK\00"
@str.20 = [15 x i8] c"add 1st mid OK\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @init_dbz_channel()
%6 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @add_mid to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @str.20, i64 0, i64 0)
%9 = tail call i32 @puts(i8* dereferenceable(1) %8)
%10 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @add_mid to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.15, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @str.19, i64 0, i64 0)
%13 = tail call i32 @puts(i8* dereferenceable(1) %12)
%14 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @query_mid to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %4)
br label %20
18: ; preds = %2
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.16, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @query_mid to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i8* %4)
br label %27
25: ; preds = %20
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.17, i64 0, i64 0))
br label %27
27: ; preds = %25, %23
%28 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @query_mid to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i8* %4)
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i8* %4)
br label %34
32: ; preds = %27
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.18, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
%35 = call i32 (...) @close_dbz_channel()
ret i32 0
}