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

/* Variables and functions */
int /*<<< orphan*/ close_entries(struct entries *);
struct entries *open_data_file(char *);
scalar_t__ read_headers(struct entries *);
struct entries *open_entries(char *name) {
  struct entries *entries;
  if ((entries = open_data_file(name)) == NULL)
    return NULL;
  if (read_headers(entries)) {
    close_entries(entries);
    return NULL;
  }
  return entries;
}


x86 assembly (clang, -O0):
<open_entries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <open_data_file@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1160 <open_entries+0x30>
movq   $0x0,-0x8(%rbp)
jmp    1191 <open_entries+0x61>
mov    -0x18(%rbp),%rdi
call   1040 <read_headers@plt>
cmp    $0x0,%rax
je     1189 <open_entries+0x59>
mov    -0x18(%rbp),%rdi
call   1030 <close_entries@plt>
movq   $0x0,-0x8(%rbp)
jmp    1191 <open_entries+0x61>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_entries>:
push   %rbx
call   1050 <open_data_file@plt>
test   %rax,%rax
je     1153 <open_entries+0x23>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <read_headers@plt>
test   %rax,%rax
je     1155 <open_entries+0x25>
mov    %rbx,%rdi
call   1030 <close_entries@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.entries = type { i32 }
define %struct.entries* @open_entries(i8* %0) {
%2 = alloca %struct.entries*
%3 = alloca i8*
%4 = alloca %struct.entries*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call %struct.entries* @open_data_file(i8* %5)
store %struct.entries* %6, %struct.entries** %4
%7 = icmp eq %struct.entries* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store %struct.entries* null, %struct.entries** %2
br label %18
9: ; preds = %1
%10 = load %struct.entries*, %struct.entries** %4
%11 = call i64 @read_headers(%struct.entries* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load %struct.entries*, %struct.entries** %4
%15 = call i32 @close_entries(%struct.entries* %14)
store %struct.entries* null, %struct.entries** %2
br label %18
16: ; preds = %9
%17 = load %struct.entries*, %struct.entries** %4
store %struct.entries* %17, %struct.entries** %2
br label %18
18: ; preds = %16, %13, %8
%19 = load %struct.entries*, %struct.entries** %2
ret %struct.entries* %19
}

LLVM IR (-O2):
%struct.entries = type { i32 }
define %struct.entries* @open_entries(i8* %0) {
%2 = tail call %struct.entries* @open_data_file(i8* %0)
%3 = icmp eq %struct.entries* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i64 @read_headers(%struct.entries* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @close_entries(%struct.entries* %2)
br label %9
9: ; preds = %4, %1, %7
%10 = phi %struct.entries* [ null, %7 ], [ null, %1 ], [ %2, %4 ]
ret %struct.entries* %10
}