#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_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char const *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, unsigned long,
                           char const *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(scalar_t__);
FILE *safe_fopen(const char *pathname, const char *mode, unsigned long line) {
  errno = 0;
  FILE *f = fopen(pathname, mode);
  if (!f) {
    fprintf(stderr, "[%s:%lu] fopen failed (%s, %s)\n\t%s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/jirka-h/aprng/refs/heads/master/src/"
            "libaprng-util.c",
            line, pathname, mode, strerror(errno));
    exit(EXIT_FAILURE);
  }
  return f;
}


x86 assembly (clang, -O0):
<safe_fopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e7d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e4 <safe_fopen+0xa4>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x28(%rbp),%r9
lea    0xe39(%rip),%rsi
lea    0xe56(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <fprintf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_fopen>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e7c(%rip),%rbp
movq   $0x0,0x0(%rbp)
call   1040 <fopen@plt>
test   %rax,%rax
je     117b <safe_fopen+0x3b>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e5e(%rip),%rax
mov    (%rax),%r12d
mov    0x0(%rbp),%rdi
call   1060 <strerror@plt>
mov    %eax,(%rsp)
lea    0xe68(%rip),%rsi
lea    0xe85(%rip),%rdx
mov    %r12d,%edi
mov    %r14,%rcx
mov    %rbx,%r8
mov    %r15,%r9
call   1030 <fprintf@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [36 x i8] c"[%s:%lu] fopen failed (%s, %s)\0A\09%s\0A\00"
@.str.1 = [142 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jirka-h/aprng/refs/heads/master/src/libaprng-util.c\00"
@EXIT_FAILURE = global i32 0
define i32* @safe_fopen(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i64 0, i64* @errno
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %8, i8* %9)
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %23, label %13
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i64, i64* %6
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = load i64, i64* @errno
%19 = call i32 @strerror(i64 %18)
%20 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str.1, i64 0, i64 0), i64 %15, i8* %16, i8* %17, i32 %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %3
%24 = load i32*, i32** %7
ret i32* %24
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [36 x i8] c"[%s:%lu] fopen failed (%s, %s)\0A\09%s\0A\00"
@.str.1 = [142 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jirka-h/aprng/refs/heads/master/src/libaprng-util.c\00"
@EXIT_FAILURE = global i32 0
define noalias i32* @safe_fopen(i8* %0, i8* %1, i64 %2) {
store i64 0, i64* @errno
%4 = tail call i32* @fopen(i8* %0, i8* %1)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = load i64, i64* @errno
%9 = tail call i32 @strerror(i64 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str.1, i64 0, i64 0), i64 %2, i8* %0, i8* %1, i32 %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %3
ret i32* %4
}