#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;
FILE *tr_get_fp(const char *fn) {
  if (*fn == '-' && fn[1] == '\0')
    return stdin;
  else {
    FILE *fp = fopen(fn, "r");
    if (fp == 0) {
      fprintf(stderr, "[tr_get_fp] fail to open file %s\n", fn);
      exit(1);
    }
    return fp;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tr_get_fp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1170 <tr_get_fp+0x40>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1170 <tr_get_fp+0x40>
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <tr_get_fp+0x8a>
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b2 <tr_get_fp+0x82>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tr_get_fp>:
push   %rbx
mov    %rdi,%rbx
cmpb   $0x2d,(%rdi)
jne    113f <tr_get_fp+0xf>
cmpb   $0x0,0x1(%rbx)
je     1155 <tr_get_fp+0x25>
lea    0xeba(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
je     1161 <tr_get_fp+0x31>
pop    %rbx
ret
mov    0x2e8c(%rip),%rax
mov    (%rax),%rax
pop    %rbx
ret
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"[tr_get_fp] fail to open file %s\0A\00"
define i32* @tr_get_fp(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 45
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = load i32*, i32** @stdin
br label %17
10: ; preds = %4, %1
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10, %8
%18 = phi i32* [ %9, %8 ], [ %11, %10 ]
ret i32* %18
}