#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*/ PEMerror(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) {
    PEMerror(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    11b7 <PEM_ASN1_read+0x57>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ff <PEM_ASN1_read+0x9f>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e1a(%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    0x2e45(%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    11e0 <PEM_ASN1_read+0x80>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@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 %22
19: ; preds = %6
%20 = load i32, i32* @ERR_R_BUF_LIB
%21 = call i32 @PEMerror(i32 %20)
store i8* null, i8** %7
br label %37
22: ; preds = %6
%23 = load i32*, i32** %14
%24 = load i32*, i32** %10
%25 = load i32, i32* @BIO_NOCLOSE
%26 = call i32 @BIO_set_fp(i32* %23, i32* %24, i32 %25)
%27 = load i32*, i32** %8
%28 = load i8*, i8** %9
%29 = load i32*, i32** %14
%30 = load i8**, i8*** %11
%31 = load i32*, i32** %12
%32 = load i8*, i8** %13
%33 = call i8* @PEM_ASN1_read_bio(i32* %27, i8* %28, i32* %29, i8** %30, i32* %31, i8* %32)
store i8* %33, i8** %15
%34 = load i32*, i32** %14
%35 = call i32 @BIO_free(i32* %34)
%36 = load i8*, i8** %15
store i8* %36, i8** %7
br label %37
37: ; preds = %22, %19
%38 = load i8*, i8** %7
ret i8* %38
}

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