#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*/ strcat(char *, char const *);
int strlen(char const *);
scalar_t__ xrealloc(char *, size_t);
char *xstrdup(char const *);
char *xstrappend(char *src, const char *newd) {
  size_t newsz;
  if (!src) {
    return xstrdup(newd);
  }
  if (!newd) {
    return xstrdup(src);
  }
  newsz = strlen(src) + strlen(newd) + 1;
  src = (char *)xrealloc(src, newsz);
  strcat(src, newd);
  return src;
}


x86 assembly (clang, -O0):
<xstrappend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <xstrappend+0x2d>
mov    -0x18(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11d5 <xstrappend+0x95>
cmpq   $0x0,-0x18(%rbp)
jne    118a <xstrappend+0x4a>
mov    -0x10(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11d5 <xstrappend+0x95>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <xrealloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrappend>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     1190 <xstrappend+0x50>
mov    %rdi,%rbx
test   %r14,%r14
je     1195 <xstrappend+0x55>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %r15d,%eax
add    $0x1,%eax
movslq %eax,%rsi
mov    %rbx,%rdi
call   1040 <xrealloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
jmp    1198 <xstrappend+0x58>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <xstrdup@plt>

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

LLVM IR (-O2):
define i8* @xstrappend(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* @xstrdup(i8* %1)
br label %19
6: ; preds = %2
%7 = icmp eq i8* %1, null
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i8* @xstrdup(i8* %0)
br label %19
10: ; preds = %6
%11 = tail call i32 @strlen(i8* %0)
%12 = tail call i32 @strlen(i8* %1)
%13 = add i32 %11, 1
%14 = add i32 %13, %12
%15 = sext i32 %14 to i64
%16 = tail call i64 @xrealloc(i8* %0, i64 %15)
%17 = inttoptr i64 %16 to i8*
%18 = tail call i32 @strcat(i8* %17, i8* %1)
br label %19
19: ; preds = %10, %8, %4
%20 = phi i8* [ %17, %10 ], [ %9, %8 ], [ %5, %4 ]
ret i8* %20
}