#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*/ 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;
int i2d_ASN1_bio_stream(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/ *, int, int /*<<< orphan*/ const *);
int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
                   const ASN1_ITEM *it) {
  BIO *b64;
  int r;
  b64 = BIO_new(BIO_f_base64());
  if (!b64) {
    ASN1error(ERR_R_MALLOC_FAILURE);
    return 0;
  }
  out = BIO_push(b64, out);
  r = i2d_ASN1_bio_stream(out, val, in, flags, it);
  (void)BIO_flush(out);
  BIO_pop(out);
  BIO_free(b64);
  return r;
}


x86 assembly (clang, -O0):
<B64_write_ASN1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    $0x0,%al
call   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d2 <B64_write_ASN1+0x52>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1090 <ASN1error@plt>
movl   $0x0,-0x4(%rbp)
jmp    121f <B64_write_ASN1+0x9f>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%r8
call   1080 <i2d_ASN1_bio_stream@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <BIO_flush@plt>
mov    -0x10(%rbp),%rdi
call   1050 <BIO_pop@plt>
mov    -0x38(%rbp),%rdi
call   1070 <BIO_free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<B64_write_ASN1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
xor    %eax,%eax
call   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
test   %rax,%rax
je     11f2 <B64_write_ASN1+0x72>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %r14,%r8
call   1080 <i2d_ASN1_bio_stream@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   10a0 <BIO_flush@plt>
mov    %rbp,%rdi
call   1050 <BIO_pop@plt>
mov    %rbx,%rdi
call   1070 <BIO_free@plt>
mov    %r14d,%eax
jmp    1202 <B64_write_ASN1+0x82>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1090 <ASN1error@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_MALLOC_FAILURE = global i32 0
define i32 @B64_write_ASN1(i32* %0, i32* %1, i32* %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store i32* %4, i32** %11
%14 = call i32 (...) @BIO_f_base64()
%15 = call i32* @BIO_new(i32 %14)
store i32* %15, i32** %12
%16 = load i32*, i32** %12
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %5
%19 = load i32, i32* @ERR_R_MALLOC_FAILURE
%20 = call i32 @ASN1error(i32 %19)
store i32 0, i32* %6
br label %38
21: ; preds = %5
%22 = load i32*, i32** %12
%23 = load i32*, i32** %7
%24 = call i32* @BIO_push(i32* %22, i32* %23)
store i32* %24, i32** %7
%25 = load i32*, i32** %7
%26 = load i32*, i32** %8
%27 = load i32*, i32** %9
%28 = load i32, i32* %10
%29 = load i32*, i32** %11
%30 = call i32 @i2d_ASN1_bio_stream(i32* %25, i32* %26, i32* %27, i32 %28, i32* %29)
store i32 %30, i32* %13
%31 = load i32*, i32** %7
%32 = call i32 @BIO_flush(i32* %31)
%33 = load i32*, i32** %7
%34 = call i32 @BIO_pop(i32* %33)
%35 = load i32*, i32** %12
%36 = call i32 @BIO_free(i32* %35)
%37 = load i32, i32* %13
store i32 %37, i32* %6
br label %38
38: ; preds = %21, %18
%39 = load i32, i32* %6
ret i32 %39
}

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