#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;
struct iobuf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int iobuf_queue(struct iobuf *, char *, int);
int vasprintf(char **, char const *, int /*<<< orphan*/);
int iobuf_vfqueue(struct iobuf *io, const char *fmt, va_list ap) {
  char *buf;
  int len;
  len = vasprintf(&buf, fmt, ap);
  if (len == -1)
    return (-1);
  len = iobuf_queue(io, buf, len);
  free(buf);
  return (len);
}


x86 assembly (clang, -O0):
<iobuf_vfqueue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rdi
call   1040 <vasprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    116c <iobuf_vfqueue+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <iobuf_vfqueue+0x5e>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <iobuf_queue@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iobuf_vfqueue>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1040 <vasprintf@plt>
cmp    $0xffffffff,%eax
je     1164 <iobuf_vfqueue+0x34>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1050 <iobuf_queue@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    1169 <iobuf_vfqueue+0x39>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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