#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*/ abort();
int /*<<< orphan*/ *fopen(char const *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char const *, char *);
scalar_t__ strstr(char const *, char *);
FILE *err_xopen_core(const char *func, const char *fn, const char *mode) {
  FILE *fp = 0;
  if (strcmp(fn, "-") == 0)
    return (strstr(mode, "r")) ? stdin : stdout;
  if ((fp = fopen(fn, mode)) == 0) {
    fprintf(stderr, "[%s] fail to open file '%s'. Abort!\n", func, fn);
    abort();
  }
  return fp;
}


x86 assembly (clang, -O0):
<err_xopen_core>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ce <err_xopen_core+0x7e>
mov    -0x20(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     11b3 <err_xopen_core+0x63>
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    11c1 <err_xopen_core+0x71>
mov    0x2e16(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1215 <err_xopen_core+0xc5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    120d <err_xopen_core+0xbd>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe03(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_xopen_core>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe9b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11a4 <err_xopen_core+0x54>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11cb <err_xopen_core+0x7b>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xe57(%rip),%rsi
mov    %r15,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
jne    11c1 <err_xopen_core+0x71>
mov    0x2e11(%rip),%rax
jmp    11c8 <err_xopen_core+0x78>
mov    0x2e20(%rip),%rax
mov    (%rax),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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