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


x86 assembly (clang, -O0):
<err_xreopen_core>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <freopen@plt>
cmp    $0x0,%rax
jne    11b9 <err_xreopen_core+0x79>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <perror@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_xreopen_core>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
call   1040 <freopen@plt>
test   %rax,%rax
je     116a <err_xreopen_core+0x2a>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e6f(%rip),%rbx
mov    (%rbx),%edi
lea    0xe86(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1060 <perror@plt>
mov    (%rbx),%edi
lea    0xe87(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"[%s] fail to open file '%s': \00"
@.str.1 = [8 x i8] c"Abort!\0A\00"
define i32* @err_xreopen_core(i8* %0, i8* %1, i8* %2, i32* %3) {
%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* %3, i32** %8
%9 = load i8*, i8** %6
%10 = load i8*, i8** %7
%11 = load i32*, i32** %8
%12 = call i64 @freopen(i8* %9, i8* %10, i32* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17)
%19 = call i32 @perror(i32* null)
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %4
%24 = load i32*, i32** %8
ret i32* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"[%s] fail to open file '%s': \00"
@.str.1 = [8 x i8] c"Abort!\0A\00"
define i32* @err_xreopen_core(i8* %0, i8* %1, i8* %2, i32* returned %3) {
%5 = tail call i64 @freopen(i8* %1, i8* %2, i32* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%10 = tail call i32 @perror(i32* null)
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %4
ret i32* %3
}