#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
struct shared_pool {
  int dummy;
};
struct item {
  int dummy;
};

/* Variables and functions */
int EFAULT;
int /*<<< orphan*/ shared_pool_unlock_item(struct item *);
struct item *t_add_and_lock(struct shared_pool *, char *, size_t,
                            int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
int t_add(struct shared_pool *sp, char *key, size_t klen, uint8_t *p,
          size_t len, uint32_t expire_after) {
  struct item *item = t_add_and_lock(sp, key, klen, p, len, expire_after);
  if (item != NULL) {
    shared_pool_unlock_item(item);
    return 0;
  } else {
    return -EFAULT;
  }
}


x86 assembly (clang, -O0):
<t_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x34(%rbp),%r9d
call   1030 <t_add_and_lock@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1181 <t_add+0x61>
mov    -0x40(%rbp),%rdi
call   1040 <shared_pool_unlock_item@plt>
movl   $0x0,-0x4(%rbp)
jmp    118f <t_add+0x6f>
xor    %eax,%eax
mov    0x2e6e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t_add>:
push   %rax
call   1030 <t_add_and_lock@plt>
test   %rax,%rax
je     1137 <t_add+0x17>
mov    %rax,%rdi
call   1040 <shared_pool_unlock_item@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2eba(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.shared_pool = type { i32 }
%struct.item = type { i32 }
@EFAULT = global i32 0
define i32 @t_add(%struct.shared_pool* %0, i8* %1, i64 %2, i32* %3, i64 %4, i32 %5) {
%7 = alloca i32
%8 = alloca %struct.shared_pool*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32*
%12 = alloca i64
%13 = alloca i32
%14 = alloca %struct.item*
store %struct.shared_pool* %0, %struct.shared_pool** %8
store i8* %1, i8** %9
store i64 %2, i64* %10
store i32* %3, i32** %11
store i64 %4, i64* %12
store i32 %5, i32* %13
%15 = load %struct.shared_pool*, %struct.shared_pool** %8
%16 = load i8*, i8** %9
%17 = load i64, i64* %10
%18 = load i32*, i32** %11
%19 = load i64, i64* %12
%20 = load i32, i32* %13
%21 = call %struct.item* @t_add_and_lock(%struct.shared_pool* %15, i8* %16, i64 %17, i32* %18, i64 %19, i32 %20)
store %struct.item* %21, %struct.item** %14
%22 = load %struct.item*, %struct.item** %14
%23 = icmp ne %struct.item* %22, null
br i1 %23, label %24, label %27
24: ; preds = %6
%25 = load %struct.item*, %struct.item** %14
%26 = call i32 @shared_pool_unlock_item(%struct.item* %25)
store i32 0, i32* %7
br label %30
27: ; preds = %6
%28 = load i32, i32* @EFAULT
%29 = sub nsw i32 0, %28
store i32 %29, i32* %7
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
%struct.shared_pool = type { i32 }
%struct.item = type { i32 }
@EFAULT = global i32 0
define i32 @t_add(%struct.shared_pool* %0, i8* %1, i64 %2, i32* %3, i64 %4, i32 %5) {
%7 = tail call %struct.item* @t_add_and_lock(%struct.shared_pool* %0, i8* %1, i64 %2, i32* %3, i64 %4, i32 %5)
%8 = icmp eq %struct.item* %7, null
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @shared_pool_unlock_item(%struct.item* %7)
br label %14
11: ; preds = %6
%12 = load i32, i32* @EFAULT
%13 = sub nsw i32 0, %12
br label %14
14: ; preds = %11, %9
%15 = phi i32 [ 0, %9 ], [ %13, %11 ]
ret i32 %15
}