#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int vsnprintf(char *, size_t, char const *, int /*<<< orphan*/);
int xvsnprintf(char *str, size_t size, const char *format, va_list ap) {
  int retval;
  retval = vsnprintf(str, size, format, ap);
  if (retval >= size) {
    fprintf(stderr,
            "Buffer of size not large enough to format entire string '%s'\n",
            str);
    exit(10);
  }
  return retval;
}


x86 assembly (clang, -O0):
<xvsnprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <vsnprintf@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     118f <xvsnprintf+0x5f>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xa,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xvsnprintf>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <vsnprintf@plt>
movslq %eax,%rcx
cmp    %rbx,%rcx
jae    114f <xvsnprintf+0x1f>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0xa,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [62 x i8] c"Buffer of size not large enough to format entire string '%s'\0A\00"
define i32 @xvsnprintf(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 = load i64, i64* %6
%12 = load i8*, i8** %7
%13 = load i32, i32* %8
%14 = call i32 @vsnprintf(i8* %10, i64 %11, i8* %12, i32 %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = sext i32 %15 to i64
%17 = load i64, i64* %6
%18 = icmp uge i64 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %4
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %5
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 10)
unreachable
24: ; preds = %4
%25 = load i32, i32* %9
ret i32 %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [62 x i8] c"Buffer of size not large enough to format entire string '%s'\0A\00"
define i32 @xvsnprintf(i8* %0, i64 %1, i8* nocapture %2, i32 %3) {
%5 = tail call i32 @vsnprintf(i8* %0, i64 %1, i8* %2, i32 %3)
%6 = sext i32 %5 to i64
%7 = icmp ult i64 %6, %1
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = tail call i32 @exit(i32 10)
unreachable
12: ; preds = %4
ret i32 %5
}