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

/* Variables and functions */
struct katcp_type *find_name_type_katcp(struct katcp_dispatch *, char *);
struct katcp_tag *pop_data_type_stack_katcp(struct katcp_stack *,
                                            struct katcp_type *);
scalar_t__ tag_data_katcp(struct katcp_dispatch *, struct katcp_tag *,
                          struct katcp_dbase *, struct katcp_type *);
int tag_dbase_katcp(struct katcp_dispatch *d, struct katcp_dbase *db,
                    struct katcp_stack *tags) {
  struct katcp_tag *t;
  struct katcp_type *tagtype, *dbtype;
  if (db == NULL)
    return -1;
  if (tags == NULL) {
    return 0;
  }
  tagtype = find_name_type_katcp(d, "tag");
  dbtype = find_name_type_katcp(d, "db");
  if (tagtype == NULL || dbtype == NULL)
    return -1;
  while ((t = pop_data_type_stack_katcp(tags, tagtype)) != NULL) {
    if (tag_data_katcp(d, t, db, dbtype) < 0) {
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<tag_dbase_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115b <tag_dbase_katcp+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <tag_dbase_katcp+0xdc>
cmpq   $0x0,-0x20(%rbp)
jne    1172 <tag_dbase_katcp+0x42>
movl   $0x0,-0x4(%rbp)
jmp    120c <tag_dbase_katcp+0xdc>
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1030 <find_name_type_katcp@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1030 <find_name_type_katcp@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11b0 <tag_dbase_katcp+0x80>
cmpq   $0x0,-0x38(%rbp)
jne    11bc <tag_dbase_katcp+0x8c>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <tag_dbase_katcp+0xdc>
jmp    11c1 <tag_dbase_katcp+0x91>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <pop_data_type_stack_katcp@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1205 <tag_dbase_katcp+0xd5>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
call   1050 <tag_data_katcp@plt>
cmp    $0x0,%rax
jge    1200 <tag_dbase_katcp+0xd0>
jmp    1200 <tag_dbase_katcp+0xd0>
jmp    11c1 <tag_dbase_katcp+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tag_dbase_katcp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r13d
test   %rsi,%rsi
je     11a6 <tag_dbase_katcp+0x76>
mov    %rdx,%r14
test   %rdx,%rdx
je     11a3 <tag_dbase_katcp+0x73>
mov    %rsi,%r12
mov    %rdi,%r15
lea    0xea5(%rip),%rsi
call   1030 <find_name_type_katcp@plt>
mov    %rax,%rbx
lea    0xe9a(%rip),%rsi
mov    %r15,%rdi
call   1030 <find_name_type_katcp@plt>
test   %rbx,%rbx
je     11a6 <tag_dbase_katcp+0x76>
mov    %rax,%rbp
test   %rax,%rax
je     11a6 <tag_dbase_katcp+0x76>
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <pop_data_type_stack_katcp@plt>
test   %rax,%rax
je     11a3 <tag_dbase_katcp+0x73>
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
mov    %rbp,%rcx
call   1050 <tag_data_katcp@plt>
jmp    1180 <tag_dbase_katcp+0x50>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.katcp_dispatch = type { i32 }
%struct.katcp_dbase = type { i32 }
%struct.katcp_stack = type { i32 }
%struct.katcp_tag = type { i32 }
%struct.katcp_type = type { i32 }
@.str = [4 x i8] c"tag\00"
@.str.1 = [3 x i8] c"db\00"
define i32 @tag_dbase_katcp(%struct.katcp_dispatch* %0, %struct.katcp_dbase* %1, %struct.katcp_stack* %2) {
%4 = alloca i32
%5 = alloca %struct.katcp_dispatch*
%6 = alloca %struct.katcp_dbase*
%7 = alloca %struct.katcp_stack*
%8 = alloca %struct.katcp_tag*
%9 = alloca %struct.katcp_type*
%10 = alloca %struct.katcp_type*
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %5
store %struct.katcp_dbase* %1, %struct.katcp_dbase** %6
store %struct.katcp_stack* %2, %struct.katcp_stack** %7
%11 = load %struct.katcp_dbase*, %struct.katcp_dbase** %6
%12 = icmp eq %struct.katcp_dbase* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %45
14: ; preds = %3
%15 = load %struct.katcp_stack*, %struct.katcp_stack** %7
%16 = icmp eq %struct.katcp_stack* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 0, i32* %4
br label %45
18: ; preds = %14
%19 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%20 = call %struct.katcp_type* @find_name_type_katcp(%struct.katcp_dispatch* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store %struct.katcp_type* %20, %struct.katcp_type** %9
%21 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%22 = call %struct.katcp_type* @find_name_type_katcp(%struct.katcp_dispatch* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store %struct.katcp_type* %22, %struct.katcp_type** %10
%23 = load %struct.katcp_type*, %struct.katcp_type** %9
%24 = icmp eq %struct.katcp_type* %23, null
br i1 %24, label %28, label %25
25: ; preds = %18
%26 = load %struct.katcp_type*, %struct.katcp_type** %10
%27 = icmp eq %struct.katcp_type* %26, null
br i1 %27, label %28, label %29
28: ; preds = %25, %18
store i32 -1, i32* %4
br label %45
29: ; preds = %25
br label %30
30: ; preds = %43, %29
%31 = load %struct.katcp_stack*, %struct.katcp_stack** %7
%32 = load %struct.katcp_type*, %struct.katcp_type** %9
%33 = call %struct.katcp_tag* @pop_data_type_stack_katcp(%struct.katcp_stack* %31, %struct.katcp_type* %32)
store %struct.katcp_tag* %33, %struct.katcp_tag** %8
%34 = icmp ne %struct.katcp_tag* %33, null
br i1 %34, label %35, label %44
35: ; preds = %30
%36 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%37 = load %struct.katcp_tag*, %struct.katcp_tag** %8
%38 = load %struct.katcp_dbase*, %struct.katcp_dbase** %6
%39 = load %struct.katcp_type*, %struct.katcp_type** %10
%40 = call i64 @tag_data_katcp(%struct.katcp_dispatch* %36, %struct.katcp_tag* %37, %struct.katcp_dbase* %38, %struct.katcp_type* %39)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %35
br label %43
43: ; preds = %42, %35
br label %30
44: ; preds = %30
store i32 0, i32* %4
br label %45
45: ; preds = %44, %28, %17, %13
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
%struct.katcp_dbase = type { i32 }
%struct.katcp_stack = type { i32 }
%struct.katcp_type = type { i32 }
%struct.katcp_tag = type { i32 }
@.str = [4 x i8] c"tag\00"
@.str.1 = [3 x i8] c"db\00"
define i32 @tag_dbase_katcp(%struct.katcp_dispatch* %0, %struct.katcp_dbase* %1, %struct.katcp_stack* %2) {
%4 = icmp eq %struct.katcp_dbase* %1, null
br i1 %4, label %21, label %5
5: ; preds = %3
%6 = icmp eq %struct.katcp_stack* %2, null
br i1 %6, label %21, label %7
7: ; preds = %5
%8 = tail call %struct.katcp_type* @find_name_type_katcp(%struct.katcp_dispatch* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = tail call %struct.katcp_type* @find_name_type_katcp(%struct.katcp_dispatch* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq %struct.katcp_type* %8, null
%11 = icmp eq %struct.katcp_type* %9, null
%12 = select i1 %10, i1 true, i1 %11
br i1 %12, label %21, label %13
13: ; preds = %7
%14 = tail call %struct.katcp_tag* @pop_data_type_stack_katcp(%struct.katcp_stack* %2, %struct.katcp_type* %8)
%15 = icmp eq %struct.katcp_tag* %14, null
br i1 %15, label %21, label %16
16: ; preds = %13, %16
%17 = phi %struct.katcp_tag* [ %19, %16 ], [ %14, %13 ]
%18 = tail call i64 @tag_data_katcp(%struct.katcp_dispatch* %0, %struct.katcp_tag* %17, %struct.katcp_dbase* %1, %struct.katcp_type* %9)
%19 = tail call %struct.katcp_tag* @pop_data_type_stack_katcp(%struct.katcp_stack* %2, %struct.katcp_type* %8)
%20 = icmp eq %struct.katcp_tag* %19, null
br i1 %20, label %21, label %16
21: ; preds = %16, %13, %7, %5, %3
%22 = phi i32 [ -1, %3 ], [ 0, %5 ], [ -1, %7 ], [ 0, %13 ], [ 0, %16 ]
ret i32 %22
}