#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_locate(int, int /*<<< orphan*/, char *);
int dfile_get_record(int, int, unsigned char *);
int dfile_get_record_size(int, int);
scalar_t__ malloc(int);
int INTERNAL_read_object_file(int file_id, char *label, unsigned char **obj) {
  int pt, size = 0;
  ;
  if ((pt = btree_locate(file_id, 0, label)) != 0) {
    if ((size = dfile_get_record_size(file_id, pt)) == 0)
      return -1;
    *obj = (unsigned char *)malloc(size);
    return dfile_get_record(file_id, pt, *obj);
  }
  return -1;
}


x86 assembly (clang, -O0):
<INTERNAL_read_object_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1060 <btree_locate@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11c3 <INTERNAL_read_object_file+0x83>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <dfile_get_record_size@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jne    1197 <INTERNAL_read_object_file+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <INTERNAL_read_object_file+0x8a>
mov    -0x20(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
call   1030 <dfile_get_record@plt>
mov    %eax,-0x4(%rbp)
jmp    11ca <INTERNAL_read_object_file+0x8a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<INTERNAL_read_object_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rdx
mov    %edi,%ebp
xor    %esi,%esi
call   1060 <btree_locate@plt>
test   %eax,%eax
je     1180 <INTERNAL_read_object_file+0x40>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <dfile_get_record_size@plt>
test   %eax,%eax
je     1180 <INTERNAL_read_object_file+0x40>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,(%r14)
mov    %ebp,%edi
mov    %ebx,%esi
mov    %rax,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <dfile_get_record@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @INTERNAL_read_object_file(i32 %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i32 0, i32* %9
%10 = load i32, i32* %5
%11 = load i8*, i8** %6
%12 = call i32 @btree_locate(i32 %10, i32 0, i8* %11)
store i32 %12, i32* %8
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %30
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load i32, i32* %8
%17 = call i32 @dfile_get_record_size(i32 %15, i32 %16)
store i32 %17, i32* %9
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 -1, i32* %4
br label %31
20: ; preds = %14
%21 = load i32, i32* %9
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = load i8**, i8*** %7
store i8* %23, i8** %24
%25 = load i32, i32* %5
%26 = load i32, i32* %8
%27 = load i8**, i8*** %7
%28 = load i8*, i8** %27
%29 = call i32 @dfile_get_record(i32 %25, i32 %26, i8* %28)
store i32 %29, i32* %4
br label %31
30: ; preds = %3
store i32 -1, i32* %4
br label %31
31: ; preds = %30, %20, %19
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
define i32 @INTERNAL_read_object_file(i32 %0, i8* %1, i8** nocapture writeonly %2) {
%4 = tail call i32 @btree_locate(i32 %0, i32 0, i8* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i32 @dfile_get_record_size(i32 %0, i32 %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = tail call i64 @malloc(i32 %7)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %2
%12 = tail call i32 @dfile_get_record(i32 %0, i32 %4, i8* %11)
br label %13
13: ; preds = %3, %6, %9
%14 = phi i32 [ %12, %9 ], [ -1, %6 ], [ -1, %3 ]
ret i32 %14
}