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

/* Variables and functions */
int BIO_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ CRYPTO_pop_info();
int /*<<< orphan*/ CRYPTO_push_info(char *);
int /*<<< orphan*/ OPENSSL_free(char *);
int /*<<< orphan*/ _dopr(char **, char **, size_t *, size_t *, int *,
                         char const *, int /*<<< orphan*/);
int BIO_vprintf(BIO *bio, const char *format, va_list args) {
  int ret;
  size_t retlen;
  char hugebuf[1024 * 2];
  char *hugebufp = hugebuf;
  size_t hugebufsize = sizeof(hugebuf);
  char *dynbuf = NULL;
  int ignored;
  dynbuf = NULL;
  CRYPTO_push_info("doapr()");
  _dopr(&hugebufp, &dynbuf, &hugebufsize, &retlen, &ignored, format, args);
  if (dynbuf) {
    ret = BIO_write(bio, dynbuf, (int)retlen);
    OPENSSL_free(dynbuf);
  } else {
    ret = BIO_write(bio, hugebuf, (int)retlen);
  }
  CRYPTO_pop_info();
  return (ret);
}


x86 assembly (clang, -O0):
<BIO_vprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x820(%rbp),%rax
mov    %rax,-0x828(%rbp)
movq   $0x800,-0x830(%rbp)
movq   $0x0,-0x838(%rbp)
movq   $0x0,-0x838(%rbp)
lea    0xe64(%rip),%rdi
call   1030 <CRYPTO_push_info@plt>
mov    -0x10(%rbp),%r9
mov    -0x14(%rbp),%eax
lea    -0x828(%rbp),%rdi
lea    -0x838(%rbp),%rsi
lea    -0x830(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x83c(%rbp),%r8
mov    %eax,(%rsp)
call   1060 <_dopr@plt>
cmpq   $0x0,-0x838(%rbp)
je     1208 <BIO_vprintf+0xb8>
mov    -0x8(%rbp),%rdi
mov    -0x838(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
call   1070 <BIO_write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x838(%rbp),%rdi
call   1050 <OPENSSL_free@plt>
jmp    1221 <BIO_vprintf+0xd1>
mov    -0x8(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
call   1070 <BIO_write@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <CRYPTO_pop_info@plt>
mov    -0x18(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BIO_vprintf>:
push   %rbp
push   %r14
push   %rbx
sub    $0x830,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x30(%rsp),%rax
mov    %rax,0x18(%rsp)
movq   $0x800,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe7a(%rip),%rdi
call   1030 <CRYPTO_push_info@plt>
mov    %ebp,(%rsp)
lea    0x18(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0x2c(%rsp),%r8
mov    %rbx,%r9
call   1060 <_dopr@plt>
mov    0x8(%rsp),%rsi
mov    0x20(%rsp),%edx
test   %rsi,%rsi
je     11d3 <BIO_vprintf+0x83>
mov    %r14,%rdi
call   1070 <BIO_write@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1050 <OPENSSL_free@plt>
jmp    11e2 <BIO_vprintf+0x92>
lea    0x30(%rsp),%rsi
mov    %r14,%rdi
call   1070 <BIO_write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <CRYPTO_pop_info@plt>
mov    %ebx,%eax
add    $0x830,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"doapr()\00"
define i32 @BIO_vprintf(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca [2048 x i8]
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
store i8* %14, i8** %10
store i64 2048, i64* %11
store i8* null, i8** %12
store i8* null, i8** %12
%15 = call i32 @CRYPTO_push_info(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = call i32 @_dopr(i8** %10, i8** %12, i64* %11, i64* %8, i32* %13, i8* %16, i32 %17)
%19 = load i8*, i8** %12
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %29
21: ; preds = %3
%22 = load i32*, i32** %4
%23 = load i8*, i8** %12
%24 = load i64, i64* %8
%25 = trunc i64 %24 to i32
%26 = call i32 @BIO_write(i32* %22, i8* %23, i32 %25)
store i32 %26, i32* %7
%27 = load i8*, i8** %12
%28 = call i32 @OPENSSL_free(i8* %27)
br label %35
29: ; preds = %3
%30 = load i32*, i32** %4
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%32 = load i64, i64* %8
%33 = trunc i64 %32 to i32
%34 = call i32 @BIO_write(i32* %30, i8* %31, i32 %33)
store i32 %34, i32* %7
br label %35
35: ; preds = %29, %21
%36 = call i32 (...) @CRYPTO_pop_info()
%37 = load i32, i32* %7
ret i32 %37
}

LLVM IR (-O2):
@.str = [8 x i8] c"doapr()\00"
define i32 @BIO_vprintf(i32* %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca [2048 x i8]
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = bitcast i64* %4 to i8*
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%12 = bitcast i8** %6 to i8*
store i8* %11, i8** %6
%13 = bitcast i64* %7 to i8*
store i64 2048, i64* %7
%14 = bitcast i8** %8 to i8*
%15 = bitcast i32* %9 to i8*
store i8* null, i8** %8
%16 = call i32 @CRYPTO_push_info(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @_dopr(i8** %6, i8** %8, i64* %7, i64* %4, i32* %9, i8* %1, i32 %2)
%18 = load i8*, i8** %8
%19 = icmp eq i8* %18, null
%20 = load i64, i64* %4
%21 = trunc i64 %20 to i32
br i1 %19, label %26, label %22
22: ; preds = %3
%23 = call i32 @BIO_write(i32* %0, i8* %18, i32 %21)
%24 = load i8*, i8** %8
%25 = call i32 @OPENSSL_free(i8* %24)
br label %28
26: ; preds = %3
%27 = call i32 @BIO_write(i32* %0, i8* %11, i32 %21)
br label %28
28: ; preds = %26, %22
%29 = phi i32 [ %23, %22 ], [ %27, %26 ]
%30 = call i32 (...) @CRYPTO_pop_info()
ret i32 %29
}