#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*/ __util_assert(char *, char const *, char const *, int, int,
                                 char *);
int vsprintf(char *, char const *, int /*<<< orphan*/);
int __util_vsprintf(const char *func, const char *file, int line, char *str,
                    const char *fmt, va_list ap) {
  int rc;
  rc = vsprintf(str, fmt, ap);
  if (rc == -1)
    __util_assert("rc != -1", func, file, line, rc != -1,
                  "Could not format string\n");
  return rc;
}


x86 assembly (clang, -O0):
<__util_vsprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <vsprintf@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    1187 <__util_vsprintf+0x67>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
cmpl   $0xffffffff,-0x30(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%r8d
lea    0xe85(%rip),%rdi
lea    0xe87(%rip),%r9
call   1030 <__util_assert@plt>
mov    -0x30(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__util_vsprintf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rcx,%rdi
mov    %r8,%rsi
mov    %r9d,%edx
call   1040 <vsprintf@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1164 <__util_vsprintf+0x44>
lea    0xeb4(%rip),%rdi
lea    0xeb6(%rip),%r9
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
xor    %r8d,%r8d
call   1030 <__util_assert@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"rc != -1\00"
@.str.1 = [25 x i8] c"Could not format string\0A\00"
define i32 @__util_vsprintf(i8* %0, i8* %1, i32 %2, i8* %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%14 = load i8*, i8** %10
%15 = load i8*, i8** %11
%16 = load i32, i32* %12
%17 = call i32 @vsprintf(i8* %14, i8* %15, i32 %16)
store i32 %17, i32* %13
%18 = load i32, i32* %13
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %28
20: ; preds = %6
%21 = load i8*, i8** %7
%22 = load i8*, i8** %8
%23 = load i32, i32* %9
%24 = load i32, i32* %13
%25 = icmp ne i32 %24, -1
%26 = zext i1 %25 to i32
%27 = call i32 @__util_assert(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22, i32 %23, i32 %26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %20, %6
%29 = load i32, i32* %13
ret i32 %29
}

LLVM IR (-O2):
@.str = [9 x i8] c"rc != -1\00"
@.str.1 = [25 x i8] c"Could not format string\0A\00"
define i32 @__util_vsprintf(i8* %0, i8* %1, i32 %2, i8* nocapture %3, i8* nocapture %4, i32 %5) {
%7 = tail call i32 @vsprintf(i8* %3, i8* %4, i32 %5)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @__util_assert(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %2, i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
ret i32 %7
}