#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*/ memcpy(char *, char const *, size_t);
scalar_t__ realloc(char *, size_t);
size_t strlen(char const *);
void append(char **source, const char *appendix) {
  size_t string_length = strlen(*source);
  size_t appendix_length = strlen(appendix);
  size_t length = string_length + appendix_length;
  *source = (char *)realloc(*source, length + 1);
  memcpy(*source + string_length, appendix, appendix_length);
  (*source)[length] = 0;
}


x86 assembly (clang, -O0):
<append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
add    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
lea    (%rax,%rbx,1),%rbp
lea    (%rax,%rbx,1),%rsi
add    $0x1,%rsi
mov    %r12,%rdi
call   1050 <realloc@plt>
mov    %rax,(%r15)
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1040 <memcpy@plt>
mov    (%r15),%rax
movb   $0x0,(%rax,%rbp,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @append(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i8** %0, i8*** %3
store i8* %1, i8** %4
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %5
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %6
%13 = load i64, i64* %5
%14 = load i64, i64* %6
%15 = add i64 %13, %14
store i64 %15, i64* %7
%16 = load i8**, i8*** %3
%17 = load i8*, i8** %16
%18 = load i64, i64* %7
%19 = add i64 %18, 1
%20 = call i64 @realloc(i8* %17, i64 %19)
%21 = inttoptr i64 %20 to i8*
%22 = load i8**, i8*** %3
store i8* %21, i8** %22
%23 = load i8**, i8*** %3
%24 = load i8*, i8** %23
%25 = load i64, i64* %5
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = load i8*, i8** %4
%28 = load i64, i64* %6
%29 = call i32 @memcpy(i8* %26, i8* %27, i64 %28)
%30 = load i8**, i8*** %3
%31 = load i8*, i8** %30
%32 = load i64, i64* %7
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8 0, i8* %33
ret void
}

LLVM IR (-O2):
define void @append(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add i64 %5, %4
%7 = add i64 %6, 1
%8 = tail call i64 @realloc(i8* %3, i64 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %0
%10 = getelementptr inbounds i8, i8* %9, i64 %4
%11 = tail call i32 @memcpy(i8* %10, i8* %1, i64 %5)
%12 = load i8*, i8** %0
%13 = getelementptr inbounds i8, i8* %12, i64 %6
store i8 0, i8* %13
ret void
}