#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_str_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 pe_as_str_lit_map_rd_read(struct pe_as_str_lit_map_rd *,
                              int /*<<< orphan*/ *);
int pe_as_str_lit_map_rd_open(struct pe_as_str_lit_map_rd *m,
                              char const *file_name) {
  FILE *source;
  int err = 0;
  source = fopen(file_name, "rb");
  if (source == 0) {
    err = errno;
    goto could_not_open_string_file;
  }
  err = pe_as_str_lit_map_rd_read(m, source);
  if (err)
    goto could_not_read_strings;
  if (fclose(source) != 0)
    err = errno;
  return err;
could_not_read_strings:
  (void)fclose(source);
could_not_open_string_file:
  return err;
}


x86 assembly (clang, -O0):
<pe_as_str_lit_map_rd_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1177 <pe_as_str_lit_map_rd_open+0x47>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    11c9 <pe_as_str_lit_map_rd_open+0x99>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <pe_as_str_lit_map_rd_read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1196 <pe_as_str_lit_map_rd_open+0x66>
jmp    11c0 <pe_as_str_lit_map_rd_open+0x90>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11b5 <pe_as_str_lit_map_rd_open+0x85>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11cf <pe_as_str_lit_map_rd_open+0x9f>
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_str_lit_map_rd_open>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%rbp
lea    0xec0(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1170 <pe_as_str_lit_map_rd_open+0x40>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <pe_as_str_lit_map_rd_read@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %ebp,%ebp
jne    1179 <pe_as_str_lit_map_rd_open+0x49>
xor    %ebp,%ebp
test   %rax,%rax
je     1179 <pe_as_str_lit_map_rd_open+0x49>
mov    0x2e69(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.pe_as_str_lit_map_rd = type { i32 }
@.str = [3 x i8] c"rb\00"
@errno = global i32 0
define i32 @pe_as_str_lit_map_rd_open(%struct.pe_as_str_lit_map_rd* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.pe_as_str_lit_map_rd*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store %struct.pe_as_str_lit_map_rd* %0, %struct.pe_as_str_lit_map_rd** %4
store i8* %1, i8** %5
store i32 0, i32* %7
%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 %32
14: ; preds = %2
%15 = load %struct.pe_as_str_lit_map_rd*, %struct.pe_as_str_lit_map_rd** %4
%16 = load i32*, i32** %6
%17 = call i32 @pe_as_str_lit_map_rd_read(%struct.pe_as_str_lit_map_rd* %15, i32* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
br label %29
21: ; preds = %14
%22 = load i32*, i32** %6
%23 = call i64 @fclose(i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32, i32* @errno
store i32 %26, i32* %7
br label %27
27: ; preds = %25, %21
%28 = load i32, i32* %7
store i32 %28, i32* %3
br label %34
29: ; preds = %20
%30 = load i32*, i32** %6
%31 = call i64 @fclose(i32* %30)
br label %32
32: ; preds = %29, %12
%33 = load i32, i32* %7
store i32 %33, i32* %3
br label %34
34: ; preds = %32, %27
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.pe_as_str_lit_map_rd = type { i32 }
@.str = [3 x i8] c"rb\00"
@errno = global i32 0
define i32 @pe_as_str_lit_map_rd_open(%struct.pe_as_str_lit_map_rd* %0, i8* nocapture %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 %15
7: ; preds = %2
%8 = tail call i32 @pe_as_str_lit_map_rd_read(%struct.pe_as_str_lit_map_rd* %0, i32* %3)
%9 = icmp eq i32 %8, 0
%10 = tail call i64 @fclose(i32* %3)
br i1 %9, label %11, label %15
11: ; preds = %7
%12 = icmp eq i64 %10, 0
%13 = load i32, i32* @errno
%14 = select i1 %12, i32 0, i32 %13
br label %15
15: ; preds = %7, %5, %11
%16 = phi i32 [ %14, %11 ], [ %6, %5 ], [ %8, %7 ]
ret i32 %16
}