#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 */
scalar_t__ ENOMEM;
scalar_t__ errno;
int /*<<< orphan*/ oom_die();
scalar_t__ vasprintf(char **, char const *, int /*<<< orphan*/);
char *xvasprintf(const char *fmt, va_list ap) {
  char *ret;
  if (vasprintf(&ret, fmt, ap) < 0) {
    if (errno == ENOMEM)
      oom_die();
    return NULL;
  }
  return ret;
}


x86 assembly (clang, -O0):
<xvasprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rdi
call   1030 <vasprintf@plt>
cmp    $0x0,%rax
jge    1177 <xvasprintf+0x57>
mov    0x2e88(%rip),%rax
mov    (%rax),%rax
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%rax
jne    116a <xvasprintf+0x4a>
mov    $0x0,%al
call   1040 <oom_die@plt>
movq   $0x0,-0x8(%rbp)
jmp    117f <xvasprintf+0x5f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xvasprintf>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%edx
mov    %rdi,%rsi
lea    0x8(%rsp),%rdi
call   1030 <vasprintf@plt>
test   %rax,%rax
js     1140 <xvasprintf+0x20>
mov    0x8(%rsp),%rbx
jmp    1163 <xvasprintf+0x43>
mov    0x2e91(%rip),%rax
mov    (%rax),%rax
mov    0x2e8f(%rip),%rcx
cmp    (%rcx),%rax
jne    1161 <xvasprintf+0x41>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <oom_die@plt>
jmp    1163 <xvasprintf+0x43>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@ENOMEM = global i64 0
define i8* @xvasprintf(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i32, i32* %5
%9 = call i64 @vasprintf(i8** %6, i8* %7, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOMEM
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 (...) @oom_die()
br label %17
17: ; preds = %15, %11
store i8* null, i8** %3
br label %20
18: ; preds = %2
%19 = load i8*, i8** %6
store i8* %19, i8** %3
br label %20
20: ; preds = %18, %17
%21 = load i8*, i8** %3
ret i8* %21
}

LLVM IR (-O2):
@errno = global i64 0
@ENOMEM = global i64 0
define i8* @xvasprintf(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @vasprintf(i8** %3, i8* %0, i32 %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENOMEM
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = call i32 (...) @oom_die()
br label %15
13: ; preds = %2
%14 = load i8*, i8** %3
br label %15
15: ; preds = %7, %11, %13
%16 = phi i8* [ %14, %13 ], [ null, %11 ], [ null, %7 ]
ret i8* %16
}