#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;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int vsnprintf(char *, int, char const *, int /*<<< orphan*/);
int vprintf(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, stdout);
  fflush(stdout);
  return r;
}


x86 assembly (clang, -O0):
<vprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1159 <vprintf+0x29>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <vprintf+0x80>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x100,%esi
call   1030 <vsnprintf@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jle    1199 <vprintf+0x69>
lea    -0x120(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vprintf>:
push   %rbx
sub    $0x100,%rsp
test   %rdi,%rdi
je     1176 <vprintf+0x46>
mov    %esi,%ecx
mov    %rdi,%rdx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1030 <vsnprintf@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1166 <vprintf+0x36>
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1040 <fputs@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
jmp    1178 <vprintf+0x48>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
define i32 @vprintf(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %26
11: ; preds = %2
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = load i32, i32* %5
%15 = call i32 @vsnprintf(i8* %12, i32 256, i8* %13, i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%20 = load i32, i32* @stdout
%21 = call i32 @fputs(i8* %19, i32 %20)
br label %22
22: ; preds = %18, %11
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
%25 = load i32, i32* %7
store i32 %25, i32* %3
br label %26
26: ; preds = %22, %10
%27 = load i32, i32* %3
ret i32 %27
}

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