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

/* Variables and functions */
int /*<<< orphan*/ cdb_hash(char *, unsigned int);
int cdb_make_addbegin(struct cdb_make *, unsigned int, unsigned int);
int cdb_make_addend(struct cdb_make *, unsigned int, unsigned int,
                    int /*<<< orphan*/);
scalar_t__ cdb_make_write(struct cdb_make *, char *, unsigned int);
int cdb_make_add(struct cdb_make *c, char *key, unsigned int keylen, char *data,
                 unsigned int datalen) {
  if (cdb_make_addbegin(c, keylen, datalen) == -1)
    return -1;
  if (cdb_make_write(c, key, keylen) != 0)
    return -1;
  if (cdb_make_write(c, data, datalen) != 0)
    return -1;
  return cdb_make_addend(c, keylen, datalen, cdb_hash(key, keylen));
}


x86 assembly (clang, -O0):
<cdb_make_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1040 <cdb_make_addbegin@plt>
cmp    $0xffffffff,%eax
jne    117f <cdb_make_add+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <cdb_make_add+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <cdb_make_write@plt>
cmp    $0x0,%rax
je     11a5 <cdb_make_add+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <cdb_make_add+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <cdb_make_write@plt>
cmp    $0x0,%rax
je     11cb <cdb_make_add+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <cdb_make_add+0xbf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <cdb_hash@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    %eax,%ecx
call   1060 <cdb_make_addend@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cdb_make_add>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%r12
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %edx,%esi
mov    %r8d,%edx
call   1040 <cdb_make_addbegin@plt>
cmp    $0xffffffff,%eax
je     118a <cdb_make_add+0x4a>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <cdb_make_write@plt>
test   %rax,%rax
jne    118a <cdb_make_add+0x4a>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1030 <cdb_make_write@plt>
test   %rax,%rax
je     1198 <cdb_make_add+0x58>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %ebp,%esi
call   1050 <cdb_hash@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %eax,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <cdb_make_addend@plt>

LLVM IR (-O0):
%struct.cdb_make = type { i32 }
define i32 @cdb_make_add(%struct.cdb_make* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.cdb_make*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store %struct.cdb_make* %0, %struct.cdb_make** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%12 = load %struct.cdb_make*, %struct.cdb_make** %7
%13 = load i32, i32* %9
%14 = load i32, i32* %11
%15 = call i32 @cdb_make_addbegin(%struct.cdb_make* %12, i32 %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %5
store i32 -1, i32* %6
br label %40
18: ; preds = %5
%19 = load %struct.cdb_make*, %struct.cdb_make** %7
%20 = load i8*, i8** %8
%21 = load i32, i32* %9
%22 = call i64 @cdb_make_write(%struct.cdb_make* %19, i8* %20, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 -1, i32* %6
br label %40
25: ; preds = %18
%26 = load %struct.cdb_make*, %struct.cdb_make** %7
%27 = load i8*, i8** %10
%28 = load i32, i32* %11
%29 = call i64 @cdb_make_write(%struct.cdb_make* %26, i8* %27, i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 -1, i32* %6
br label %40
32: ; preds = %25
%33 = load %struct.cdb_make*, %struct.cdb_make** %7
%34 = load i32, i32* %9
%35 = load i32, i32* %11
%36 = load i8*, i8** %8
%37 = load i32, i32* %9
%38 = call i32 @cdb_hash(i8* %36, i32 %37)
%39 = call i32 @cdb_make_addend(%struct.cdb_make* %33, i32 %34, i32 %35, i32 %38)
store i32 %39, i32* %6
br label %40
40: ; preds = %32, %31, %24, %17
%41 = load i32, i32* %6
ret i32 %41
}

LLVM IR (-O2):
%struct.cdb_make = type { i32 }
define i32 @cdb_make_add(%struct.cdb_make* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = tail call i32 @cdb_make_addbegin(%struct.cdb_make* %0, i32 %2, i32 %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = tail call i64 @cdb_make_write(%struct.cdb_make* %0, i8* %1, i32 %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = tail call i64 @cdb_make_write(%struct.cdb_make* %0, i8* %3, i32 %4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i32 @cdb_hash(i8* %1, i32 %2)
%16 = tail call i32 @cdb_make_addend(%struct.cdb_make* %0, i32 %2, i32 %4, i32 %15)
br label %17
17: ; preds = %11, %8, %5, %14
%18 = phi i32 [ %16, %14 ], [ -1, %5 ], [ -1, %8 ], [ -1, %11 ]
ret i32 %18
}