#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__ malloc(int);
int uuid_str_vsnprintf(char *, int, char const *, int /*<<< orphan*/);
char *uuid_str_vasprintf(const char *fmt, va_list ap) {
  char *rv;
  int n;
  n = uuid_str_vsnprintf(NULL, 0, fmt, ap);
  if ((rv = (char *)malloc(n + 1)) == NULL)
    return NULL;
  uuid_str_vsnprintf(rv, n + 1, fmt, ap);
  return rv;
}


x86 assembly (clang, -O0):
<uuid_str_vasprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1030 <uuid_str_vsnprintf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    116a <uuid_str_vasprintf+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    1188 <uuid_str_vasprintf+0x68>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1030 <uuid_str_vsnprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uuid_str_vasprintf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
xor    %r12d,%r12d
xor    %edi,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <uuid_str_vsnprintf@plt>
mov    %eax,%ebx
add    $0x1,%ebx
mov    %ebx,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1167 <uuid_str_vasprintf+0x47>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <uuid_str_vsnprintf@plt>
mov    %rbp,%r12
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @uuid_str_vasprintf(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = load i32, i32* %5
%10 = call i32 @uuid_str_vsnprintf(i8* null, i32 0, i8* %8, i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = add nsw i32 %11, 1
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i8* null, i8** %3
br label %25
17: ; preds = %2
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = call i32 @uuid_str_vsnprintf(i8* %18, i32 %20, i8* %21, i32 %22)
%24 = load i8*, i8** %6
store i8* %24, i8** %3
br label %25
25: ; preds = %17, %16
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
define i8* @uuid_str_vasprintf(i8* %0, i32 %1) {
%3 = tail call i32 @uuid_str_vsnprintf(i8* null, i32 0, i8* %0, i32 %1)
%4 = add nsw i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @uuid_str_vsnprintf(i8* %6, i32 %4, i8* %0, i32 %1)
br label %10
10: ; preds = %2, %8
%11 = phi i8* [ %6, %8 ], [ null, %2 ]
ret i8* %11
}