#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 katcp_type {
  int dummy;
};
struct katcp_stack {
  int dummy;
};
struct katcp_dispatch {
  int dummy;
};
struct katcp_dbase {
  int dummy;
};
struct katcl_parse {
  int dummy;
};

/* Variables and functions */
struct katcp_stack *create_stack_katcp();
int /*<<< orphan*/ create_tag_katcp(char *, int /*<<< orphan*/);
int /*<<< orphan*/ destroy_stack_katcp(struct katcp_stack *);
struct katcp_type *find_name_type_katcp(struct katcp_dispatch *, char *);
int get_count_parse_katcl(struct katcl_parse *);
char *get_string_parse_katcl(struct katcl_parse *, int);
int /*<<< orphan*/ push_stack_katcp(struct katcp_stack *, void *,
                                    struct katcp_type *);
scalar_t__ replace_dbase_values_katcp(struct katcp_dispatch *,
                                      struct katcp_dbase *, char *,
                                      struct katcp_stack *,
                                      struct katcp_stack *);
struct katcp_dbase *search_named_type_katcp(struct katcp_dispatch *, char *,
                                            char *, int /*<<< orphan*/ *);
void *search_type_katcp(struct katcp_dispatch *, struct katcp_type *, char *,
                        int /*<<< orphan*/);
