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

/* Variables and functions */
int /*<<< orphan*/ ASN1_R_DECODE_ERROR;
int /*<<< orphan*/ *ASN1_item_d2i_bio(int /*<<< orphan*/ const *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ ASN1error(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_pop(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it) {
  BIO *b64;
  ASN1_VALUE *val;
  if (!(b64 = BIO_new(BIO_f_base64()))) {
    ASN1error(ERR_R_MALLOC_FAILURE);
    return 0;
  }
  bio = BIO_push(b64, bio);
  val = ASN1_item_d2i_bio(it, bio, NULL);
  if (!val)
    ASN1error(ASN1_R_DECODE_ERROR);
  (void)BIO_flush(bio);
  bio = BIO_pop(bio);
  BIO_free(b64);
  return val;
}


x86 assembly (clang, -O0):
<b64_read_asn1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c7 <b64_read_asn1+0x47>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1090 <ASN1error@plt>
movq   $0x0,-0x8(%rbp)
jmp    122d <b64_read_asn1+0xad>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <ASN1_item_d2i_bio@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1206 <b64_read_asn1+0x86>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1090 <ASN1error@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <BIO_flush@plt>
mov    -0x10(%rbp),%rdi
call   1050 <BIO_pop@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <BIO_free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b64_read_asn1>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
test   %rax,%rax
je     11ec <b64_read_asn1+0x6c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1080 <ASN1_item_d2i_bio@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11d2 <b64_read_asn1+0x52>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1090 <ASN1error@plt>
mov    %r15,%rdi
call   10a0 <BIO_flush@plt>
mov    %r15,%rdi
call   1050 <BIO_pop@plt>
mov    %rbx,%rdi
call   1070 <BIO_free@plt>
jmp    11fd <b64_read_asn1+0x7d>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1090 <ASN1error@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ERR_R_MALLOC_FAILURE = global i32 0
@ASN1_R_DECODE_ERROR = global i32 0
define i32* @b64_read_asn1(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = call i32 (...) @BIO_f_base64()
%9 = call i32* @BIO_new(i32 %8)
store i32* %9, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* @ERR_R_MALLOC_FAILURE
%13 = call i32 @ASN1error(i32 %12)
store i32* null, i32** %3
br label %34
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = load i32*, i32** %4
%17 = call i32* @BIO_push(i32* %15, i32* %16)
store i32* %17, i32** %4
%18 = load i32*, i32** %5
%19 = load i32*, i32** %4
%20 = call i32* @ASN1_item_d2i_bio(i32* %18, i32* %19, i32* null)
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp ne i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %14
%24 = load i32, i32* @ASN1_R_DECODE_ERROR
%25 = call i32 @ASN1error(i32 %24)
br label %26
26: ; preds = %23, %14
%27 = load i32*, i32** %4
%28 = call i32 @BIO_flush(i32* %27)
%29 = load i32*, i32** %4
%30 = call i32* @BIO_pop(i32* %29)
store i32* %30, i32** %4
%31 = load i32*, i32** %6
%32 = call i32 @BIO_free(i32* %31)
%33 = load i32*, i32** %7
store i32* %33, i32** %3
br label %34
34: ; preds = %26, %11
%35 = load i32*, i32** %3
ret i32* %35
}

LLVM IR (-O2):
@ERR_R_MALLOC_FAILURE = global i32 0
@ASN1_R_DECODE_ERROR = global i32 0
define i32* @b64_read_asn1(i32* %0, i32* %1) {
%3 = tail call i32 (...) @BIO_f_base64()
%4 = tail call i32* @BIO_new(i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @ERR_R_MALLOC_FAILURE
%8 = tail call i32 @ASN1error(i32 %7)
br label %20
9: ; preds = %2
%10 = tail call i32* @BIO_push(i32* %4, i32* %0)
%11 = tail call i32* @ASN1_item_d2i_bio(i32* %1, i32* %10, i32* null)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @ASN1_R_DECODE_ERROR
%15 = tail call i32 @ASN1error(i32 %14)
br label %16
16: ; preds = %13, %9
%17 = tail call i32 @BIO_flush(i32* %10)
%18 = tail call i32* @BIO_pop(i32* %10)
%19 = tail call i32 @BIO_free(i32* %4)
br label %20
20: ; preds = %16, %6
%21 = phi i32* [ %11, %16 ], [ null, %6 ]
ret i32* %21
}