#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*/ outbuf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int vsnprintf(char *, int, char const *, int /*<<< orphan*/);
int vfprintf(FILE *fp, const char *fmt, va_list ap) {
  char outbuf[256];
  int r;
  if (fmt == NULL)
    return 0;
  r = vsnprintf(outbuf, sizeof(outbuf), fmt, ap);
  if (r > 0)
    fputs(outbuf, fp);
  return r;
}


x86 assembly (clang, -O0):
<vfprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114d <vfprintf+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    1191 <vfprintf+0x71>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    $0x100,%esi
call   1030 <vsnprintf@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jle    1188 <vfprintf+0x68>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vfprintf>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
test   %rsi,%rsi
je     1156 <vfprintf+0x36>
mov    %edx,%ecx
mov    %rsi,%rdx
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1030 <vsnprintf@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1158 <vfprintf+0x38>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
jmp    1158 <vfprintf+0x38>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
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 [256 x i8]
%9 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 0, i32* %4
br label %26
13: ; preds = %3
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = call i32 @vsnprintf(i8* %14, i32 256, i8* %15, i32 %16)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%22 = load i32*, i32** %5
%23 = call i32 @fputs(i8* %21, i32* %22)
br label %24
24: ; preds = %20, %13
%25 = load i32, i32* %9
store i32 %25, i32* %4
br label %26
26: ; preds = %24, %12
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
define i32 @vfprintf(i32* nocapture %0, i8* %1, i32 %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8* %1, null
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = call i32 @vsnprintf(i8* %5, i32 256, i8* %1, i32 %2)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @fputs(i8* %5, i32* %0)
br label %12
12: ; preds = %7, %10, %3
%13 = phi i32 [ 0, %3 ], [ %8, %10 ], [ %8, %7 ]
ret i32 %13
}