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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char *);
char *vsaprintf(char const *, int /*<<< orphan*/);
int vfprintf(FILE *stream, const char *format, va_list ap) {
  char *string;
  if (!stream) {
    return -1;
  }
  string = vsaprintf(format, ap);
  if (!string) {
    return -1;
  }
  fwrite(string, strlen(string), sizeof(char), stream);
  free(string);
  return 0;
}


x86 assembly (clang, -O0):
<vfprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116a <vfprintf+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <vfprintf+0x86>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <vsaprintf@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1191 <vfprintf+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <vfprintf+0x86>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vfprintf>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1187 <vfprintf+0x47>
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %edx,%esi
call   1050 <vsaprintf@plt>
test   %rax,%rax
je     1187 <vfprintf+0x47>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @vfprintf(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %3
store i32 -1, i32* %4
br label %27
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = call i8* @vsaprintf(i8* %13, i32 %14)
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %12
store i32 -1, i32* %4
br label %27
19: ; preds = %12
%20 = load i8*, i8** %8
%21 = load i8*, i8** %8
%22 = call i32 @strlen(i8* %21)
%23 = load i32*, i32** %5
%24 = call i32 @fwrite(i8* %20, i32 %22, i32 1, i32* %23)
%25 = load i8*, i8** %8
%26 = call i32 @free(i8* %25)
store i32 0, i32* %4
br label %27
27: ; preds = %19, %18, %11
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
define i32 @vfprintf(i32* %0, i8* %1, i32 %2) {
%4 = icmp eq i32* %0, null
br i1 %4, label %12, label %5
5: ; preds = %3
%6 = tail call i8* @vsaprintf(i8* %1, i32 %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call i32 @strlen(i8* %6)
%10 = tail call i32 @fwrite(i8* %6, i32 %9, i32 1, i32* %0)
%11 = tail call i32 @free(i8* %6)
br label %12
12: ; preds = %5, %3, %8
%13 = phi i32 [ 0, %8 ], [ -1, %3 ], [ -1, %5 ]
ret i32 %13
}