#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;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_CLOSE;
int /*<<< orphan*/ BIO_R_NO_SUCH_FILE;
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_file();
int /*<<< orphan*/ BIO_set_fp(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/);
int /*<<< orphan*/ BIOerror(int /*<<< orphan*/);
scalar_t__ ENOENT;
int /*<<< orphan*/ ERR_R_SYS_LIB;
int /*<<< orphan*/ ERR_asprintf_error_data(char *, char const *, char const *);
int /*<<< orphan*/ SYSerror(scalar_t__);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char const *);
BIO *BIO_new_file(const char *filename, const char *mode) {
  BIO *ret;
  FILE *file = NULL;
  file = fopen(filename, mode);
  if (file == NULL) {
    SYSerror(errno);
    ERR_asprintf_error_data("fopen('%s', '%s')", filename, mode);
    if (errno == ENOENT)
      BIOerror(BIO_R_NO_SUCH_FILE);
    else
      BIOerror(ERR_R_SYS_LIB);
    return (NULL);
  }
  if ((ret = BIO_new(BIO_s_file())) == NULL) {
    fclose(file);
    return (NULL);
  }
  BIO_set_fp(ret, file, BIO_CLOSE);
  return (ret);
}


x86 assembly (clang, -O0):
<BIO_new_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    121f <BIO_new_file+0x9f>
mov    0x2e15(%rip),%rax
mov    (%rax),%rdi
call   1050 <SYSerror@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe2e(%rip),%rdi
call   1030 <ERR_asprintf_error_data@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%rax
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%rax
jne    1204 <BIO_new_file+0x84>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   10a0 <BIOerror@plt>
jmp    1212 <BIO_new_file+0x92>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   10a0 <BIOerror@plt>
movq   $0x0,-0x8(%rbp)
jmp    126f <BIO_new_file+0xef>
mov    $0x0,%al
call   1090 <BIO_s_file@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1251 <BIO_new_file+0xd1>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    126f <BIO_new_file+0xef>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2d68(%rip),%rax
mov    (%rax),%edx
call   1070 <BIO_set_fp@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BIO_new_file>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
call   1080 <fopen@plt>
test   %rax,%rax
je     11c4 <BIO_new_file+0x44>
mov    %rax,%r14
xor    %eax,%eax
call   1090 <BIO_s_file@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
test   %rax,%rax
je     11fd <BIO_new_file+0x7d>
mov    %rax,%rbx
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <BIO_set_fp@plt>
jmp    1217 <BIO_new_file+0x97>
mov    0x2e05(%rip),%r14
mov    (%r14),%rdi
call   1050 <SYSerror@plt>
lea    0xe26(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <ERR_asprintf_error_data@plt>
mov    (%r14),%rax
mov    0x2dc9(%rip),%rcx
cmp    (%rcx),%rax
jne    1207 <BIO_new_file+0x87>
mov    0x2ded(%rip),%rax
jmp    120e <BIO_new_file+0x8e>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    1215 <BIO_new_file+0x95>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   10a0 <BIOerror@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [18 x i8] c"fopen('%s', '%s')\00"
@ENOENT = global i64 0
@BIO_R_NO_SUCH_FILE = global i32 0
@ERR_R_SYS_LIB = global i32 0
@BIO_CLOSE = global i32 0
define i32* @BIO_new_file(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %7
%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 eq i32* %11, null
br i1 %12, label %13, label %29
13: ; preds = %2
%14 = load i64, i64* @errno
%15 = call i32 @SYSerror(i64 %14)
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i32 @ERR_asprintf_error_data(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17)
%19 = load i64, i64* @errno
%20 = load i64, i64* @ENOENT
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i32, i32* @BIO_R_NO_SUCH_FILE
%24 = call i32 @BIOerror(i32 %23)
br label %28
25: ; preds = %13
%26 = load i32, i32* @ERR_R_SYS_LIB
%27 = call i32 @BIOerror(i32 %26)
br label %28
28: ; preds = %25, %22
store i32* null, i32** %3
br label %42
29: ; preds = %2
%30 = call i32 (...) @BIO_s_file()
%31 = call i32* @BIO_new(i32 %30)
store i32* %31, i32** %6
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32*, i32** %7
%35 = call i32 @fclose(i32* %34)
store i32* null, i32** %3
br label %42
36: ; preds = %29
%37 = load i32*, i32** %6
%38 = load i32*, i32** %7
%39 = load i32, i32* @BIO_CLOSE
%40 = call i32 @BIO_set_fp(i32* %37, i32* %38, i32 %39)
%41 = load i32*, i32** %6
store i32* %41, i32** %3
br label %42
42: ; preds = %36, %33, %28
%43 = load i32*, i32** %3
ret i32* %43
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [18 x i8] c"fopen('%s', '%s')\00"
@ENOENT = global i64 0
@BIO_R_NO_SUCH_FILE = global i32 0
@ERR_R_SYS_LIB = global i32 0
@BIO_CLOSE = global i32 0
define i32* @BIO_new_file(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* %1)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %18
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = tail call i32 @SYSerror(i64 %6)
%8 = tail call i32 @ERR_asprintf_error_data(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = load i32, i32* @BIO_R_NO_SUCH_FILE
%14 = tail call i32 @BIOerror(i32 %13)
br label %27
15: ; preds = %5
%16 = load i32, i32* @ERR_R_SYS_LIB
%17 = tail call i32 @BIOerror(i32 %16)
br label %27
18: ; preds = %2
%19 = tail call i32 (...) @BIO_s_file()
%20 = tail call i32* @BIO_new(i32 %19)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @fclose(i32* %3)
br label %27
24: ; preds = %18
%25 = load i32, i32* @BIO_CLOSE
%26 = tail call i32 @BIO_set_fp(i32* %20, i32* %3, i32 %25)
br label %27
27: ; preds = %12, %15, %24, %22
%28 = phi i32* [ null, %22 ], [ %20, %24 ], [ null, %15 ], [ null, %12 ]
ret i32* %28
}