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

/* Variables and functions */
scalar_t__ append_ts_katcp(struct katcp_dispatch *, struct katcp_time *);
struct katcp_time *create_ts_katcp(int (*)(struct katcp_dispatch *, void *),
                                   void *);
int /*<<< orphan*/ destroy_ts_katcp(struct katcp_dispatch *,
                                    struct katcp_time *);
struct katcp_time *find_ts_katcp(struct katcp_dispatch *, void *);
struct katcp_time *
find_make_append_ts_katcp(struct katcp_dispatch *d,
                          int (*call)(struct katcp_dispatch *d, void *data),
                          void *data) {
  struct katcp_time *ts;
  ts = find_ts_katcp(d, data);
  if (ts == NULL) {
    ts = create_ts_katcp(call, data);
    if (ts == NULL) {
      return NULL;
    }
    if (append_ts_katcp(d, ts) < 0) {
      destroy_ts_katcp(d, ts);
      return NULL;
    }
  }
  return ts;
}


x86 assembly (clang, -O0):
<find_make_append_ts_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <find_ts_katcp@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cf <find_make_append_ts_katcp+0x8f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <create_ts_katcp@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1199 <find_make_append_ts_katcp+0x59>
movq   $0x0,-0x8(%rbp)
jmp    11d7 <find_make_append_ts_katcp+0x97>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <append_ts_katcp@plt>
cmp    $0x0,%rax
jge    11ca <find_make_append_ts_katcp+0x8a>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <destroy_ts_katcp@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d7 <find_make_append_ts_katcp+0x97>
jmp    11cf <find_make_append_ts_katcp+0x8f>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_make_append_ts_katcp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rdx,%rsi
call   1030 <find_ts_katcp@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1191 <find_make_append_ts_katcp+0x51>
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <create_ts_katcp@plt>
test   %rax,%rax
je     118f <find_make_append_ts_katcp+0x4f>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <append_ts_katcp@plt>
test   %rax,%rax
jns    1191 <find_make_append_ts_katcp+0x51>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <destroy_ts_katcp@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.katcp_time = type { i32 }
%struct.katcp_dispatch = type { i32 }
define %struct.katcp_time* @find_make_append_ts_katcp(%struct.katcp_dispatch* %0, i32 (%struct.katcp_dispatch*, i8*)* %1, i8* %2) {
%4 = alloca %struct.katcp_time*
%5 = alloca %struct.katcp_dispatch*
%6 = alloca i32 (%struct.katcp_dispatch*, i8*)*
%7 = alloca i8*
%8 = alloca %struct.katcp_time*
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %5
store i32 (%struct.katcp_dispatch*, i8*)* %1, i32 (%struct.katcp_dispatch*, i8*)** %6
store i8* %2, i8** %7
%9 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%10 = load i8*, i8** %7
%11 = call %struct.katcp_time* @find_ts_katcp(%struct.katcp_dispatch* %9, i8* %10)
store %struct.katcp_time* %11, %struct.katcp_time** %8
%12 = load %struct.katcp_time*, %struct.katcp_time** %8
%13 = icmp eq %struct.katcp_time* %12, null
br i1 %13, label %14, label %31
14: ; preds = %3
%15 = load i32 (%struct.katcp_dispatch*, i8*)*, i32 (%struct.katcp_dispatch*, i8*)** %6
%16 = load i8*, i8** %7
%17 = call %struct.katcp_time* @create_ts_katcp(i32 (%struct.katcp_dispatch*, i8*)* %15, i8* %16)
store %struct.katcp_time* %17, %struct.katcp_time** %8
%18 = load %struct.katcp_time*, %struct.katcp_time** %8
%19 = icmp eq %struct.katcp_time* %18, null
br i1 %19, label %20, label %21
20: ; preds = %14
store %struct.katcp_time* null, %struct.katcp_time** %4
br label %33
21: ; preds = %14
%22 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%23 = load %struct.katcp_time*, %struct.katcp_time** %8
%24 = call i64 @append_ts_katcp(%struct.katcp_dispatch* %22, %struct.katcp_time* %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%28 = load %struct.katcp_time*, %struct.katcp_time** %8
%29 = call i32 @destroy_ts_katcp(%struct.katcp_dispatch* %27, %struct.katcp_time* %28)
store %struct.katcp_time* null, %struct.katcp_time** %4
br label %33
30: ; preds = %21
br label %31
31: ; preds = %30, %3
%32 = load %struct.katcp_time*, %struct.katcp_time** %8
store %struct.katcp_time* %32, %struct.katcp_time** %4
br label %33
33: ; preds = %31, %26, %20
%34 = load %struct.katcp_time*, %struct.katcp_time** %4
ret %struct.katcp_time* %34
}

LLVM IR (-O2):
%struct.katcp_time = type { i32 }
%struct.katcp_dispatch = type { i32 }
define %struct.katcp_time* @find_make_append_ts_katcp(%struct.katcp_dispatch* %0, i32 (%struct.katcp_dispatch*, i8*)* %1, i8* %2) {
%4 = tail call %struct.katcp_time* @find_ts_katcp(%struct.katcp_dispatch* %0, i8* %2)
%5 = icmp eq %struct.katcp_time* %4, null
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = tail call %struct.katcp_time* @create_ts_katcp(i32 (%struct.katcp_dispatch*, i8*)* %1, i8* %2)
%8 = icmp eq %struct.katcp_time* %7, null
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = tail call i64 @append_ts_katcp(%struct.katcp_dispatch* %0, %struct.katcp_time* %7)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @destroy_ts_katcp(%struct.katcp_dispatch* %0, %struct.katcp_time* %7)
br label %14
14: ; preds = %3, %9, %6, %12
%15 = phi %struct.katcp_time* [ null, %12 ], [ null, %6 ], [ %7, %9 ], [ %4, %3 ]
ret %struct.katcp_time* %15
}