#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 */
size_t INT_MAX;
int /*<<< orphan*/ _dopr(char **, int /*<<< orphan*/ *, size_t *, size_t *,
                         int *, char const *, int /*<<< orphan*/);
int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) {
  size_t retlen;
  int truncated;
  _dopr(&buf, NULL, &n, &retlen, &truncated, format, args);
  if (truncated)
    return -1;
  else
    return (retlen <= INT_MAX) ? (int)retlen : -1;
}


x86 assembly (clang, -O0):
<BIO_vsnprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%r9
mov    -0x24(%rbp),%eax
lea    -0x10(%rbp),%rdi
xor    %ecx,%ecx
mov    %ecx,%esi
lea    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r8
mov    %eax,(%rsp)
call   1030 <_dopr@plt>
cmpl   $0x0,-0x34(%rbp)
je     1160 <BIO_vsnprintf+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    1193 <BIO_vsnprintf+0x83>
mov    -0x30(%rbp),%rax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
ja     1180 <BIO_vsnprintf+0x70>
mov    -0x30(%rbp),%rax
mov    %eax,-0x38(%rbp)
jmp    118d <BIO_vsnprintf+0x7d>
mov    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    118d <BIO_vsnprintf+0x7d>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BIO_vsnprintf>:
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%r9
mov    %rdi,0x28(%rsp)
mov    %rsi,0x20(%rsp)
mov    %ecx,(%rsp)
xor    %ebx,%ebx
lea    0x28(%rsp),%rdi
lea    0x20(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r8
xor    %esi,%esi
call   1030 <_dopr@plt>
mov    0x18(%rsp),%rax
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%rax
mov    $0xffffffff,%ecx
cmovbe %eax,%ecx
cmp    0x14(%rsp),%ebx
sbb    %eax,%eax
or     %ecx,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@INT_MAX = global i64 0
define i32 @BIO_vsnprintf(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 i64
%11 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %8
%13 = load i32, i32* %9
%14 = call i32 @_dopr(i8** %6, i32* null, i64* %7, i64* %10, i32* %11, i8* %12, i32 %13)
%15 = load i32, i32* %11
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -1, i32* %5
br label %28
18: ; preds = %4
%19 = load i64, i64* %10
%20 = load i64, i64* @INT_MAX
%21 = icmp ule i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i64, i64* %10
%24 = trunc i64 %23 to i32
br label %26
25: ; preds = %18
br label %26
26: ; preds = %25, %22
%27 = phi i32 [ %24, %22 ], [ -1, %25 ]
store i32 %27, i32* %5
br label %28
28: ; preds = %26, %17
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
@INT_MAX = global i64 0
define i32 @BIO_vsnprintf(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
%9 = bitcast i64* %7 to i8*
%10 = bitcast i32* %8 to i8*
%11 = call i32 @_dopr(i8** %5, i32* null, i64* %6, i64* %7, i32* %8, i8* %2, i32 %3)
%12 = load i32, i32* %8
%13 = icmp eq i32 %12, 0
%14 = load i64, i64* %7
%15 = load i64, i64* @INT_MAX
%16 = icmp ugt i64 %14, %15
%17 = trunc i64 %14 to i32
%18 = select i1 %16, i32 -1, i32 %17
%19 = select i1 %13, i32 %18, i32 -1
ret i32 %19
}