#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*/ errno;
scalar_t__ tc_test_string(char const *, int, size_t, int, int /*<<< orphan*/);
int vsnprintf(char *, size_t, char const *, int /*<<< orphan*/);
int _tc_vsnprintf(const char *file, int line, char *buf, size_t limit,
                  const char *format, va_list args) {
  int res = vsnprintf(buf, limit, format, args);
  return tc_test_string(file, line, limit, res, errno) ? -1 : res;
}


x86 assembly (clang, -O0):
<_tc_vsnprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1030 <vsnprintf@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%ecx
mov    0x2e75(%rip),%rax
mov    (%rax),%r8d
call   1040 <tc_test_string@plt>
cmp    $0x0,%rax
je     118a <_tc_vsnprintf+0x6a>
mov    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    1190 <_tc_vsnprintf+0x70>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_tc_vsnprintf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %esi,%r14d
mov    %rdi,%r15
mov    %rdx,%rdi
mov    %rcx,%rsi
mov    %r8,%rdx
mov    %r9d,%ecx
call   1030 <vsnprintf@plt>
mov    %eax,%ebp
mov    0x2e96(%rip),%rax
mov    (%rax),%r8d
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1040 <tc_test_string@plt>
neg    %rax
sbb    %eax,%eax
or     %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @_tc_vsnprintf(i8* %0, i32 %1, i8* %2, i64 %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%14 = load i8*, i8** %9
%15 = load i64, i64* %10
%16 = load i8*, i8** %11
%17 = load i32, i32* %12
%18 = call i32 @vsnprintf(i8* %14, i64 %15, i8* %16, i32 %17)
store i32 %18, i32* %13
%19 = load i8*, i8** %7
%20 = load i32, i32* %8
%21 = load i64, i64* %10
%22 = load i32, i32* %13
%23 = load i32, i32* @errno
%24 = call i64 @tc_test_string(i8* %19, i32 %20, i64 %21, i32 %22, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %6
br label %29
27: ; preds = %6
%28 = load i32, i32* %13
br label %29
29: ; preds = %27, %26
%30 = phi i32 [ -1, %26 ], [ %28, %27 ]
ret i32 %30
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @_tc_vsnprintf(i8* %0, i32 %1, i8* nocapture %2, i64 %3, i8* nocapture %4, i32 %5) {
%7 = tail call i32 @vsnprintf(i8* %2, i64 %3, i8* %4, i32 %5)
%8 = load i32, i32* @errno
%9 = tail call i64 @tc_test_string(i8* %0, i32 %1, i64 %3, i32 %7, i32 %8)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i32 %7, i32 -1
ret i32 %11
}