#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_tobject {
  int dummy;
};
struct katcp_tag {
  int dummy;
};
struct katcp_dispatch {
  int dummy;
};

/* Variables and functions */
struct katcp_tobject *create_tobject_katcp(void *, struct katcp_type *,
                                           int /*<<< orphan*/);
int /*<<< orphan*/ destroy_tobject_katcp(struct katcp_tobject *);
scalar_t__ tag_tobject_katcp(struct katcp_dispatch *, struct katcp_tag *,
                             struct katcp_tobject *);
int tag_data_katcp(struct katcp_dispatch *d, struct katcp_tag *t, void *data,
                   struct katcp_type *type) {
  struct katcp_tobject *to;
  to = create_tobject_katcp(data, type, 0);
  if (to == NULL)
    return -1;
  if (tag_tobject_katcp(d, t, to) < 0) {
    destroy_tobject_katcp(to);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tag_data_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1050 <create_tobject_katcp@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1172 <tag_data_katcp+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <tag_data_katcp+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <tag_tobject_katcp@plt>
cmp    $0x0,%rax
jge    11a2 <tag_data_katcp+0x72>
mov    -0x30(%rbp),%rdi
call   1040 <destroy_tobject_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <tag_data_katcp+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tag_data_katcp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
mov    %rdx,%rdi
mov    %rcx,%rsi
xor    %edx,%edx
call   1050 <create_tobject_katcp@plt>
test   %rax,%rax
je     116f <tag_data_katcp+0x3f>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <tag_tobject_katcp@plt>
test   %rax,%rax
jns    1174 <tag_data_katcp+0x44>
mov    %rbx,%rdi
call   1040 <destroy_tobject_katcp@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.katcp_dispatch = type { i32 }
%struct.katcp_tag = type { i32 }
%struct.katcp_type = type { i32 }
%struct.katcp_tobject = type { i32 }
define i32 @tag_data_katcp(%struct.katcp_dispatch* %0, %struct.katcp_tag* %1, i8* %2, %struct.katcp_type* %3) {
%5 = alloca i32
%6 = alloca %struct.katcp_dispatch*
%7 = alloca %struct.katcp_tag*
%8 = alloca i8*
%9 = alloca %struct.katcp_type*
%10 = alloca %struct.katcp_tobject*
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %6
store %struct.katcp_tag* %1, %struct.katcp_tag** %7
store i8* %2, i8** %8
store %struct.katcp_type* %3, %struct.katcp_type** %9
%11 = load i8*, i8** %8
%12 = load %struct.katcp_type*, %struct.katcp_type** %9
%13 = call %struct.katcp_tobject* @create_tobject_katcp(i8* %11, %struct.katcp_type* %12, i32 0)
store %struct.katcp_tobject* %13, %struct.katcp_tobject** %10
%14 = load %struct.katcp_tobject*, %struct.katcp_tobject** %10
%15 = icmp eq %struct.katcp_tobject* %14, null
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %27
17: ; preds = %4
%18 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %6
%19 = load %struct.katcp_tag*, %struct.katcp_tag** %7
%20 = load %struct.katcp_tobject*, %struct.katcp_tobject** %10
%21 = call i64 @tag_tobject_katcp(%struct.katcp_dispatch* %18, %struct.katcp_tag* %19, %struct.katcp_tobject* %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load %struct.katcp_tobject*, %struct.katcp_tobject** %10
%25 = call i32 @destroy_tobject_katcp(%struct.katcp_tobject* %24)
store i32 -1, i32* %5
br label %27
26: ; preds = %17
store i32 0, i32* %5
br label %27
27: ; preds = %26, %23, %16
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
%struct.katcp_tag = type { i32 }
%struct.katcp_type = type { i32 }
%struct.katcp_tobject = type { i32 }
define i32 @tag_data_katcp(%struct.katcp_dispatch* %0, %struct.katcp_tag* %1, i8* %2, %struct.katcp_type* %3) {
%5 = tail call %struct.katcp_tobject* @create_tobject_katcp(i8* %2, %struct.katcp_type* %3, i32 0)
%6 = icmp eq %struct.katcp_tobject* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i64 @tag_tobject_katcp(%struct.katcp_dispatch* %0, %struct.katcp_tag* %1, %struct.katcp_tobject* %5)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @destroy_tobject_katcp(%struct.katcp_tobject* %5)
br label %12
12: ; preds = %7, %4, %10
%13 = phi i32 [ -1, %10 ], [ -1, %4 ], [ 0, %7 ]
ret i32 %13
}