#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 */

/* Variables and functions */
int btree_insertkey(int, int /*<<< orphan*/, char *, int, int);
int btree_locate(int, int /*<<< orphan*/, char *);
int dfile_new_record(int, unsigned char *, int);
int dfile_put_record(int, int, unsigned char *, int);
int /*<<< orphan*/ dfile_write_header(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int INTERNAL_write_object_file(int file_id, char *label, unsigned char *obj,
                               int size, int overwrite) {
  int pt;
  char key[32 + 1];
  if ((pt = btree_locate(file_id, 0, label)) != 0) {
    if (!overwrite)
      return -1;
    if (dfile_put_record(file_id, pt, obj, size) == -1)
      return -1;
  } else {
    if ((pt = dfile_new_record(file_id, obj, size)) == 0)
      return -1;
    memset(key, 0, 32 + 1);
    strncpy(key, label, 32);
    if (btree_insertkey(file_id, 0, key, pt, 1) == -1)
      return -1;
  }
  dfile_write_header(file_id);
  return 0;
}


x86 assembly (clang, -O0):
<INTERNAL_write_object_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1060 <btree_locate@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11e6 <INTERNAL_write_object_file+0x76>
cmpl   $0x0,-0x20(%rbp)
jne    11ba <INTERNAL_write_object_file+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <INTERNAL_write_object_file+0xff>
mov    -0x8(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1090 <dfile_put_record@plt>
cmp    $0xffffffff,%eax
jne    11e1 <INTERNAL_write_object_file+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <INTERNAL_write_object_file+0xff>
jmp    1260 <INTERNAL_write_object_file+0xf0>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <dfile_new_record@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    120d <INTERNAL_write_object_file+0x9d>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <INTERNAL_write_object_file+0xff>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x21,%edx
call   1040 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rdx
mov    -0x24(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%r8d
call   1050 <btree_insertkey@plt>
cmp    $0xffffffff,%eax
jne    125b <INTERNAL_write_object_file+0xeb>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <INTERNAL_write_object_file+0xff>
jmp    1260 <INTERNAL_write_object_file+0xf0>
mov    -0x8(%rbp),%edi
call   1070 <dfile_write_header@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<INTERNAL_write_object_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%ebx
mov    %ecx,%r15d
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %edi,%r12d
xor    %esi,%esi
mov    %rbp,%rdx
call   1060 <btree_locate@plt>
test   %eax,%eax
je     11bc <INTERNAL_write_object_file+0x4c>
mov    $0xffffffff,%r14d
test   %ebx,%ebx
je     121f <INTERNAL_write_object_file+0xaf>
mov    %r12d,%edi
mov    %eax,%esi
mov    %r13,%rdx
mov    %r15d,%ecx
call   1090 <dfile_put_record@plt>
cmp    $0xffffffff,%eax
jne    1214 <INTERNAL_write_object_file+0xa4>
jmp    121f <INTERNAL_write_object_file+0xaf>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %r15d,%edx
call   1080 <dfile_new_record@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
je     121f <INTERNAL_write_object_file+0xaf>
mov    %eax,%r15d
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x21,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
mov    %r12d,%edi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r15d,%ecx
mov    $0x1,%r8d
call   1050 <btree_insertkey@plt>
cmp    $0xffffffff,%eax
je     121f <INTERNAL_write_object_file+0xaf>
mov    %r12d,%edi
call   1070 <dfile_write_header@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @INTERNAL_write_object_file(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [33 x i8]
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%14 = load i32, i32* %7
%15 = load i8*, i8** %8
%16 = call i32 @btree_locate(i32 %14, i32 0, i8* %15)
store i32 %16, i32* %12
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %5
%19 = load i32, i32* %11
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %18
store i32 -1, i32* %6
br label %54
22: ; preds = %18
%23 = load i32, i32* %7
%24 = load i32, i32* %12
%25 = load i8*, i8** %9
%26 = load i32, i32* %10
%27 = call i32 @dfile_put_record(i32 %23, i32 %24, i8* %25, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 -1, i32* %6
br label %54
30: ; preds = %22
br label %51
31: ; preds = %5
%32 = load i32, i32* %7
%33 = load i8*, i8** %9
%34 = load i32, i32* %10
%35 = call i32 @dfile_new_record(i32 %32, i8* %33, i32 %34)
store i32 %35, i32* %12
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 -1, i32* %6
br label %54
38: ; preds = %31
%39 = getelementptr inbounds [33 x i8], [33 x i8]* %13, i64 0, i64 0
%40 = call i32 @memset(i8* %39, i32 0, i32 33)
%41 = getelementptr inbounds [33 x i8], [33 x i8]* %13, i64 0, i64 0
%42 = load i8*, i8** %8
%43 = call i32 @strncpy(i8* %41, i8* %42, i32 32)
%44 = load i32, i32* %7
%45 = getelementptr inbounds [33 x i8], [33 x i8]* %13, i64 0, i64 0
%46 = load i32, i32* %12
%47 = call i32 @btree_insertkey(i32 %44, i32 0, i8* %45, i32 %46, i32 1)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %50
49: ; preds = %38
store i32 -1, i32* %6
br label %54
50: ; preds = %38
br label %51
51: ; preds = %50, %30
%52 = load i32, i32* %7
%53 = call i32 @dfile_write_header(i32 %52)
store i32 0, i32* %6
br label %54
54: ; preds = %51, %49, %37, %29, %21
%55 = load i32, i32* %6
ret i32 %55
}

LLVM IR (-O2):
define i32 @INTERNAL_write_object_file(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca [33 x i8]
%7 = getelementptr inbounds [33 x i8], [33 x i8]* %6, i64 0, i64 0
%8 = tail call i32 @btree_locate(i32 %0, i32 0, i8* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = icmp eq i32 %4, 0
br i1 %11, label %25, label %12
12: ; preds = %10
%13 = tail call i32 @dfile_put_record(i32 %0, i32 %8, i8* %2, i32 %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %25, label %23
15: ; preds = %5
%16 = tail call i32 @dfile_new_record(i32 %0, i8* %2, i32 %3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = call i32 @memset(i8* %7, i32 0, i32 33)
%20 = call i32 @strncpy(i8* %7, i8* %1, i32 32)
%21 = call i32 @btree_insertkey(i32 %0, i32 0, i8* %7, i32 %16, i32 1)
%22 = icmp eq i32 %21, -1
br i1 %22, label %25, label %23
23: ; preds = %18, %12
%24 = call i32 @dfile_write_header(i32 %0)
br label %25
25: ; preds = %18, %15, %12, %10, %23
%26 = phi i32 [ 0, %23 ], [ -1, %10 ], [ -1, %12 ], [ -1, %15 ], [ -1, %18 ]
ret i32 %26
}