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

/* Variables and functions */
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 *PEM_ASN1_read_bio(int /*<<< orphan*/ *, char const *,
                        int /*<<< orphan*/ *, void **, int /*<<< orphan*/ *,
                        void *);
int /*<<< orphan*/ PEM_F_PEM_ASN1_READ;
int /*<<< orphan*/ PEMerr(int /*<<< orphan*/, int /*<<< orphan*/);
void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
                    pem_password_cb *cb, void *u) {
  BIO *b;
  void *ret;
  if ((b = BIO_new(BIO_s_file())) == NULL) {
    PEMerr(PEM_F_PEM_ASN1_READ, ERR_R_BUF_LIB);
    return (0);
  }
  BIO_set_fp(b, fp, BIO_NOCLOSE);
  ret = PEM_ASN1_read_bio(d2i, name, b, x, cb, u);
  BIO_free(b);
  return (ret);
}


x86 assembly (clang, -O0):
<PEM_ASN1_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    $0x0,%al
call   1080 <BIO_s_file@plt>
mov    %eax,%edi
call   1040 <BIO_new@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11c0 <PEM_ASN1_read+0x60>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1030 <PEMerr@plt>
movq   $0x0,-0x8(%rbp)
jmp    1208 <PEM_ASN1_read+0xa8>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
call   1060 <BIO_set_fp@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x38(%rbp),%r9
call   1070 <PEM_ASN1_read_bio@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <BIO_free@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PEM_ASN1_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <BIO_s_file@plt>
mov    %eax,%edi
call   1040 <BIO_new@plt>
test   %rax,%rax
je     11d0 <PEM_ASN1_read+0x70>
mov    %rax,%rbp
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <BIO_set_fp@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    (%rsp),%r9
call   1070 <PEM_ASN1_read_bio@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1050 <BIO_free@plt>
mov    %rbx,%rax
jmp    11e9 <PEM_ASN1_read+0x89>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
call   1030 <PEMerr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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