#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*/ exit(int);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char const *, char *);
FILE *fnvOpenFile(const char *filename) {
  if (strcmp(filename, "-") == 0) {
    return stdin;
  }
  FILE *fp = fopen(filename, "rb");
  if (fp) {
    return fp;
  }
  fprintf(stderr, "Error, cannot open file: %s\n", filename);
  exit(1);
}


x86 assembly (clang, -O0):
<fnvOpenFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1179 <fnvOpenFile+0x39>
mov    0x2e7b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11c8 <fnvOpenFile+0x88>
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a5 <fnvOpenFile+0x65>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c8 <fnvOpenFile+0x88>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnvOpenFile>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     116b <fnvOpenFile+0x2b>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1177 <fnvOpenFile+0x37>
pop    %rbx
ret
mov    0x2e76(%rip),%rax
mov    (%rax),%rax
pop    %rbx
ret
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Error, cannot open file: %s\0A\00"
define i32* @fnvOpenFile(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i32*, i32** @stdin
store i32* %9, i32** %2
br label %22
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i32*, i32** %4
store i32* %16, i32** %2
br label %22
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15, %8
%23 = load i32*, i32** %2
ret i32* %23
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Error, cannot open file: %s\0A\00"
define i32* @fnvOpenFile(i8* %0) {
%2 = tail call i64 @strcmp(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 %4, label %6
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* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6, %4
%14 = phi i32* [ %5, %4 ], [ %7, %6 ]
ret i32* %14
}