#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 CiString_Append(char **str, const char *suffix) {
  size_t suffixLen = strlen(suffix);
  if (suffixLen == 0)
    return;
  size_t prefixLen = strlen(*str);
  *str = realloc(*str, prefixLen + suffixLen + 1);
  memcpy(*str + prefixLen, suffix, suffixLen + 1);
}


x86 assembly (clang, -O0):
<CiString_Append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115d <CiString_Append+0x2d>
jmp    11ab <CiString_Append+0x7b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
add    -0x18(%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    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
call   1040 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CiString_Append>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     118e <CiString_Append+0x5e>
mov    %rax,%rbx
mov    (%r14),%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
lea    (%rbx,%rax,1),%rsi
add    $0x1,%rsi
add    $0x1,%rbx
mov    %r12,%rdi
call   1050 <realloc@plt>
mov    %rax,(%r14)
add    %rax,%r13
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <memcpy@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @CiString_Append(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** %4
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
br label %32
12: ; preds = %2
%13 = load i8**, i8*** %3
%14 = load i8*, i8** %13
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %6
%16 = load i8**, i8*** %3
%17 = load i8*, i8** %16
%18 = load i64, i64* %6
%19 = load i64, i64* %5
%20 = add i64 %18, %19
%21 = add i64 %20, 1
%22 = call i8* @realloc(i8* %17, i64 %21)
%23 = load i8**, i8*** %3
store i8* %22, i8** %23
%24 = load i8**, i8*** %3
%25 = load i8*, i8** %24
%26 = load i64, i64* %6
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i8*, i8** %4
%29 = load i64, i64* %5
%30 = add i64 %29, 1
%31 = call i32 @memcpy(i8* %27, i8* %28, i64 %30)
br label %32
32: ; preds = %12, %11
ret void
}

LLVM IR (-O2):
define void @CiString_Append(i8** nocapture %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = load i8*, i8** %0
%7 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%8 = add i64 %3, 1
%9 = add i64 %8, %7
%10 = tail call i8* @realloc(i8* %6, i64 %9)
store i8* %10, i8** %0
%11 = getelementptr inbounds i8, i8* %10, i64 %7
%12 = tail call i32 @memcpy(i8* %11, i8* %1, i64 %8)
br label %13
13: ; preds = %2, %5
ret void
}