#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*/ fatal(char *, char const *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ *stdin;
FILE *opn(const char *p) {
  FILE *fd;
  if (p[0] == '-' && p[1] == '\0')
    fd = stdin;
  else if ((fd = fopen(p, "r")) == NULL)
    fatal("Cannot open file %s\n", p);
  return (fd);
}


x86 assembly (clang, -O0):
<opn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1160 <opn+0x40>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1160 <opn+0x40>
mov    0x2e94(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    1193 <opn+0x73>
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    118e <opn+0x6e>
mov    -0x8(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1040 <fatal@plt>
jmp    1193 <opn+0x73>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opn>:
push   %rbx
mov    %rdi,%rbx
cmpb   $0x2d,(%rdi)
jne    112f <opn+0xf>
cmpb   $0x0,0x1(%rbx)
je     1158 <opn+0x38>
lea    0xeca(%rip),%rsi
mov    %rbx,%rdi
call   1030 <fopen@plt>
test   %rax,%rax
je     1145 <opn+0x25>
pop    %rbx
ret
lea    0xeb6(%rip),%rdi
mov    %rbx,%rsi
call   1040 <fatal@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e89(%rip),%rax
mov    (%rax),%rax
pop    %rbx
ret

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"Cannot open file %s\0A\00"
define i32* @opn(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%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** %2
%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** %3
br label %25
17: ; preds = %9, %1
%18 = load i8*, i8** %2
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %3
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i8*, i8** %2
%23 = call i32 @fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %17
br label %25
25: ; preds = %24, %15
%26 = load i32*, i32** %3
ret i32* %26
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"Cannot open file %s\0A\00"
define i32* @opn(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 %15
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 %15
13: ; preds = %10
%14 = tail call i32 @fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %10, %13, %8
%16 = phi i32* [ %9, %8 ], [ null, %13 ], [ %11, %10 ]
ret i32* %16
}