#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*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ free(char *);
int vasprintf(char **, char const *, int /*<<< orphan*/);
int BIO_vprintf(BIO *bio, const char *format, va_list args) {
  int ret;
  char *buf = NULL;
  ret = vasprintf(&buf, format, args);
  if (buf == NULL) {
    ret = -1;
    goto fail;
  }
  BIO_write(bio, buf, ret);
  free(buf);
fail:
  return (ret);
}


x86 assembly (clang, -O0):
<BIO_vprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rdi
call   1040 <vasprintf@plt>
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1175 <BIO_vprintf+0x45>
movl   $0xffffffff,-0x18(%rbp)
jmp    118e <BIO_vprintf+0x5e>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1050 <BIO_write@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BIO_vprintf>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   1040 <vasprintf@plt>
mov    (%rsp),%rsi
test   %rsi,%rsi
je     1167 <BIO_vprintf+0x37>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%edx
call   1050 <BIO_write@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    116c <BIO_vprintf+0x3c>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @BIO_vprintf(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* null, i8** %8
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = call i32 @vasprintf(i8** %8, i8* %9, i32 %10)
store i32 %11, i32* %7
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %7
br label %22
15: ; preds = %3
%16 = load i32*, i32** %4
%17 = load i8*, i8** %8
%18 = load i32, i32* %7
%19 = call i32 @BIO_write(i32* %16, i8* %17, i32 %18)
%20 = load i8*, i8** %8
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %15, %14
%23 = load i32, i32* %7
ret i32 %23
}

LLVM IR (-O2):
define i32 @BIO_vprintf(i32* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = call i32 @vasprintf(i8** %4, i8* %1, i32 %2)
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = call i32 @BIO_write(i32* %0, i8* %7, i32 %6)
%11 = load i8*, i8** %4
%12 = call i32 @free(i8* %11)
br label %13
13: ; preds = %3, %9
%14 = phi i32 [ %6, %9 ], [ -1, %3 ]
ret i32 %14
}