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

/* Variables and functions */
int /*<<< orphan*/ Sys_failure(char *);
int /*<<< orphan*/ Warning(char *);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int vsnprintf(char *, size_t, char const *, int /*<<< orphan*/);
void Vsnprintf(char *str, size_t size, const char *format, va_list ap) {
  int retval;
  assert(str != NULL);
  assert(format != NULL);
  retval = vsnprintf(str, size, format, ap);
  if (retval < 0)
    Sys_failure("vsnprintf");
  if (retval == size - 1)
    Warning("vsnprintf: the output may be truncated.");
}


x86 assembly (clang, -O0):
<Vsnprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <vsnprintf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11a8 <Vsnprintf+0x68>
lea    0xe5d(%rip),%rdi
call   1060 <Sys_failure@plt>
movslq -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jne    11c9 <Vsnprintf+0x89>
lea    0xe46(%rip),%rdi
call   1050 <Warning@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Vsnprintf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1040 <assert@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <vsnprintf@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1192 <Vsnprintf+0x52>
lea    0xe73(%rip),%rdi
call   1060 <Sys_failure@plt>
movslq %ebp,%rax
add    $0xffffffffffffffff,%rbx
cmp    %rax,%rbx
jne    11b4 <Vsnprintf+0x74>
lea    0xe65(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <Warning@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"vsnprintf\00"
@.str.1 = [40 x i8] c"vsnprintf: the output may be truncated.\00"
define void @Vsnprintf(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = call i32 @vsnprintf(i8* %18, i64 %19, i8* %20, i32 %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %4
%26 = call i32 @Sys_failure(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %4
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = load i64, i64* %6
%31 = sub i64 %30, 1
%32 = icmp eq i64 %29, %31
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 @Warning(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %27
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"vsnprintf\00"
@.str.1 = [40 x i8] c"vsnprintf: the output may be truncated.\00"
define void @Vsnprintf(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = icmp ne i8* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp ne i8* %2, null
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @vsnprintf(i8* %0, i64 %1, i8* %2, i32 %3)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = tail call i32 @Sys_failure(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %4
%16 = sext i32 %11 to i64
%17 = add i64 %1, -1
%18 = icmp eq i64 %17, %16
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i32 @Warning(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
ret void
}