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

/* Variables and functions */
int /*<<< orphan*/ VM_putchar(int /*<<< orphan*/);
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
void VM_vprintf(const char *fmt, va_list ap) {
  char buf[80], *p = buf;
  vsnprintf(buf, sizeof(buf), fmt, ap);
  while (*p != '\0')
    VM_putchar(*p++);
}


x86 assembly (clang, -O0):
<VM_vprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    $0x50,%esi
call   1030 <vsnprintf@plt>
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1178 <VM_vprintf+0x58>
mov    -0x68(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x68(%rbp)
movsbl (%rax),%edi
call   1040 <VM_putchar@plt>
jmp    114c <VM_vprintf+0x2c>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VM_vprintf>:
push   %rbx
sub    $0x50,%rsp
mov    %esi,%ecx
mov    %rdi,%rdx
mov    %rsp,%rdi
mov    $0x50,%esi
call   1030 <vsnprintf@plt>
mov    (%rsp),%al
test   %al,%al
je     1163 <VM_vprintf+0x43>
lea    0x1(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1040 <VM_putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <VM_vprintf+0x30>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @VM_vprintf(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
store i8* %7, i8** %6
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = load i32, i32* %4
%11 = call i32 @vsnprintf(i8* %8, i32 80, i8* %9, i32 %10)
br label %12
12: ; preds = %17, %2
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %6
%20 = load i8, i8* %18
%21 = sext i8 %20 to i32
%22 = call i32 @VM_putchar(i32 %21)
br label %12
23: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @VM_vprintf(i8* nocapture %0, i32 %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = call i32 @vsnprintf(i8* %4, i32 80, i8* %0, i32 %1)
%6 = load i8, i8* %4
%7 = icmp eq i8 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %2, %8
%9 = phi i8 [ %14, %8 ], [ %6, %2 ]
%10 = phi i8* [ %12, %8 ], [ %4, %2 ]
%11 = sext i8 %9 to i32
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = tail call i32 @VM_putchar(i32 %11)
%14 = load i8, i8* %12
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %8, %2
ret void
}