#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_WRITE_ASN1;
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;
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) {
    ASN1err(ASN1_F_B64_WRITE_ASN1, 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   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11db <B64_write_ASN1+0x5b>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1228 <B64_write_ASN1+0xa8>
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   1090 <i2d_ASN1_bio_stream@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <BIO_flush@plt>
mov    -0x10(%rbp),%rdi
call   1060 <BIO_pop@plt>
mov    -0x38(%rbp),%rdi
call   1080 <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   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <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   1090 <i2d_ASN1_bio_stream@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   10a0 <BIO_flush@plt>
mov    %rbp,%rdi
call   1060 <BIO_pop@plt>
mov    %rbx,%rdi
call   1080 <BIO_free@plt>
mov    %r14d,%eax
jmp    120b <B64_write_ASN1+0x8b>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ASN1_F_B64_WRITE_ASN1 = global i32 0
@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 %22, label %18
18: ; preds = %5
%19 = load i32, i32* @ASN1_F_B64_WRITE_ASN1
%20 = load i32, i32* @ERR_R_MALLOC_FAILURE
%21 = call i32 @ASN1err(i32 %19, i32 %20)
store i32 0, i32* %6
br label %39
22: ; preds = %5
%23 = load i32*, i32** %12
%24 = load i32*, i32** %7
%25 = call i32* @BIO_push(i32* %23, i32* %24)
store i32* %25, i32** %7
%26 = load i32*, i32** %7
%27 = load i32*, i32** %8
%28 = load i32*, i32** %9
%29 = load i32, i32* %10
%30 = load i32*, i32** %11
%31 = call i32 @i2d_ASN1_bio_stream(i32* %26, i32* %27, i32* %28, i32 %29, i32* %30)
store i32 %31, i32* %13
%32 = load i32*, i32** %7
%33 = call i32 @BIO_flush(i32* %32)
%34 = load i32*, i32** %7
%35 = call i32 @BIO_pop(i32* %34)
%36 = load i32*, i32** %12
%37 = call i32 @BIO_free(i32* %36)
%38 = load i32, i32* %13
store i32 %38, i32* %6
br label %39
39: ; preds = %22, %18
%40 = load i32, i32* %6
ret i32 %40
}

LLVM IR (-O2):
@ASN1_F_B64_WRITE_ASN1 = global i32 0
@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 %13
9: ; preds = %5
%10 = load i32, i32* @ASN1_F_B64_WRITE_ASN1
%11 = load i32, i32* @ERR_R_MALLOC_FAILURE
%12 = tail call i32 @ASN1err(i32 %10, i32 %11)
br label %19
13: ; preds = %5
%14 = tail call i32* @BIO_push(i32* %7, i32* %0)
%15 = tail call i32 @i2d_ASN1_bio_stream(i32* %14, i32* %1, i32* %2, i32 %3, i32* %4)
%16 = tail call i32 @BIO_flush(i32* %14)
%17 = tail call i32 @BIO_pop(i32* %14)
%18 = tail call i32 @BIO_free(i32* %7)
br label %19
19: ; preds = %13, %9
%20 = phi i32 [ %15, %13 ], [ 0, %9 ]
ret i32 %20
}