scalar_t__ store_kv_dbase_katcp(struct katcp_dispatch *, char *, char *,
                                struct katcp_stack *, struct katcp_stack *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strdup(char *);
int set_dbase_katcp(struct katcp_dispatch *d, struct katcl_parse *p) {
  struct katcp_dbase *db;
  struct katcp_stack *stack, *tags;
  struct katcp_type *stringtype, *tagtype;
  int i, count, state;
  char *key, *schema, *temp;
  void *data;
  key = get_string_parse_katcl(p, 1);
  if (key == NULL)
    return -1;
  stringtype = find_name_type_katcp(d, "string");
  if (stringtype == NULL)
    return -1;
  tagtype = find_name_type_katcp(d, "tag");
  if (tagtype == NULL)
    return -1;
  stack = create_stack_katcp();
  tags = create_stack_katcp();
  count = get_count_parse_katcl(p);
  state = 0;
  schema = NULL;
  for (i = 2; i < count; i++) {
    temp = get_string_parse_katcl(p, i);
    switch (state) {
    case 0:
      if (strcmp(temp, "schema") == 0) {
        state = 1;
        break;
      }
    case 2:
      if (strcmp(temp, "tags") == 0) {
        state = 3;
        break;
      }
      data = search_type_katcp(d, stringtype, temp, strdup(temp));
      if (data != NULL && push_stack_katcp(stack, data, stringtype) < 0) {
        destroy_stack_katcp(stack);
        destroy_stack_katcp(tags);
        return -1;
      }
      break;
    case 1:
      schema = temp;
      state = 2;
      break;
    case 3:
      data = search_type_katcp(d, tagtype, temp, create_tag_katcp(temp, 0));
      if (data != NULL && push_stack_katcp(tags, data, tagtype) < 0) {
        destroy_stack_katcp(stack);
        destroy_stack_katcp(tags);
        return -1;
      }
      break;
    }
  }
  db = search_named_type_katcp(d, "db", key, NULL);
  if (db != NULL) {
    if (replace_dbase_values_katcp(d, db, schema, stack, tags) < 0) {
      destroy_stack_katcp(stack);
      destroy_stack_katcp(tags);
      return -1;
    }
  } else {
    if (store_kv_dbase_katcp(d, key, schema, stack, tags) < 0) {
      destroy_stack_katcp(stack);
      destroy_stack_katcp(tags);
      return -1;
    }
  }
  destroy_stack_katcp(tags);
  return 0;
}


x86 assembly (clang, -O0):
<set_dbase_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1060 <get_string_parse_katcl@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    120c <set_dbase_katcp+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1534 <set_dbase_katcp+0x364>
mov    -0x10(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1050 <find_name_type_katcp@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1237 <set_dbase_katcp+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    1534 <set_dbase_katcp+0x364>
mov    -0x10(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   1050 <find_name_type_katcp@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1262 <set_dbase_katcp+0x92>
movl   $0xffffffff,-0x4(%rbp)
jmp    1534 <set_dbase_katcp+0x364>
mov    $0x0,%al
call   1040 <create_stack_katcp@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <create_stack_katcp@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <get_count_parse_katcl@plt>
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movq   $0x0,-0x60(%rbp)
movl   $0x2,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x48(%rbp),%eax
jge    1471 <set_dbase_katcp+0x2a1>
mov    -0x18(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1060 <get_string_parse_katcl@plt>
mov    %rax,-0x68(%rbp)
mov    -0x4c(%rbp),%eax
mov    %rax,-0x78(%rbp)
sub    $0x3,%rax
ja     145e <set_dbase_katcp+0x28e>
mov    -0x78(%rbp),%rax
lea    0xd2e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x68(%rbp),%rdi
lea    0xd35(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1300 <set_dbase_katcp+0x130>
movl   $0x1,-0x4c(%rbp)
jmp    145e <set_dbase_katcp+0x28e>
jmp    1305 <set_dbase_katcp+0x135>
mov    -0x68(%rbp),%rdi
lea    0xd12(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    132a <set_dbase_katcp+0x15a>
movl   $0x3,-0x4c(%rbp)
jmp    145e <set_dbase_katcp+0x28e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x68(%rbp),%rdi
call   10f0 <strdup@plt>
mov    -0x90(%rbp),%rdi
mov    -0x88(%rbp),%rsi
mov    -0x80(%rbp),%rdx
mov    %eax,%ecx
call   1090 <search_type_katcp@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     13b1 <set_dbase_katcp+0x1e1>
mov    -0x28(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   10e0 <push_stack_katcp@plt>
cmp    $0x0,%eax
jge    13b1 <set_dbase_katcp+0x1e1>
mov    -0x28(%rbp),%rdi
call   1030 <destroy_stack_katcp@plt>
mov    -0x30(%rbp),%rdi
call   1030 <destroy_stack_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1534 <set_dbase_katcp+0x364>
jmp    145e <set_dbase_katcp+0x28e>
mov    -0x68(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0x2,-0x4c(%rbp)
jmp    145e <set_dbase_katcp+0x28e>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x68(%rbp),%rdi
xor    %esi,%esi
call   10c0 <create_tag_katcp@plt>
mov    -0xa8(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
mov    -0x98(%rbp),%rdx
mov    %eax,%ecx
call   1090 <search_type_katcp@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     1459 <set_dbase_katcp+0x289>
mov    -0x30(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   10e0 <push_stack_katcp@plt>
cmp    $0x0,%eax
jge    1459 <set_dbase_katcp+0x289>
mov    -0x28(%rbp),%rdi
call   1030 <destroy_stack_katcp@plt>
mov    -0x30(%rbp),%rdi
call   1030 <destroy_stack_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1534 <set_dbase_katcp+0x364>
jmp    145e <set_dbase_katcp+0x28e>
jmp    1463 <set_dbase_katcp+0x293>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    129a <set_dbase_katcp+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x58(%rbp),%rdx
lea    0xba7(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <search_named_type_katcp@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     14de <set_dbase_katcp+0x30e>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   10d0 <replace_dbase_values_katcp@plt>
cmp    $0x0,%rax
jge    14d9 <set_dbase_katcp+0x309>
mov    -0x28(%rbp),%rdi
call   1030 <destroy_stack_katcp@plt>
mov    -0x30(%rbp),%rdi
call   1030 <destroy_stack_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1534 <set_dbase_katcp+0x364>
jmp    1524 <set_dbase_katcp+0x354>
mov    -0x10(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   10b0 <store_kv_dbase_katcp@plt>
cmp    $0x0,%rax
jge    151f <set_dbase_katcp+0x34f>
mov    -0x28(%rbp),%rdi
call   1030 <destroy_stack_katcp@plt>
mov    -0x30(%rbp),%rdi
call   1030 <destroy_stack_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1534 <set_dbase_katcp+0x364>
jmp    1524 <set_dbase_katcp+0x354>
mov    -0x30(%rbp),%rdi
call   1030 <destroy_stack_katcp@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_dbase_katcp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r13
mov    %rdi,%rbp
mov    %rsi,%rdi
mov    $0x1,%esi
call   1060 <get_string_parse_katcl@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     1419 <set_dbase_katcp+0x249>
mov    %rax,%rbx
lea    0xe06(%rip),%rsi
mov    %rbp,%rdi
call   1050 <find_name_type_katcp@plt>
test   %rax,%rax
je     1419 <set_dbase_katcp+0x249>
mov    %rax,%r12
lea    0xdf2(%rip),%rsi
mov    %rbp,%rdi
call   1050 <find_name_type_katcp@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     1419 <set_dbase_katcp+0x249>
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <create_stack_katcp@plt>
mov    %rax,(%rsp)
xor    %eax,%eax
call   1040 <create_stack_katcp@plt>
mov    %rax,0x10(%rsp)
mov    %r13,%rdi
call   10a0 <get_count_parse_katcl@plt>
cmp    $0x3,%eax
mov    %rbp,0x20(%rsp)
mov    %rbx,0x28(%rsp)
jl     13b5 <set_dbase_katcp+0x1e5>
mov    %eax,%r15d
mov    %r12,0x30(%rsp)
mov    $0x2,%r12d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    0x18(%rsp),%rbx
jmp    12a8 <set_dbase_katcp+0xd8>
nopl   0x0(%rax)
mov    $0x2,%r14d
mov    %rbp,0x8(%rsp)
add    $0x1,%r12d
cmp    %r12d,%r15d
je     13bc <set_dbase_katcp+0x1ec>
mov    %r13,%rdi
mov    %r12d,%esi
call   1060 <get_string_parse_katcl@plt>
cmp    $0x3,%r14d
ja     129b <set_dbase_katcp+0xcb>
mov    %rax,%rbp
mov    %r14d,%eax
lea    0xd3a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %rbp,%rdi
lea    0xd42(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     13aa <set_dbase_katcp+0x1da>
mov    %rbp,%rdi
lea    0xd32(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1395 <set_dbase_katcp+0x1c5>
mov    %rbp,%rdi
call   10f0 <strdup@plt>
mov    0x20(%rsp),%rdi
mov    0x30(%rsp),%rbx
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %eax,%ecx
call   1090 <search_type_katcp@plt>
test   %rax,%rax
je     13a0 <set_dbase_katcp+0x1d0>
mov    (%rsp),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   10e0 <push_stack_katcp@plt>
test   %eax,%eax
mov    0x18(%rsp),%rbx
jns    129b <set_dbase_katcp+0xcb>
jmp    1400 <set_dbase_katcp+0x230>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
xor    %esi,%esi
call   10c0 <create_tag_katcp@plt>
mov    0x20(%rsp),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %eax,%ecx
call   1090 <search_type_katcp@plt>
mov    $0x3,%r14d
test   %rax,%rax
je     129b <set_dbase_katcp+0xcb>
mov    0x10(%rsp),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   10e0 <push_stack_katcp@plt>
test   %eax,%eax
jns    129b <set_dbase_katcp+0xcb>
jmp    1400 <set_dbase_katcp+0x230>
mov    $0x3,%r14d
jmp    129b <set_dbase_katcp+0xcb>
mov    0x18(%rsp),%rbx
jmp    129b <set_dbase_katcp+0xcb>
mov    $0x1,%r14d
jmp    129b <set_dbase_katcp+0xcb>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0xc64(%rip),%rsi
xor    %r14d,%r14d
mov    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    0x28(%rsp),%rbp
mov    %rbp,%rdx
xor    %ecx,%ecx
call   1070 <search_named_type_katcp@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     142b <set_dbase_katcp+0x25b>
mov    %rax,%rsi
mov    0x8(%rsp),%rdx
mov    (%rsp),%rcx
mov    0x10(%rsp),%r8
call   10d0 <replace_dbase_values_katcp@plt>
test   %rax,%rax
jns    140f <set_dbase_katcp+0x23f>
mov    (%rsp),%rdi
call   1030 <destroy_stack_katcp@plt>
mov    $0xffffffff,%r14d
mov    0x10(%rsp),%rdi
call   1030 <destroy_stack_katcp@plt>
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rsi
mov    0x8(%rsp),%rdx
mov    (%rsp),%rcx
mov    0x10(%rsp),%r8
call   10b0 <store_kv_dbase_katcp@plt>
test   %rax,%rax
jns    140f <set_dbase_katcp+0x23f>
jmp    1400 <set_dbase_katcp+0x230>

LLVM IR (-O0):
%struct.katcp_dispatch = type { i32 }
%struct.katcl_parse = type { i32 }
%struct.katcp_dbase = type { i32 }
%struct.katcp_stack = type { i32 }
%struct.katcp_type = type { i32 }
@.str = [7 x i8] c"string\00"
@.str.1 = [4 x i8] c"tag\00"
@.str.2 = [7 x i8] c"schema\00"
@.str.3 = [5 x i8] c"tags\00"
@.str.4 = [3 x i8] c"db\00"
define i32 @set_dbase_katcp(%struct.katcp_dispatch* %0, %struct.katcl_parse* %1) {
%3 = alloca i32
%4 = alloca %struct.katcp_dispatch*
%5 = alloca %struct.katcl_parse*
%6 = alloca %struct.katcp_dbase*
%7 = alloca %struct.katcp_stack*
%8 = alloca %struct.katcp_stack*
%9 = alloca %struct.katcp_type*
%10 = alloca %struct.katcp_type*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %4
store %struct.katcl_parse* %1, %struct.katcl_parse** %5
%18 = load %struct.katcl_parse*, %struct.katcl_parse** %5
%19 = call i8* @get_string_parse_katcl(%struct.katcl_parse* %18, i32 1)
store i8* %19, i8** %14
%20 = load i8*, i8** %14
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 -1, i32* %3
br label %145
23: ; preds = %2
%24 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%25 = call %struct.katcp_type* @find_name_type_katcp(%struct.katcp_dispatch* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store %struct.katcp_type* %25, %struct.katcp_type** %9
%26 = load %struct.katcp_type*, %struct.katcp_type** %9
%27 = icmp eq %struct.katcp_type* %26, null
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 -1, i32* %3
br label %145
29: ; preds = %23
%30 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%31 = call %struct.katcp_type* @find_name_type_katcp(%struct.katcp_dispatch* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store %struct.katcp_type* %31, %struct.katcp_type** %10
%32 = load %struct.katcp_type*, %struct.katcp_type** %10
%33 = icmp eq %struct.katcp_type* %32, null
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 -1, i32* %3
br label %145
35: ; preds = %29
%36 = call %struct.katcp_stack* (...) @create_stack_katcp()
store %struct.katcp_stack* %36, %struct.katcp_stack** %7
%37 = call %struct.katcp_stack* (...) @create_stack_katcp()
store %struct.katcp_stack* %37, %struct.katcp_stack** %8
%38 = load %struct.katcl_parse*, %struct.katcl_parse** %5
%39 = call i32 @get_count_parse_katcl(%struct.katcl_parse* %38)
store i32 %39, i32* %12
store i32 0, i32* %13
store i8* null, i8** %15
store i32 2, i32* %11
br label %40
40: ; preds = %105, %35
%41 = load i32, i32* %11
%42 = load i32, i32* %12
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %108
44: ; preds = %40
%45 = load %struct.katcl_parse*, %struct.katcl_parse** %5
%46 = load i32, i32* %11
%47 = call i8* @get_string_parse_katcl(%struct.katcl_parse* %45, i32 %46)
store i8* %47, i8** %16
%48 = load i32, i32* %13
switch i32 %48, label %104 [
i32 0, label %49
i32 2, label %55
i32 1, label %81
i32 3, label %83
]
49: ; preds = %44
%50 = load i8*, i8** %16
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %49
store i32 1, i32* %13
br label %104
54: ; preds = %49
br label %55
55: ; preds = %44, %54
%56 = load i8*, i8** %16
%57 = call i32 @strcmp(i8* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %55
store i32 3, i32* %13
br label %104
60: ; preds = %55
%61 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%62 = load %struct.katcp_type*, %struct.katcp_type** %9
%63 = load i8*, i8** %16
%64 = load i8*, i8** %16
%65 = call i32 @strdup(i8* %64)
%66 = call i8* @search_type_katcp(%struct.katcp_dispatch* %61, %struct.katcp_type* %62, i8* %63, i32 %65)
store i8* %66, i8** %17
%67 = load i8*, i8** %17
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %80
69: ; preds = %60
%70 = load %struct.katcp_stack*, %struct.katcp_stack** %7
%71 = load i8*, i8** %17
%72 = load %struct.katcp_type*, %struct.katcp_type** %9
%73 = call i32 @push_stack_katcp(%struct.katcp_stack* %70, i8* %71, %struct.katcp_type* %72)
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %80
75: ; preds = %69
%76 = load %struct.katcp_stack*, %struct.katcp_stack** %7
%77 = call i32 @destroy_stack_katcp(%struct.katcp_stack* %76)
%78 = load %struct.katcp_stack*, %struct.katcp_stack** %8
%79 = call i32 @destroy_stack_katcp(%struct.katcp_stack* %78)
store i32 -1, i32* %3
br label %145
80: ; preds = %69, %60
br label %104
81: ; preds = %44
%82 = load i8*, i8** %16
store i8* %82, i8** %15
store i32 2, i32* %13
br label %104
83: ; preds = %44
%84 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%85 = load %struct.katcp_type*, %struct.katcp_type** %10
%86 = load i8*, i8** %16
%87 = load i8*, i8** %16
%88 = call i32 @create_tag_katcp(i8* %87, i32 0)
%89 = call i8* @search_type_katcp(%struct.katcp_dispatch* %84, %struct.katcp_type* %85, i8* %86, i32 %88)
store i8* %89, i8** %17
%90 = load i8*, i8** %17
%91 = icmp ne i8* %90, null
br i1 %91, label %92, label %103
92: ; preds = %83
%93 = load %struct.katcp_stack*, %struct.katcp_stack** %8
%94 = load i8*, i8** %17
%95 = load %struct.katcp_type*, %struct.katcp_type** %10
%96 = call i32 @push_stack_katcp(%struct.katcp_stack* %93, i8* %94, %struct.katcp_type* %95)
%97 = icmp slt i32 %96, 0
br i1 %97, label %98, label %103
98: ; preds = %92
%99 = load %struct.katcp_stack*, %struct.katcp_stack** %7
%100 = call i32 @destroy_stack_katcp(%struct.katcp_stack* %99)
%101 = load %struct.katcp_stack*, %struct.katcp_stack** %8
%102 = call i32 @destroy_stack_katcp(%struct.katcp_stack* %101)
store i32 -1, i32* %3
br label %145
103: ; preds = %92, %83
br label %104
104: ; preds = %44, %103, %81, %80, %59, %53
br label %105
105: ; preds = %104
%106 = load i32, i32* %11
%107 = add nsw i32 %106, 1
store i32 %107, i32* %11
br label %40
108: ; preds = %40
%109 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%110 = load i8*, i8** %14
%111 = call %struct.katcp_dbase* @search_named_type_katcp(%struct.katcp_dispatch* %109, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %110, i32* null)
store %struct.katcp_dbase* %111, %struct.katcp_dbase** %6
%112 = load %struct.katcp_dbase*, %struct.katcp_dbase** %6
%113 = icmp ne %struct.katcp_dbase* %112, null
br i1 %113, label %114, label %128
114: ; preds = %108
%115 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%116 = load %struct.katcp_dbase*, %struct.katcp_dbase** %6
%117 = load i8*, i8** %15
%118 = load %struct.katcp_stack*, %struct.katcp_stack** %7
%119 = load %struct.katcp_stack*, %struct.katcp_stack** %8
%120 = call i64 @replace_dbase_values_katcp(%struct.katcp_dispatch* %115, %struct.katcp_dbase* %116, i8* %117, %struct.katcp_stack* %118, %struct.katcp_stack* %119)
%121 = icmp slt i64 %120, 0
br i1 %121, label %122, label %127
122: ; preds = %114
%123 = load %struct.katcp_stack*, %struct.katcp_stack** %7
%124 = call i32 @destroy_stack_katcp(%struct.katcp_stack* %123)
%125 = load %struct.katcp_stack*, %struct.katcp_stack** %8
%126 = call i32 @destroy_stack_katcp(%struct.katcp_stack* %125)
store i32 -1, i32* %3
br label %145
127: ; preds = %114
br label %142
128: ; preds = %108
%129 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%130 = load i8*, i8** %14
%131 = load i8*, i8** %15
%132 = load %struct.katcp_stack*, %struct.katcp_stack** %7
%133 = load %struct.katcp_stack*, %struct.katcp_stack** %8
%134 = call i64 @store_kv_dbase_katcp(%struct.katcp_dispatch* %129, i8* %130, i8* %131, %struct.katcp_stack* %132, %struct.katcp_stack* %133)
%135 = icmp slt i64 %134, 0
br i1 %135, label %136, label %141
136: ; preds = %128
%137 = load %struct.katcp_stack*, %struct.katcp_stack** %7
%138 = call i32 @destroy_stack_katcp(%struct.katcp_stack* %137)
%139 = load %struct.katcp_stack*, %struct.katcp_stack** %8
%140 = call i32 @destroy_stack_katcp(%struct.katcp_stack* %139)
store i32 -1, i32* %3
br label %145
141: ; preds = %128
br label %142
142: ; preds = %141, %127
%143 = load %struct.katcp_stack*, %struct.katcp_stack** %8
%144 = call i32 @destroy_stack_katcp(%struct.katcp_stack* %143)
store i32 0, i32* %3
br label %145
145: ; preds = %142, %136, %122, %98, %75, %34, %28, %22
%146 = load i32, i32* %3
ret i32 %146
}

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
%struct.katcl_parse = type { i32 }
%struct.katcp_type = type { i32 }
%struct.katcp_stack = type { i32 }
%struct.katcp_dbase = type { i32 }
@.str = [7 x i8] c"string\00"
@.str.1 = [4 x i8] c"tag\00"
@.str.2 = [7 x i8] c"schema\00"
@.str.3 = [5 x i8] c"tags\00"
@.str.4 = [3 x i8] c"db\00"
define i32 @set_dbase_katcp(%struct.katcp_dispatch* %0, %struct.katcl_parse* %1) {
%3 = tail call i8* @get_string_parse_katcl(%struct.katcl_parse* %1, i32 1)
%4 = icmp eq i8* %3, null
br i1 %4, label %62, label %5
5: ; preds = %2
%6 = tail call %struct.katcp_type* @find_name_type_katcp(%struct.katcp_dispatch* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq %struct.katcp_type* %6, null
br i1 %7, label %62, label %8
8: ; preds = %5
%9 = tail call %struct.katcp_type* @find_name_type_katcp(%struct.katcp_dispatch* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq %struct.katcp_type* %9, null
br i1 %10, label %62, label %11
11: ; preds = %8
%12 = tail call %struct.katcp_stack* (...) @create_stack_katcp()
%13 = tail call %struct.katcp_stack* (...) @create_stack_katcp()
%14 = tail call i32 @get_count_parse_katcl(%struct.katcl_parse* %1)
%15 = icmp sgt i32 %14, 2
br i1 %15, label %16, label %47
16: ; preds = %11, %42
%17 = phi i8* [ %44, %42 ], [ null, %11 ]
%18 = phi i32 [ %45, %42 ], [ 2, %11 ]
%19 = phi i32 [ %43, %42 ], [ 0, %11 ]
%20 = tail call i8* @get_string_parse_katcl(%struct.katcl_parse* %1, i32 %18)
switch i32 %19, label %42 [
i32 0, label %21
i32 2, label %24
i32 1, label %34
i32 3, label %35
]
21: ; preds = %16
%22 = tail call i32 @strcmp(i8* dereferenceable(1) %20, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %42, label %24
24: ; preds = %21, %16
%25 = tail call i32 @strcmp(i8* dereferenceable(1) %20, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %42, label %27
27: ; preds = %24
%28 = tail call i32 @strdup(i8* %20)
%29 = tail call i8* @search_type_katcp(%struct.katcp_dispatch* %0, %struct.katcp_type* %6, i8* %20, i32 %28)
%30 = icmp eq i8* %29, null
br i1 %30, label %42, label %31
31: ; preds = %27
%32 = tail call i32 @push_stack_katcp(%struct.katcp_stack* %12, i8* %29, %struct.katcp_type* %6)
%33 = icmp slt i32 %32, 0
br i1 %33, label %57, label %42
34: ; preds = %16
br label %42
35: ; preds = %16
%36 = tail call i32 @create_tag_katcp(i8* %20, i32 0)
%37 = tail call i8* @search_type_katcp(%struct.katcp_dispatch* %0, %struct.katcp_type* %9, i8* %20, i32 %36)
%38 = icmp eq i8* %37, null
br i1 %38, label %42, label %39
39: ; preds = %35
%40 = tail call i32 @push_stack_katcp(%struct.katcp_stack* %13, i8* %37, %struct.katcp_type* %9)
%41 = icmp slt i32 %40, 0
br i1 %41, label %57, label %42
42: ; preds = %24, %21, %34, %16, %31, %27, %39, %35
%43 = phi i32 [ %19, %16 ], [ 3, %39 ], [ 3, %35 ], [ 2, %34 ], [ %19, %31 ], [ %19, %27 ], [ 1, %21 ], [ 3, %24 ]
%44 = phi i8* [ %17, %16 ], [ %17, %39 ], [ %17, %35 ], [ %20, %34 ], [ %17, %31 ], [ %17, %27 ], [ %17, %21 ], [ %17, %24 ]
%45 = add nuw nsw i32 %18, 1
%46 = icmp eq i32 %45, %14
br i1 %46, label %47, label %16
47: ; preds = %42, %11
%48 = phi i8* [ null, %11 ], [ %44, %42 ]
%49 = tail call %struct.katcp_dbase* @search_named_type_katcp(%struct.katcp_dispatch* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %3, i32* null)
%50 = icmp eq %struct.katcp_dbase* %49, null
br i1 %50, label %54, label %51
51: ; preds = %47
%52 = tail call i64 @replace_dbase_values_katcp(%struct.katcp_dispatch* %0, %struct.katcp_dbase* %49, i8* %48, %struct.katcp_stack* %12, %struct.katcp_stack* %13)
%53 = icmp slt i64 %52, 0
br i1 %53, label %57, label %59
54: ; preds = %47
%55 = tail call i64 @store_kv_dbase_katcp(%struct.katcp_dispatch* %0, i8* %3, i8* %48, %struct.katcp_stack* %12, %struct.katcp_stack* %13)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %39, %31, %54, %51
%58 = tail call i32 @destroy_stack_katcp(%struct.katcp_stack* %12)
br label %59
59: ; preds = %57, %51, %54
%60 = phi i32 [ 0, %54 ], [ 0, %51 ], [ -1, %57 ]
%61 = tail call i32 @destroy_stack_katcp(%struct.katcp_stack* %13)
br label %62
62: ; preds = %59, %8, %5, %2
%63 = phi i32 [ -1, %2 ], [ -1, %5 ], [ -1, %8 ], [ %60, %59 ]
ret i32 %63
}