#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 */

/* Variables and functions */
int asprintf(char **, char *, char *, char const *);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ free(char *);
void astrcat(char **out, const char *add) {
  char *tmp = *out;
  if (asprintf(out, "%s%s", tmp ?: "", add) == -1) {
    die("asprintf failed");
  }
  free(tmp);
}


x86 assembly (clang, -O0):
<astrcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1172 <astrcat+0x42>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1182 <astrcat+0x52>
lea    0xe9b(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1182 <astrcat+0x52>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe6b(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    11af <astrcat+0x7f>
lea    0xe5b(%rip),%rdi
call   1050 <die@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astrcat>:
push   %rbx
mov    %rsi,%rcx
mov    (%rdi),%rbx
test   %rbx,%rbx
lea    0xed3(%rip),%rdx
cmovne %rbx,%rdx
lea    0xeb4(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    1162 <astrcat+0x32>
lea    0xea8(%rip),%rdi
call   1050 <die@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [16 x i8] c"asprintf failed\00"
define void @astrcat(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%6 = load i8**, i8*** %3
%7 = load i8*, i8** %6
store i8* %7, i8** %5
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
br label %13
12: ; preds = %2
br label %13
13: ; preds = %12, %11
%14 = phi i8* [ %9, %11 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %12 ]
%15 = load i8*, i8** %4
%16 = call i32 @asprintf(i8** %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = load i8*, i8** %5
%22 = call i32 @free(i8* %21)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [16 x i8] c"asprintf failed\00"
define void @astrcat(i8** %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %3
%6 = tail call i32 @asprintf(i8** %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = tail call i32 @free(i8* %3)
ret void
}