#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 /*<<< orphan*/ strlcat(char *, char const *, size_t);
int strlen(char const *);
char *xrealloc(char *, size_t);
char *xstrdup(char const *);
void xstrappend(char **str, const char *suffix) {
  if (!*str) {
    *str = xstrdup(suffix);
    return;
  }
  size_t len = strlen(*str) + strlen(suffix) + 1;
  *str = xrealloc(*str, len);
  strlcat(*str, suffix, len);
}


x86 assembly (clang, -O0):
<xstrappend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1176 <xstrappend+0x36>
mov    -0x10(%rbp),%rdi
call   1060 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    11cc <xstrappend+0x8c>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <xrealloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strlcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrappend>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     118d <xstrappend+0x4d>
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r15d,%eax
add    $0x1,%eax
movslq %eax,%r15
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1050 <xrealloc@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strlcat@plt>
mov    %r14,%rdi
call   1060 <xstrdup@plt>
mov    %rax,(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @xstrappend(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i64
store i8** %0, i8*** %3
store i8* %1, i8** %4
%6 = load i8**, i8*** %3
%7 = load i8*, i8** %6
%8 = icmp ne i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i8* @xstrdup(i8* %10)
%12 = load i8**, i8*** %3
store i8* %11, i8** %12
br label %32
13: ; preds = %2
%14 = load i8**, i8*** %3
%15 = load i8*, i8** %14
%16 = call i32 @strlen(i8* %15)
%17 = load i8*, i8** %4
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %16, %18
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
store i64 %21, i64* %5
%22 = load i8**, i8*** %3
%23 = load i8*, i8** %22
%24 = load i64, i64* %5
%25 = call i8* @xrealloc(i8* %23, i64 %24)
%26 = load i8**, i8*** %3
store i8* %25, i8** %26
%27 = load i8**, i8*** %3
%28 = load i8*, i8** %27
%29 = load i8*, i8** %4
%30 = load i64, i64* %5
%31 = call i32 @strlcat(i8* %28, i8* %29, i64 %30)
br label %32
32: ; preds = %13, %9
ret void
}

LLVM IR (-O2):
define void @xstrappend(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i8* @xstrdup(i8* %1)
store i8* %6, i8** %0
br label %16
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %3)
%9 = tail call i32 @strlen(i8* %1)
%10 = add i32 %8, 1
%11 = add i32 %10, %9
%12 = sext i32 %11 to i64
%13 = load i8*, i8** %0
%14 = tail call i8* @xrealloc(i8* %13, i64 %12)
store i8* %14, i8** %0
%15 = tail call i32 @strlcat(i8* %14, i8* %1, i64 %12)
br label %16
16: ; preds = %7, %5
ret void
}