#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_dict {
  int dummy;
};

/* Variables and functions */
scalar_t__ add_dict_katcp(struct katcp_dict *, char *, struct katcp_tobject *);
struct katcp_tobject *create_tobject_katcp(void *, struct katcp_type *,
                                           int /*<<< orphan*/);
int /*<<< orphan*/ destroy_tobject_katcp(struct katcp_tobject *);
scalar_t__ update_dict_katcp(struct katcp_dict *, char *,
                             struct katcp_tobject *);
int add_type_dict_katcp(struct katcp_dict *dt, char *key, struct katcp_type *t,
                        void *data) {
  struct katcp_tobject *to;
  to = create_tobject_katcp(data, t, 0);
  if (to == NULL)
    return -1;
  if (add_dict_katcp(dt, key, to) < 0) {
    if (update_dict_katcp(dt, key, to) < 0) {
      destroy_tobject_katcp(to);
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<add_type_dict_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    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <create_tobject_katcp@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1182 <add_type_dict_katcp+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <add_type_dict_katcp+0x99>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <add_dict_katcp@plt>
cmp    $0x0,%rax
jge    11d2 <add_type_dict_katcp+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <update_dict_katcp@plt>
cmp    $0x0,%rax
jge    11cd <add_type_dict_katcp+0x8d>
mov    -0x30(%rbp),%rdi
call   1040 <destroy_tobject_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <add_type_dict_katcp+0x99>
jmp    11d2 <add_type_dict_katcp+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_type_dict_katcp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
mov    %rcx,%rdi
mov    %rdx,%rsi
xor    %edx,%edx
call   1050 <create_tobject_katcp@plt>
test   %rax,%rax
je     1192 <add_type_dict_katcp+0x52>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1060 <add_dict_katcp@plt>
test   %rax,%rax
jns    1197 <add_type_dict_katcp+0x57>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <update_dict_katcp@plt>
test   %rax,%rax
jns    1197 <add_type_dict_katcp+0x57>
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_dict = type { i32 }
%struct.katcp_type = type { i32 }
%struct.katcp_tobject = type { i32 }
define i32 @add_type_dict_katcp(%struct.katcp_dict* %0, i8* %1, %struct.katcp_type* %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.katcp_dict*
%7 = alloca i8*
%8 = alloca %struct.katcp_type*
%9 = alloca i8*
%10 = alloca %struct.katcp_tobject*
store %struct.katcp_dict* %0, %struct.katcp_dict** %6
store i8* %1, i8** %7
store %struct.katcp_type* %2, %struct.katcp_type** %8
store i8* %3, i8** %9
%11 = load i8*, i8** %9
%12 = load %struct.katcp_type*, %struct.katcp_type** %8
%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 %34
17: ; preds = %4
%18 = load %struct.katcp_dict*, %struct.katcp_dict** %6
%19 = load i8*, i8** %7
%20 = load %struct.katcp_tobject*, %struct.katcp_tobject** %10
%21 = call i64 @add_dict_katcp(%struct.katcp_dict* %18, i8* %19, %struct.katcp_tobject* %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %17
%24 = load %struct.katcp_dict*, %struct.katcp_dict** %6
%25 = load i8*, i8** %7
%26 = load %struct.katcp_tobject*, %struct.katcp_tobject** %10
%27 = call i64 @update_dict_katcp(%struct.katcp_dict* %24, i8* %25, %struct.katcp_tobject* %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load %struct.katcp_tobject*, %struct.katcp_tobject** %10
%31 = call i32 @destroy_tobject_katcp(%struct.katcp_tobject* %30)
store i32 -1, i32* %5
br label %34
32: ; preds = %23
br label %33
33: ; preds = %32, %17
store i32 0, i32* %5
br label %34
34: ; preds = %33, %29, %16
%35 = load i32, i32* %5
ret i32 %35
}

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