#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_F_B64_READ_ASN1;
int /*<<< orphan*/ ASN1_R_DECODE_ERROR;
int /*<<< orphan*/ *ASN1_item_d2i_bio(int /*<<< orphan*/ const *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, 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()))) {
    ASN1err(ASN1_F_B64_READ_ASN1, ERR_R_MALLOC_FAILURE);
    return 0;
  }
  bio = BIO_push(b64, bio);
  val = ASN1_item_d2i_bio(it, bio, NULL);
  if (!val)
    ASN1err(ASN1_F_B64_READ_ASN1, 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   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11d0 <b64_read_asn1+0x50>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movq   $0x0,-0x8(%rbp)
jmp    123f <b64_read_asn1+0xbf>
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   1090 <ASN1_item_d2i_bio@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1218 <b64_read_asn1+0x98>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <BIO_flush@plt>
mov    -0x10(%rbp),%rdi
call   1060 <BIO_pop@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <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   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
test   %rax,%rax
je     11f5 <b64_read_asn1+0x75>
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   1090 <ASN1_item_d2i_bio@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11db <b64_read_asn1+0x5b>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
mov    %r15,%rdi
call   10a0 <BIO_flush@plt>
mov    %r15,%rdi
call   1060 <BIO_pop@plt>
mov    %rbx,%rdi
call   1080 <BIO_free@plt>
jmp    120f <b64_read_asn1+0x8f>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ASN1_F_B64_READ_ASN1 = global i32 0
@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 %15, label %11
11: ; preds = %2
%12 = load i32, i32* @ASN1_F_B64_READ_ASN1
%13 = load i32, i32* @ERR_R_MALLOC_FAILURE
%14 = call i32 @ASN1err(i32 %12, i32 %13)
store i32* null, i32** %3
br label %36
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = load i32*, i32** %4
%18 = call i32* @BIO_push(i32* %16, i32* %17)
store i32* %18, i32** %4
%19 = load i32*, i32** %5
%20 = load i32*, i32** %4
%21 = call i32* @ASN1_item_d2i_bio(i32* %19, i32* %20, i32* null)
store i32* %21, i32** %7
%22 = load i32*, i32** %7
%23 = icmp ne i32* %22, null
br i1 %23, label %28, label %24
24: ; preds = %15
%25 = load i32, i32* @ASN1_F_B64_READ_ASN1
%26 = load i32, i32* @ASN1_R_DECODE_ERROR
%27 = call i32 @ASN1err(i32 %25, i32 %26)
br label %28
28: ; preds = %24, %15
%29 = load i32*, i32** %4
%30 = call i32 @BIO_flush(i32* %29)
%31 = load i32*, i32** %4
%32 = call i32* @BIO_pop(i32* %31)
store i32* %32, i32** %4
%33 = load i32*, i32** %6
%34 = call i32 @BIO_free(i32* %33)
%35 = load i32*, i32** %7
store i32* %35, i32** %3
br label %36
36: ; preds = %28, %11
%37 = load i32*, i32** %3
ret i32* %37
}

LLVM IR (-O2):
@ASN1_F_B64_READ_ASN1 = global i32 0
@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 %10
6: ; preds = %2
%7 = load i32, i32* @ASN1_F_B64_READ_ASN1
%8 = load i32, i32* @ERR_R_MALLOC_FAILURE
%9 = tail call i32 @ASN1err(i32 %7, i32 %8)
br label %22
10: ; preds = %2
%11 = tail call i32* @BIO_push(i32* %4, i32* %0)
%12 = tail call i32* @ASN1_item_d2i_bio(i32* %1, i32* %11, i32* null)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @ASN1_F_B64_READ_ASN1
%16 = load i32, i32* @ASN1_R_DECODE_ERROR
%17 = tail call i32 @ASN1err(i32 %15, i32 %16)
br label %18
18: ; preds = %14, %10
%19 = tail call i32 @BIO_flush(i32* %11)
%20 = tail call i32* @BIO_pop(i32* %11)
%21 = tail call i32 @BIO_free(i32* %4)
br label %22
22: ; preds = %18, %6
%23 = phi i32* [ %12, %18 ], [ null, %6 ]
ret i32* %23
}