#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);
char *realloc(char *, size_t);
size_t strlen(char const *);
void strappend(char **base_ptr, const char *append) {
  char *base = NULL;
  size_t len_base = strlen(*base_ptr);
  size_t len_app = strlen(append);
  size_t len_new = len_base + len_app + 1;
  base = realloc(*base_ptr, len_new);
  memcpy(base + len_base, append, len_app);
  base[len_base + len_app] = '\0';
  *base_ptr = base;
}


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

x86 assembly (clang, -O2):
<strappend>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%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,%r12
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%r12,%rbp,1)
mov    %r12,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @strappend(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 i8* @realloc(i8* %3, i64 %7)
%9 = getelementptr inbounds i8, i8* %8, i64 %4
%10 = tail call i32 @memcpy(i8* %9, i8* %1, i64 %5)
%11 = getelementptr inbounds i8, i8* %8, i64 %6
store i8 0, i8* %11
store i8* %8, i8** %0
ret void
}