#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 */
int /*<<< orphan*/ ASN1_F_ASN1_D2I_FP;
void *ASN1_d2i_bio(void *(*)(), int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   void **);
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, 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) {
    ASN1err(ASN1_F_ASN1_D2I_FP, 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   1080 <BIO_s_file@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11b8 <ASN1_d2i_fp+0x58>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <ASN1_d2i_fp+0x98>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
call   1070 <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   1060 <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   1080 <BIO_s_file@plt>
mov    %eax,%edi
call   1050 <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   1070 <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   1060 <BIO_free@plt>
mov    %r14,%rax
jmp    11d9 <ASN1_d2i_fp+0x79>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ASN1_F_ASN1_D2I_FP = global i32 0
@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 %19
15: ; preds = %4
%16 = load i32, i32* @ASN1_F_ASN1_D2I_FP
%17 = load i32, i32* @ERR_R_BUF_LIB
%18 = call i32 @ASN1err(i32 %16, i32 %17)
store i8* null, i8** %5
br label %33
19: ; preds = %4
%20 = load i32*, i32** %10
%21 = load i32*, i32** %8
%22 = load i32, i32* @BIO_NOCLOSE
%23 = call i32 @BIO_set_fp(i32* %20, i32* %21, i32 %22)
%24 = load i8* ()*, i8* ()** %6
%25 = bitcast i8* ()* %24 to i8* (...)*
%26 = load i32*, i32** %7
%27 = load i32*, i32** %10
%28 = load i8**, i8*** %9
%29 = call i8* @ASN1_d2i_bio(i8* (...)* %25, i32* %26, i32* %27, i8** %28)
store i8* %29, i8** %11
%30 = load i32*, i32** %10
%31 = call i32 @BIO_free(i32* %30)
%32 = load i8*, i8** %11
store i8* %32, i8** %5
br label %33
33: ; preds = %19, %15
%34 = load i8*, i8** %5
ret i8* %34
}

LLVM IR (-O2):
@ASN1_F_ASN1_D2I_FP = global i32 0
@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 %12
8: ; preds = %4
%9 = load i32, i32* @ASN1_F_ASN1_D2I_FP
%10 = load i32, i32* @ERR_R_BUF_LIB
%11 = tail call i32 @ASN1err(i32 %9, i32 %10)
br label %18
12: ; preds = %4
%13 = load i32, i32* @BIO_NOCLOSE
%14 = tail call i32 @BIO_set_fp(i32* %6, i32* %2, i32 %13)
%15 = bitcast i8* ()* %0 to i8* (...)*
%16 = tail call i8* @ASN1_d2i_bio(i8* (...)* %15, i32* %1, i32* %6, i8** %3)
%17 = tail call i32 @BIO_free(i32* %6)
br label %18
18: ; preds = %12, %8
%19 = phi i8* [ null, %8 ], [ %16, %12 ]
ret i8* %19
}