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

/* Variables and functions */
int add_string_parse_katcl(struct katcl_parse *, int, char *);
struct katcl_parse *create_parse_katcl();
int /*<<< orphan*/ destroy_parse_katcl(struct katcl_parse *);
void *search_named_type_katcp(struct katcp_dispatch *, char *, char *,
                              int /*<<< orphan*/ *);
scalar_t__ set_dbase_katcp(struct katcp_dispatch *, struct katcl_parse *);
void *parse_dbase_type_katcp(struct katcp_dispatch *d, char **str) {
  struct katcl_parse *p;
  int i, err;
  if (str == NULL || str[0] == NULL || str[1] == NULL)
    return NULL;
  p = create_parse_katcl();
  if (p == NULL)
    return NULL;
  err = add_string_parse_katcl(p, 0x10 | 0x01, "?set");
  for (i = 0; str[i] != NULL; i++) {
    err += add_string_parse_katcl(p, 0x10 | ((str[i + 1] == NULL) ? 0x02 : 0x0),
                                  str[i]);
  }
  if (err < 0) {
    destroy_parse_katcl(p);
    return NULL;
  }
  if (set_dbase_katcp(d, p) < 0) {
    destroy_parse_katcl(p);
    return NULL;
  }
  destroy_parse_katcl(p);
  return search_named_type_katcp(d, "db", str[0], NULL);
}


