#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*/ error(int, int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ *fopen(char const *, char const *);
int strlen(char const *);
void open_file(FILE **outfp, const char *filename, const char *mode) {
  FILE *fp;
  if (strlen(filename) == 1 && filename[0] == '-')
    return;
  if (!(fp = fopen(filename, mode)))
    error(1, errno, "cannot access %s", filename);
  *outfp = fp;
}


x86 assembly (clang, -O0):
<open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jne    116b <open_file+0x3b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    116b <open_file+0x3b>
jmp    11af <open_file+0x7f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a4 <open_file+0x74>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edi
lea    0xe61(%rip),%rdx
call   1040 <error@plt>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jne    1150 <open_file+0x20>
cmpb   $0x2d,(%rbx)
je     1183 <open_file+0x53>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1180 <open_file+0x50>
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rdx
mov    $0x1,%edi
mov    %rbx,%rcx
call   1040 <error@plt>
mov    %r15,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [17 x i8] c"cannot access %s\00"
define void @open_file(i32** %0, i8* %1, i8* %2) {
%4 = alloca i32**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i32** %0, i32*** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %18
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 45
br i1 %16, label %17, label %18
17: ; preds = %11
br label %30
18: ; preds = %11, %3
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = call i32* @fopen(i8* %19, i8* %20)
store i32* %21, i32** %7
%22 = icmp ne i32* %21, null
br i1 %22, label %27, label %23
23: ; preds = %18
%24 = load i32, i32* @errno
%25 = load i8*, i8** %5
%26 = call i32 @error(i32 1, i32 %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %23, %18
%28 = load i32*, i32** %7
%29 = load i32**, i32*** %4
store i32* %28, i32** %29
br label %30
30: ; preds = %27, %17
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [17 x i8] c"cannot access %s\00"
define void @open_file(i32** nocapture writeonly %0, i8* %1, i8* nocapture %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 45
br i1 %8, label %16, label %9
9: ; preds = %6, %3
%10 = tail call i32* @fopen(i8* %1, i8* %2)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @errno
%14 = tail call i32 @error(i32 1, i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %15
15: ; preds = %12, %9
store i32* %10, i32** %0
br label %16
16: ; preds = %6, %15
ret void
}