#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 pe_as_id_lit_map_rd {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int errno;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ pe_as_id_lit_map_rd_close(struct pe_as_id_lit_map_rd *);
int /*<<< orphan*/ pe_as_id_lit_map_rd_init(struct pe_as_id_lit_map_rd *);
int pe_as_id_lit_map_rd_read(struct pe_as_id_lit_map_rd *, char const *,
                             int /*<<< orphan*/ *);
int pe_as_id_lit_map_rd_open(struct pe_as_id_lit_map_rd *m,
                             char const *file_name) {
  FILE *source;
  int err;
  source = fopen(file_name, "rb");
  if (source == 0) {
    err = errno;
    goto could_not_open_file;
  }
  err = pe_as_id_lit_map_rd_read(m, file_name, source);
  if (err)
    goto could_not_read_ids;
  pe_as_id_lit_map_rd_init(m);
  if (fclose(source) != 0) {
    err = errno;
    pe_as_id_lit_map_rd_close(m);
  }
  return err;
could_not_read_ids:
  (void)fclose(source);
could_not_open_file:
  return err;
}


x86 assembly (clang, -O0):
<pe_as_id_lit_map_rd_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1190 <pe_as_id_lit_map_rd_open+0x40>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    11f8 <pe_as_id_lit_map_rd_open+0xa8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <pe_as_id_lit_map_rd_read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11b3 <pe_as_id_lit_map_rd_open+0x63>
jmp    11ef <pe_as_id_lit_map_rd_open+0x9f>
mov    -0x10(%rbp),%rdi
call   1050 <pe_as_id_lit_map_rd_init@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11e4 <pe_as_id_lit_map_rd_open+0x94>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <pe_as_id_lit_map_rd_close@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fe <pe_as_id_lit_map_rd_open+0xae>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pe_as_id_lit_map_rd_open>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe9f(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     118f <pe_as_id_lit_map_rd_open+0x3f>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1060 <pe_as_id_lit_map_rd_read@plt>
test   %eax,%eax
je     119a <pe_as_id_lit_map_rd_open+0x4a>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11c4 <pe_as_id_lit_map_rd_open+0x74>
mov    0x2e4a(%rip),%rax
mov    (%rax),%ebp
jmp    11c4 <pe_as_id_lit_map_rd_open+0x74>
mov    %r14,%rdi
call   1050 <pe_as_id_lit_map_rd_init@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
je     11c2 <pe_as_id_lit_map_rd_open+0x72>
mov    0x2e2a(%rip),%rax
mov    (%rax),%ebp
mov    %r14,%rdi
call   1040 <pe_as_id_lit_map_rd_close@plt>
jmp    11c4 <pe_as_id_lit_map_rd_open+0x74>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.pe_as_id_lit_map_rd = type { i32 }
@.str = [3 x i8] c"rb\00"
@errno = global i32 0
define i32 @pe_as_id_lit_map_rd_open(%struct.pe_as_id_lit_map_rd* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.pe_as_id_lit_map_rd*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store %struct.pe_as_id_lit_map_rd* %0, %struct.pe_as_id_lit_map_rd** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* @errno
store i32 %13, i32* %7
br label %37
14: ; preds = %2
%15 = load %struct.pe_as_id_lit_map_rd*, %struct.pe_as_id_lit_map_rd** %4
%16 = load i8*, i8** %5
%17 = load i32*, i32** %6
%18 = call i32 @pe_as_id_lit_map_rd_read(%struct.pe_as_id_lit_map_rd* %15, i8* %16, i32* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
br label %34
22: ; preds = %14
%23 = load %struct.pe_as_id_lit_map_rd*, %struct.pe_as_id_lit_map_rd** %4
%24 = call i32 @pe_as_id_lit_map_rd_init(%struct.pe_as_id_lit_map_rd* %23)
%25 = load i32*, i32** %6
%26 = call i64 @fclose(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = load i32, i32* @errno
store i32 %29, i32* %7
%30 = load %struct.pe_as_id_lit_map_rd*, %struct.pe_as_id_lit_map_rd** %4
%31 = call i32 @pe_as_id_lit_map_rd_close(%struct.pe_as_id_lit_map_rd* %30)
br label %32
32: ; preds = %28, %22
%33 = load i32, i32* %7
store i32 %33, i32* %3
br label %39
34: ; preds = %21
%35 = load i32*, i32** %6
%36 = call i64 @fclose(i32* %35)
br label %37
37: ; preds = %34, %12
%38 = load i32, i32* %7
store i32 %38, i32* %3
br label %39
39: ; preds = %37, %32
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.pe_as_id_lit_map_rd = type { i32 }
@.str = [3 x i8] c"rb\00"
@errno = global i32 0
define i32 @pe_as_id_lit_map_rd_open(%struct.pe_as_id_lit_map_rd* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = load i32, i32* @errno
br label %19
7: ; preds = %2
%8 = tail call i32 @pe_as_id_lit_map_rd_read(%struct.pe_as_id_lit_map_rd* %0, i8* %1, i32* %3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = tail call i32 @pe_as_id_lit_map_rd_init(%struct.pe_as_id_lit_map_rd* %0)
%12 = tail call i64 @fclose(i32* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = load i32, i32* @errno
%16 = tail call i32 @pe_as_id_lit_map_rd_close(%struct.pe_as_id_lit_map_rd* %0)
br label %19
17: ; preds = %7
%18 = tail call i64 @fclose(i32* %3)
br label %19
19: ; preds = %5, %17, %10, %14
%20 = phi i32 [ %15, %14 ], [ 0, %10 ], [ %6, %5 ], [ %8, %17 ]
ret i32 %20
}