#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 const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ stderr;
FILE *efopen(const char *name, const char *mode) {
  FILE *f = fopen(name, mode);
  if (f == NULL) {
    fprintf(stderr, "luac: cannot open %sput file ",
            *mode == 'r' ? "in" : "out");
    perror(name);
    exit(1);
  }
  return f;
}


x86 assembly (clang, -O0):
<efopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b0 <efopen+0x70>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
lea    0xe9e(%rip),%rdx
lea    0xe94(%rip),%rax
cmp    $0x72,%ecx
cmove  %rax,%rdx
lea    0xe68(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<efopen>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <fopen@plt>
test   %rax,%rax
je     115c <efopen+0x1c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
cmpb   $0x72,(%rbx)
lea    0xeaf(%rip),%rax
lea    0xeab(%rip),%rdx
cmove  %rax,%rdx
lea    0xe7f(%rip),%rsi
call   1030 <fprintf@plt>
mov    %r14,%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"luac: cannot open %sput file \00"
@.str.1 = [3 x i8] c"in\00"
@.str.2 = [4 x i8] c"out\00"
define i32* @efopen(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %6, i8* %7)
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %23
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 114
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%19 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %3
%21 = call i32 @perror(i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i32*, i32** %5
ret i32* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"luac: cannot open %sput file \00"
@.str.1 = [3 x i8] c"in\00"
@.str.2 = [4 x i8] c"out\00"
define noalias i32* @efopen(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* %1)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 114
%9 = select i1 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%10 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @perror(i8* %0)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
ret i32* %3
}