#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*/ __wdie(char *);
int /*<<< orphan*/ assert(char const *);
int vsnprintf(char *, size_t, char const *, int /*<<< orphan*/);
int __wxvsnprintf(char *string, size_t size, const char *format, va_list args) {
  assert(format);
  int len = vsnprintf(string, size, format, args);
  if (len >= 0)
    return len;
  __wdie("Out of memory.");
  return -1;
}


x86 assembly (clang, -O0):
<__wxvsnprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1030 <vsnprintf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     117c <__wxvsnprintf+0x4c>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <__wxvsnprintf+0x5f>
lea    0xe7d(%rip),%rdi
call   1050 <__wdie@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__wxvsnprintf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %rdx,%rdi
call   1040 <assert@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1030 <vsnprintf@plt>
test   %eax,%eax
jns    1171 <__wxvsnprintf+0x41>
lea    0xe99(%rip),%rdi
call   1050 <__wdie@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Out of memory.\00"
define i32 @__wxvsnprintf(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i8*, i8** %8
%12 = call i32 @assert(i8* %11)
%13 = load i8*, i8** %6
%14 = load i64, i64* %7
%15 = load i8*, i8** %8
%16 = load i32, i32* %9
%17 = call i32 @vsnprintf(i8* %13, i64 %14, i8* %15, i32 %16)
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = load i32, i32* %10
store i32 %21, i32* %5
br label %24
22: ; preds = %4
%23 = call i32 @__wdie(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %24
24: ; preds = %22, %20
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
@.str = [15 x i8] c"Out of memory.\00"
define i32 @__wxvsnprintf(i8* nocapture %0, i64 %1, i8* %2, i32 %3) {
%5 = tail call i32 @assert(i8* %2)
%6 = tail call i32 @vsnprintf(i8* %0, i64 %1, i8* %2, i32 %3)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @__wdie(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %4, %8
%11 = phi i32 [ -1, %8 ], [ %6, %4 ]
ret i32 %11
}