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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fopen(char const *const, char *);
int /*<<< orphan*/ pm_error(char *, char const *const, int /*<<< orphan*/,
                            int /*<<< orphan*/);
int /*<<< orphan*/ *stdin;
scalar_t__ streq(char const *const, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
FILE *pm_openr(const char *const name) {
  FILE *f;
  if (streq(name, "-"))
    f = stdin;
  else {
    f = fopen(name, "rb");
    if (f == NULL)
      pm_error("Unable to open file '%s' for reading.  "
               "fopen() returns errno %d (%s)",
               name, errno, strerror(errno));
  }
  return f;
}


x86 assembly (clang, -O0):
<pm_openr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1030 <streq@plt>
cmp    $0x0,%rax
je     1179 <pm_openr+0x39>
mov    0x2e7b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    11d4 <pm_openr+0x94>
mov    -0x8(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cf <pm_openr+0x8f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
lea    0xe3b(%rip),%rdi
call   1060 <pm_error@plt>
jmp    11d4 <pm_openr+0x94>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pm_openr>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xeb3(%rip),%rsi
call   1030 <streq@plt>
test   %rax,%rax
je     1163 <pm_openr+0x23>
mov    0x2e8a(%rip),%rax
mov    (%rax),%rax
jmp    119c <pm_openr+0x5c>
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
jne    119c <pm_openr+0x5c>
mov    0x2e5a(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1050 <strerror@plt>
lea    0xe77(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
call   1060 <pm_error@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [69 x i8] c"Unable to open file '%s' for reading. fopen() returns errno %d (%s)\00"
@errno = global i32 0
define i32* @pm_openr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @streq(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32*, i32** @stdin
store i32* %8, i32** %3
br label %21
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = load i32, i32* @errno
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @pm_error(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i8* %15, i32 %16, i32 %18)
br label %20
20: ; preds = %14, %9
br label %21
21: ; preds = %20, %7
%22 = load i32*, i32** %3
ret i32* %22
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [69 x i8] c"Unable to open file '%s' for reading. fopen() returns errno %d (%s)\00"
@errno = global i32 0
define i32* @pm_openr(i8* %0) {
%2 = tail call i64 @streq(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = load i32*, i32** @stdin
br label %13
6: ; preds = %1
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* @errno
%11 = tail call i32 @strerror(i32 %10)
%12 = tail call i32 @pm_error(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %10, i32 %11)
br label %13
13: ; preds = %6, %9, %4
%14 = phi i32* [ %5, %4 ], [ null, %9 ], [ %7, %6 ]
ret i32* %14
}