#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_F_BIO_NEW_FILE;
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_file_internal();
int /*<<< orphan*/ BIO_set_fp(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/);
int /*<<< orphan*/ BIOerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_SYS_LIB;
int /*<<< orphan*/ ERR_add_error_data(int, char *, char const *, char *,
                                      char const *, char *);
int /*<<< orphan*/ SYS_F_FOPEN;
int /*<<< orphan*/ SYSerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char const *, char const *);
int /*<<< orphan*/ get_last_sys_error();
BIO *BIO_new_file(const char *filename, const char *mode) {
  BIO *ret;
  FILE *file;
  if ((file = fopen(filename, mode)) == NULL) {
    SYSerr(SYS_F_FOPEN, get_last_sys_error());
    ERR_add_error_data(5, "fopen('", filename, "','", mode, "')");
    BIOerr(BIO_F_BIO_NEW_FILE, ERR_R_SYS_LIB);
    return (NULL);
  }
  if ((ret = BIO_new(BIO_s_file_internal())) == NULL)
    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)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1213 <BIO_new_file+0x93>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <get_last_sys_error@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%esi
call   1030 <SYSerr@plt>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%r8
mov    $0x5,%edi
lea    0xe24(%rip),%rsi
lea    0xe25(%rip),%rcx
lea    0xe22(%rip),%r9
call   10a0 <ERR_add_error_data@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
call   1060 <BIOerr@plt>
movq   $0x0,-0x8(%rbp)
jmp    125a <BIO_new_file+0xda>
mov    $0x0,%al
call   1040 <BIO_s_file_internal@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    123c <BIO_new_file+0xbc>
movq   $0x0,-0x8(%rbp)
jmp    125a <BIO_new_file+0xda>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
call   1080 <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   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r12
call   1090 <fopen@plt>
test   %rax,%rax
je     11ce <BIO_new_file+0x4e>
mov    %rax,%r13
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <BIO_s_file_internal@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
test   %rax,%rax
je     1226 <BIO_new_file+0xa6>
mov    %rax,%rbx
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <BIO_set_fp@plt>
mov    %rbx,%r14
jmp    1226 <BIO_new_file+0xa6>
mov    0x2e03(%rip),%rax
mov    (%rax),%ebx
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <get_last_sys_error@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <SYSerr@plt>
lea    0xe0f(%rip),%rsi
lea    0xe10(%rip),%rcx
lea    0xe0d(%rip),%r9
mov    $0x5,%edi
mov    %r12,%rdx
mov    %r15,%r8
call   10a0 <ERR_add_error_data@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
call   1060 <BIOerr@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SYS_F_FOPEN = global i32 0
@.str = [8 x i8] c"fopen('\00"
@.str.1 = [4 x i8] c"','\00"
@.str.2 = [3 x i8] c"')\00"
@BIO_F_BIO_NEW_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
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %8, i8* %9)
store i32* %10, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %22
12: ; preds = %2
%13 = load i32, i32* @SYS_F_FOPEN
%14 = call i32 (...) @get_last_sys_error()
%15 = call i32 @SYSerr(i32 %13, i32 %14)
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i32 @ERR_add_error_data(i32 5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @BIO_F_BIO_NEW_FILE
%20 = load i32, i32* @ERR_R_SYS_LIB
%21 = call i32 @BIOerr(i32 %19, i32 %20)
store i32* null, i32** %3
br label %33
22: ; preds = %2
%23 = call i32 (...) @BIO_s_file_internal()
%24 = call i32* @BIO_new(i32 %23)
store i32* %24, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %22
store i32* null, i32** %3
br label %33
27: ; preds = %22
%28 = load i32*, i32** %6
%29 = load i32*, i32** %7
%30 = load i32, i32* @BIO_CLOSE
%31 = call i32 @BIO_set_fp(i32* %28, i32* %29, i32 %30)
%32 = load i32*, i32** %6
store i32* %32, i32** %3
br label %33
33: ; preds = %27, %26, %12
%34 = load i32*, i32** %3
ret i32* %34
}

LLVM IR (-O2):
@SYS_F_FOPEN = global i32 0
@.str = [8 x i8] c"fopen('\00"
@.str.1 = [4 x i8] c"','\00"
@.str.2 = [3 x i8] c"')\00"
@BIO_F_BIO_NEW_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 %13
5: ; preds = %2
%6 = load i32, i32* @SYS_F_FOPEN
%7 = tail call i32 (...) @get_last_sys_error()
%8 = tail call i32 @SYSerr(i32 %6, i32 %7)
%9 = tail call i32 @ERR_add_error_data(i32 5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @BIO_F_BIO_NEW_FILE
%11 = load i32, i32* @ERR_R_SYS_LIB
%12 = tail call i32 @BIOerr(i32 %10, i32 %11)
br label %20
13: ; preds = %2
%14 = tail call i32 (...) @BIO_s_file_internal()
%15 = tail call i32* @BIO_new(i32 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i32, i32* @BIO_CLOSE
%19 = tail call i32 @BIO_set_fp(i32* %15, i32* %3, i32 %18)
br label %20
20: ; preds = %13, %17, %5
%21 = phi i32* [ null, %5 ], [ %15, %17 ], [ null, %13 ]
ret i32* %21
}