#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*/ assert(int);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char const *);
char *xrealloc(char *, scalar_t__);
char *strappend(char **dest, const char *src) {
  assert(dest != NULL && src != NULL);
  *dest = xrealloc(*dest, strlen(*dest) + strlen(src) + 1);
  strcat(*dest, src);
  return *dest;
}


x86 assembly (clang, -O0):
<strappend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
je     116b <strappend+0x2b>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
call   1040 <xrealloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strappend>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
mov    (%rbx),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%rsi
add    $0x1,%rsi
mov    %r15,%rdi
call   1040 <xrealloc@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    (%rbx),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strappend(i8** %0, i8* %1) {
%3 = icmp ne i8** %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = load i8*, i8** %0
%9 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = add i64 %9, 1
%12 = add i64 %11, %10
%13 = tail call i8* @xrealloc(i8* %8, i64 %12)
store i8* %13, i8** %0
%14 = tail call i32 @strcat(i8* %13, i8* %1)
%15 = load i8*, i8** %0
ret i8* %15
}