#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*/ ta_free(char *);
int /*<<< orphan*/ ta_set_parent(char *, void *);
int /*<<< orphan*/ ta_vasprintf_append_at(char **, int /*<<< orphan*/,
                                          char const *, int /*<<< orphan*/);
char *ta_vasprintf(void *ta_parent, const char *fmt, va_list ap) {
  char *res = NULL;
  ta_vasprintf_append_at(&res, 0, fmt, ap);
  if (!res || !ta_set_parent(res, ta_parent)) {
    ta_free(res);
    return NULL;
  }
  return res;
}


x86 assembly (clang, -O0):
<ta_vasprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1040 <ta_vasprintf_append_at@plt>
cmpq   $0x0,-0x28(%rbp)
je     117e <ta_vasprintf+0x4e>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <ta_set_parent@plt>
cmp    $0x0,%eax
jne    1194 <ta_vasprintf+0x64>
mov    -0x28(%rbp),%rdi
call   1030 <ta_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    119c <ta_vasprintf+0x6c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ta_vasprintf>:
push   %r14
push   %rbx
push   %rax
mov    %edx,%ecx
mov    %rsi,%rdx
mov    %rdi,%r14
movq   $0x0,(%rsp)
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1040 <ta_vasprintf_append_at@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1169 <ta_vasprintf+0x39>
mov    %r14,%rsi
call   1050 <ta_set_parent@plt>
mov    (%rsp),%rbx
test   %eax,%eax
jne    1173 <ta_vasprintf+0x43>
mov    %rbx,%rdi
call   1030 <ta_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @ta_vasprintf(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* null, i8** %8
%9 = load i8*, i8** %6
%10 = load i32, i32* %7
%11 = call i32 @ta_vasprintf_append_at(i8** %8, i32 0, i8* %9, i32 %10)
%12 = load i8*, i8** %8
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i8*, i8** %8
%16 = load i8*, i8** %5
%17 = call i32 @ta_set_parent(i8* %15, i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %14, %3
%20 = load i8*, i8** %8
%21 = call i32 @ta_free(i8* %20)
store i8* null, i8** %4
br label %24
22: ; preds = %14
%23 = load i8*, i8** %8
store i8* %23, i8** %4
br label %24
24: ; preds = %22, %19
%25 = load i8*, i8** %4
ret i8* %25
}

LLVM IR (-O2):
define i8* @ta_vasprintf(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = call i32 @ta_vasprintf_append_at(i8** %4, i32 0, i8* %1, i32 %2)
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = call i32 @ta_set_parent(i8* %7, i8* %0)
%11 = icmp eq i32 %10, 0
%12 = load i8*, i8** %4
br i1 %11, label %13, label %16
13: ; preds = %9, %3
%14 = phi i8* [ null, %3 ], [ %12, %9 ]
%15 = call i32 @ta_free(i8* %14)
br label %16
16: ; preds = %9, %13
%17 = phi i8* [ null, %13 ], [ %12, %9 ]
ret i8* %17
}