#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 /*<<< orphan*/ btree_init(int);
int /*<<< orphan*/ dfile_get_version(int);
int dfile_open(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(int /*<<< orphan*/, char *, int);
int g_open_object_file(char *name, int w) {
  int id;
  if ((id = dfile_open(name, w)) == -1)
    return -1;
  btree_init(id);
  if (strncmp(dfile_get_version(id), "GP00", 4) != 0) {
    fprintf(stderr, "Unkown Object-File Version\n");
    return -1;
  }
  return id;
}


x86 assembly (clang, -O0):
<g_open_object_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <dfile_open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1183 <g_open_object_file+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <g_open_object_file+0x87>
mov    -0x18(%rbp),%edi
call   1060 <btree_init@plt>
mov    -0x18(%rbp),%edi
call   1040 <dfile_get_version@plt>
mov    %eax,%edi
lea    0xe64(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11d1 <g_open_object_file+0x81>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <g_open_object_file+0x87>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<g_open_object_file>:
push   %rbx
call   1070 <dfile_open@plt>
mov    %eax,%ebx
mov    $0xffffffff,%eax
cmp    $0xffffffff,%ebx
je     11a7 <g_open_object_file+0x57>
mov    %ebx,%edi
call   1060 <btree_init@plt>
mov    %ebx,%edi
call   1040 <dfile_get_version@plt>
lea    0xe89(%rip),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
mov    %ebx,%eax
test   %rcx,%rcx
je     11a7 <g_open_object_file+0x57>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"GP00\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Unkown Object-File Version\0A\00"
define i32 @g_open_object_file(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i32, i32* %5
%9 = call i32 @dfile_open(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %24
12: ; preds = %2
%13 = load i32, i32* %6
%14 = call i32 @btree_init(i32 %13)
%15 = load i32, i32* %6
%16 = call i32 @dfile_get_version(i32 %15)
%17 = call i64 @strncmp(i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %24
22: ; preds = %12
%23 = load i32, i32* %6
store i32 %23, i32* %3
br label %24
24: ; preds = %22, %19, %11
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [5 x i8] c"GP00\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Unkown Object-File Version\0A\00"
define i32 @g_open_object_file(i8* %0, i32 %1) {
%3 = tail call i32 @dfile_open(i8* %0, i32 %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = tail call i32 @btree_init(i32 %3)
%7 = tail call i32 @dfile_get_version(i32 %3)
%8 = tail call i64 @strncmp(i32 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %5, %2, %10
%14 = phi i32 [ -1, %10 ], [ -1, %2 ], [ %3, %5 ]
ret i32 %14
}