#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*/ ENOMEM;
scalar_t__ cdb_make_write(struct cdb_make *, char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ uint32_pack(char *, unsigned int);
int cdb_make_addbegin(struct cdb_make *c, unsigned int keylen,
                      unsigned int datalen) {
  char buf[8];
  if (keylen > 0xffffffff) {
    errno = ENOMEM;
    return -1;
  }
  if (datalen > 0xffffffff) {
    errno = ENOMEM;
    return -1;
  }
  uint32_pack(buf, keylen);
  uint32_pack(buf + 4, datalen);
  if (cdb_make_write(c, buf, 8) != 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<cdb_make_addbegin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jbe    115a <cdb_make_addbegin+0x3a>
mov    0x2e9d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8c(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11cd <cdb_make_addbegin+0xad>
cmpl   $0xffffffff,-0x18(%rbp)
jbe    1182 <cdb_make_addbegin+0x62>
mov    0x2e75(%rip),%rax
mov    (%rax),%ecx
mov    0x2e64(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11cd <cdb_make_addbegin+0xad>
lea    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <uint32_pack@plt>
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0x18(%rbp),%esi
call   1040 <uint32_pack@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1030 <cdb_make_write@plt>
cmp    $0x0,%rax
je     11c6 <cdb_make_addbegin+0xa6>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cd <cdb_make_addbegin+0xad>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cdb_make_addbegin>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %rdi,%r14
lea    0x8(%rsp),%r15
mov    %r15,%rdi
call   1040 <uint32_pack@plt>
lea    0xc(%rsp),%rdi
mov    %ebx,%esi
call   1040 <uint32_pack@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <cdb_make_write@plt>
neg    %rax
sbb    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.cdb_make = type { i32 }
@ENOMEM = global i32 0
@errno = global i32 0
define i32 @cdb_make_addbegin(%struct.cdb_make* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.cdb_make*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [8 x i8]
store %struct.cdb_make* %0, %struct.cdb_make** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = icmp ugt i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = load i32, i32* @ENOMEM
store i32 %12, i32* @errno
store i32 -1, i32* %4
br label %32
13: ; preds = %3
%14 = load i32, i32* %7
%15 = icmp ugt i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = load i32, i32* @ENOMEM
store i32 %17, i32* @errno
store i32 -1, i32* %4
br label %32
18: ; preds = %13
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%20 = load i32, i32* %6
%21 = call i32 @uint32_pack(i8* %19, i32 %20)
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%23 = getelementptr inbounds i8, i8* %22, i64 4
%24 = load i32, i32* %7
%25 = call i32 @uint32_pack(i8* %23, i32 %24)
%26 = load %struct.cdb_make*, %struct.cdb_make** %5
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%28 = call i64 @cdb_make_write(%struct.cdb_make* %26, i8* %27, i32 8)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %18
store i32 -1, i32* %4
br label %32
31: ; preds = %18
store i32 0, i32* %4
br label %32
32: ; preds = %31, %30, %16, %11
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
%struct.cdb_make = type { i32 }
@ENOMEM = global i32 0
@errno = global i32 0
define i32 @cdb_make_addbegin(%struct.cdb_make* %0, i32 %1, i32 %2) {
%4 = alloca [8 x i8]
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%6 = call i32 @uint32_pack(i8* %5, i32 %1)
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 4
%8 = call i32 @uint32_pack(i8* %7, i32 %2)
%9 = call i64 @cdb_make_write(%struct.cdb_make* %0, i8* %5, i32 8)
%10 = icmp ne i64 %9, 0
%11 = sext i1 %10 to i32
ret i32 %11
}