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

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ errno;
int /*<<< orphan*/ fatal(char *, char const *, ...);
struct index_file *index_file_open(char const *);
int /*<<< orphan*/ strerror(scalar_t__);
struct index_file *open_index(const char *filename) {
  struct index_file *index;
  index = index_file_open(filename);
  if (!index) {
    if (errno == EINVAL)
      fatal("%s has wrong magic or version number", filename);
    fatal("Could not open %s for reading: %s\n", filename, strerror(errno));
  }
  return index;
}


x86 assembly (clang, -O0):
<open_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <index_file_open@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ab <open_index+0x7b>
mov    0x2e85(%rip),%rax
mov    (%rax),%rax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
jne    1180 <open_index+0x50>
mov    -0x8(%rbp),%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <fatal@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%rdi
call   1040 <strerror@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1050 <fatal@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_index>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <index_file_open@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1187 <open_index+0x57>
mov    0x2e94(%rip),%r15
mov    (%r15),%rdi
mov    0x2e82(%rip),%rax
cmp    (%rax),%rdi
jne    116f <open_index+0x3f>
lea    0xe9e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fatal@plt>
mov    (%r15),%rdi
call   1040 <strerror@plt>
lea    0xeaa(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fatal@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.index_file = type { i32 }
@errno = global i64 0
@EINVAL = global i64 0
@.str = [37 x i8] c"%s has wrong magic or version number\00"
@.str.1 = [35 x i8] c"Could not open %s for reading: %s\0A\00"
define %struct.index_file* @open_index(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.index_file*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call %struct.index_file* @index_file_open(i8* %4)
store %struct.index_file* %5, %struct.index_file** %3
%6 = load %struct.index_file*, %struct.index_file** %3
%7 = icmp ne %struct.index_file* %6, null
br i1 %7, label %20, label %8
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINVAL
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i8*, i8** %2
%14 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %8
%16 = load i8*, i8** %2
%17 = load i64, i64* @errno
%18 = call i32 @strerror(i64 %17)
%19 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 %18)
br label %20
20: ; preds = %15, %1
%21 = load %struct.index_file*, %struct.index_file** %3
ret %struct.index_file* %21
}

LLVM IR (-O2):
%struct.index_file = type { i32 }
@errno = global i64 0
@EINVAL = global i64 0
@.str = [37 x i8] c"%s has wrong magic or version number\00"
@.str.1 = [35 x i8] c"Could not open %s for reading: %s\0A\00"
define %struct.index_file* @open_index(i8* %0) {
%2 = tail call %struct.index_file* @index_file_open(i8* %0)
%3 = icmp eq %struct.index_file* %2, null
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = load i64, i64* @EINVAL
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = tail call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = load i64, i64* @errno
br label %11
11: ; preds = %8, %4
%12 = phi i64 [ %10, %8 ], [ %5, %4 ]
%13 = tail call i32 @strerror(i64 %12)
%14 = tail call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %13)
br label %15
15: ; preds = %11, %1
ret %struct.index_file* %2
}