x86 assembly (clang, -O0):
<parse_dbase_type_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1188 <parse_dbase_type_katcp+0x38>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1188 <parse_dbase_type_katcp+0x38>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1195 <parse_dbase_type_katcp+0x45>
movq   $0x0,-0x8(%rbp)
jmp    12aa <parse_dbase_type_katcp+0x15a>
mov    $0x0,%al
call   1030 <create_parse_katcl@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b8 <parse_dbase_type_katcp+0x68>
movq   $0x0,-0x8(%rbp)
jmp    12aa <parse_dbase_type_katcp+0x15a>
mov    -0x20(%rbp),%rdi
mov    $0x11,%esi
lea    0xe38(%rip),%rdx
call   1040 <add_string_parse_katcl@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1235 <parse_dbase_type_katcp+0xe5>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
xor    %esi,%esi
mov    $0x2,%eax
cmp    $0x0,%rcx
cmove  %eax,%esi
or     $0x10,%esi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
call   1040 <add_string_parse_katcl@plt>
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d7 <parse_dbase_type_katcp+0x87>
cmpl   $0x0,-0x28(%rbp)
jge    1255 <parse_dbase_type_katcp+0x105>
mov    -0x20(%rbp),%rdi
call   1070 <destroy_parse_katcl@plt>
movq   $0x0,-0x8(%rbp)
jmp    12aa <parse_dbase_type_katcp+0x15a>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <set_dbase_katcp@plt>
cmp    $0x0,%rax
jge    1282 <parse_dbase_type_katcp+0x132>
mov    -0x20(%rbp),%rdi
call   1070 <destroy_parse_katcl@plt>
movq   $0x0,-0x8(%rbp)
jmp    12aa <parse_dbase_type_katcp+0x15a>
mov    -0x20(%rbp),%rdi
call   1070 <destroy_parse_katcl@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xd68(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <search_named_type_katcp@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_dbase_type_katcp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rsi,%rsi
je     1228 <parse_dbase_type_katcp+0xd8>
mov    %rsi,%r15
cmpq   $0x0,(%rsi)
je     1228 <parse_dbase_type_katcp+0xd8>
cmpq   $0x0,0x8(%r15)
je     1228 <parse_dbase_type_katcp+0xd8>
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <create_parse_katcl@plt>
test   %rax,%rax
je     1228 <parse_dbase_type_katcp+0xd8>
mov    %rax,%r12
lea    0xe6a(%rip),%rdx
mov    %rax,%rdi
mov    $0x11,%esi
call   1040 <add_string_parse_katcl@plt>
mov    %eax,%ebp
mov    (%r15),%rdx
test   %rdx,%rdx
je     11e5 <parse_dbase_type_katcp+0x95>
lea    0x8(%r15),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
cmpq   $0x0,(%rbx)
sete   %al
lea    (%rax,%rax,1),%esi
add    $0x10,%esi
mov    %r12,%rdi
call   1040 <add_string_parse_katcl@plt>
add    %eax,%ebp
mov    (%rbx),%rdx
add    $0x8,%rbx
test   %rdx,%rdx
jne    11c0 <parse_dbase_type_katcp+0x70>
test   %ebp,%ebp
js     1220 <parse_dbase_type_katcp+0xd0>
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <set_dbase_katcp@plt>
mov    %rax,%rbp
mov    %r12,%rdi
call   1070 <destroy_parse_katcl@plt>
test   %rbp,%rbp
js     1228 <parse_dbase_type_katcp+0xd8>
mov    (%r15),%rdx
lea    0xdf7(%rip),%rsi
mov    %r14,%rdi
xor    %ecx,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <search_named_type_katcp@plt>
mov    %r12,%rdi
call   1070 <destroy_parse_katcl@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.katcp_dispatch = type { i32 }
%struct.katcl_parse = type { i32 }
@.str = [5 x i8] c"?set\00"
@.str.1 = [3 x i8] c"db\00"
define i8* @parse_dbase_type_katcp(%struct.katcp_dispatch* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca %struct.katcp_dispatch*
%5 = alloca i8**
%6 = alloca %struct.katcl_parse*
%7 = alloca i32
%8 = alloca i32
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = icmp eq i8** %9, null
br i1 %10, label %21, label %11
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %16, %11, %2
store i8* null, i8** %3
br label %82
22: ; preds = %16
%23 = call %struct.katcl_parse* (...) @create_parse_katcl()
store %struct.katcl_parse* %23, %struct.katcl_parse** %6
%24 = load %struct.katcl_parse*, %struct.katcl_parse** %6
%25 = icmp eq %struct.katcl_parse* %24, null
br i1 %25, label %26, label %27
26: ; preds = %22
store i8* null, i8** %3
br label %82
27: ; preds = %22
%28 = load %struct.katcl_parse*, %struct.katcl_parse** %6
%29 = call i32 @add_string_parse_katcl(%struct.katcl_parse* %28, i32 17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %29, i32* %8
store i32 0, i32* %7
br label %30
30: ; preds = %57, %27
%31 = load i8**, i8*** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %60
37: ; preds = %30
%38 = load %struct.katcl_parse*, %struct.katcl_parse** %6
%39 = load i8**, i8*** %5
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %39, i64 %42
%44 = load i8*, i8** %43
%45 = icmp eq i8* %44, null
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 2, i32 0
%48 = or i32 16, %47
%49 = load i8**, i8*** %5
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 @add_string_parse_katcl(%struct.katcl_parse* %38, i32 %48, i8* %53)
%55 = load i32, i32* %8
%56 = add nsw i32 %55, %54
store i32 %56, i32* %8
br label %57
57: ; preds = %37
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %30
60: ; preds = %30
%61 = load i32, i32* %8
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load %struct.katcl_parse*, %struct.katcl_parse** %6
%65 = call i32 @destroy_parse_katcl(%struct.katcl_parse* %64)
store i8* null, i8** %3
br label %82
66: ; preds = %60
%67 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%68 = load %struct.katcl_parse*, %struct.katcl_parse** %6
%69 = call i64 @set_dbase_katcp(%struct.katcp_dispatch* %67, %struct.katcl_parse* %68)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %66
%72 = load %struct.katcl_parse*, %struct.katcl_parse** %6
%73 = call i32 @destroy_parse_katcl(%struct.katcl_parse* %72)
store i8* null, i8** %3
br label %82
74: ; preds = %66
%75 = load %struct.katcl_parse*, %struct.katcl_parse** %6
%76 = call i32 @destroy_parse_katcl(%struct.katcl_parse* %75)
%77 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 0
%80 = load i8*, i8** %79
%81 = call i8* @search_named_type_katcp(%struct.katcp_dispatch* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %80, i32* null)
store i8* %81, i8** %3
br label %82
82: ; preds = %74, %71, %63, %26, %21
%83 = load i8*, i8** %3
ret i8* %83
}

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
%struct.katcl_parse = type { i32 }
@.str = [5 x i8] c"?set\00"
@.str.1 = [3 x i8] c"db\00"
define i8* @parse_dbase_type_katcp(%struct.katcp_dispatch* %0, i8** %1) {
%3 = icmp eq i8** %1, null
br i1 %3, label %43, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = icmp eq i8* %5, null
br i1 %6, label %43, label %7
7: ; preds = %4
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %43, label %11
11: ; preds = %7
%12 = tail call %struct.katcl_parse* (...) @create_parse_katcl()
%13 = icmp eq %struct.katcl_parse* %12, null
br i1 %13, label %43, label %14
14: ; preds = %11
%15 = tail call i32 @add_string_parse_katcl(%struct.katcl_parse* %12, i32 17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %1
%17 = icmp eq i8* %16, null
br i1 %17, label %31, label %18
18: ; preds = %14, %18
%19 = phi i64 [ %22, %18 ], [ 0, %14 ]
%20 = phi i8* [ %29, %18 ], [ %16, %14 ]
%21 = phi i32 [ %28, %18 ], [ %15, %14 ]
%22 = add nuw nsw i64 %19, 1
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
%26 = select i1 %25, i32 18, i32 16
%27 = tail call i32 @add_string_parse_katcl(%struct.katcl_parse* %12, i32 %26, i8* %20)
%28 = add nsw i32 %27, %21
%29 = load i8*, i8** %23
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %18
31: ; preds = %18, %14
%32 = phi i32 [ %15, %14 ], [ %28, %18 ]
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = tail call i32 @destroy_parse_katcl(%struct.katcl_parse* %12)
br label %43
36: ; preds = %31
%37 = tail call i64 @set_dbase_katcp(%struct.katcp_dispatch* %0, %struct.katcl_parse* %12)
%38 = icmp slt i64 %37, 0
%39 = tail call i32 @destroy_parse_katcl(%struct.katcl_parse* %12)
br i1 %38, label %43, label %40
40: ; preds = %36
%41 = load i8*, i8** %1
%42 = tail call i8* @search_named_type_katcp(%struct.katcp_dispatch* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %41, i32* null)
br label %43
43: ; preds = %36, %11, %2, %4, %7, %40, %34
%44 = phi i8* [ null, %34 ], [ %42, %40 ], [ null, %7 ], [ null, %4 ], [ null, %2 ], [ null, %11 ], [ null, %36 ]
ret i8* %44
}