#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(char *);
char *realloc(char *, size_t);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
char *String_append_string(char *dst, const char *src) {
  size_t length_dst = strlen(dst);
  size_t length_src = strlen(src);
  dst = realloc(dst, (length_dst + length_src + 1) * sizeof(char));
  assert(dst);
  strcpy(&dst[length_dst], src);
  dst[length_src + length_dst] = '\0';
  return dst;
}


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

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

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

LLVM IR (-O2):
define i8* @String_append_string(i8* nocapture %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %4, %3
%6 = add i64 %5, 1
%7 = tail call i8* @realloc(i8* %0, i64 %6)
%8 = tail call i32 @assert(i8* %7)
%9 = getelementptr inbounds i8, i8* %7, i64 %3
%10 = tail call i32 @strcpy(i8* %9, i8* %1)
%11 = getelementptr inbounds i8, i8* %7, i64 %5
store i8 0, i8* %11
ret i8* %7
}