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

/* Variables and functions */
void *ASN1_d2i_bio(void *(*)(), int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   void **);
int /*<<< orphan*/ ASN1error(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_file();
int /*<<< orphan*/ BIO_set_fp(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_BUF_LIB;
void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x) {
  BIO *b;
  void *ret;
  if ((b = BIO_new(BIO_s_file())) == NULL) {
    ASN1error(ERR_R_BUF_LIB);
    return (NULL);
  }
  BIO_set_fp(b, in, BIO_NOCLOSE);
  ret = ASN1_d2i_bio(xnew, d2i, b, x);
  BIO_free(b);
  return (ret);
}


x86 assembly (clang, -O0):
<ASN1_d2i_fp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    $0x0,%al
call   1070 <BIO_s_file@plt>
mov    %eax,%edi
call   1040 <BIO_new@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11af <ASN1_d2i_fp+0x4f>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1080 <ASN1error@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ef <ASN1_d2i_fp+0x8f>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
call   1060 <BIO_set_fp@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <ASN1_d2i_bio@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <BIO_free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_d2i_fp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
xor    %eax,%eax
call   1070 <BIO_s_file@plt>
mov    %eax,%edi
call   1040 <BIO_new@plt>
test   %rax,%rax
je     11c0 <ASN1_d2i_fp+0x60>
mov    %rax,%rbx
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <BIO_set_fp@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <ASN1_d2i_bio@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <BIO_free@plt>
mov    %r14,%rax
jmp    11d0 <ASN1_d2i_fp+0x70>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1080 <ASN1error@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ERR_R_BUF_LIB = global i32 0
@BIO_NOCLOSE = global i32 0
define i8* @ASN1_d2i_fp(i8* ()* %0, i32* %1, i32* %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i8* ()*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i8*
store i8* ()* %0, i8* ()** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i8** %3, i8*** %9
%12 = call i32 (...) @BIO_s_file()
%13 = call i32* @BIO_new(i32 %12)
store i32* %13, i32** %10
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i32, i32* @ERR_R_BUF_LIB
%17 = call i32 @ASN1error(i32 %16)
store i8* null, i8** %5
br label %32
18: ; preds = %4
%19 = load i32*, i32** %10
%20 = load i32*, i32** %8
%21 = load i32, i32* @BIO_NOCLOSE
%22 = call i32 @BIO_set_fp(i32* %19, i32* %20, i32 %21)
%23 = load i8* ()*, i8* ()** %6
%24 = bitcast i8* ()* %23 to i8* (...)*
%25 = load i32*, i32** %7
%26 = load i32*, i32** %10
%27 = load i8**, i8*** %9
%28 = call i8* @ASN1_d2i_bio(i8* (...)* %24, i32* %25, i32* %26, i8** %27)
store i8* %28, i8** %11
%29 = load i32*, i32** %10
%30 = call i32 @BIO_free(i32* %29)
%31 = load i8*, i8** %11
store i8* %31, i8** %5
br label %32
32: ; preds = %18, %15
%33 = load i8*, i8** %5
ret i8* %33
}

LLVM IR (-O2):
@ERR_R_BUF_LIB = global i32 0
@BIO_NOCLOSE = global i32 0
define i8* @ASN1_d2i_fp(i8* ()* %0, i32* %1, i32* %2, i8** %3) {
%5 = tail call i32 (...) @BIO_s_file()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* @ERR_R_BUF_LIB
%10 = tail call i32 @ASN1error(i32 %9)
br label %17
11: ; preds = %4
%12 = load i32, i32* @BIO_NOCLOSE
%13 = tail call i32 @BIO_set_fp(i32* %6, i32* %2, i32 %12)
%14 = bitcast i8* ()* %0 to i8* (...)*
%15 = tail call i8* @ASN1_d2i_bio(i8* (...)* %14, i32* %1, i32* %6, i8** %3)
%16 = tail call i32 @BIO_free(i32* %6)
br label %17
17: ; preds = %11, %8
%18 = phi i8* [ null, %8 ], [ %15, %11 ]
ret i8* %18
}