#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 */
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void append(char **str, char *append) {
  int len = *str == NULL ? 0 : strlen(*str);
  *str = (char *)realloc(*str, (len + strlen(append) + 1) * sizeof(char));
  strcpy(*str + len, append);
}


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
cmpq   $0x0,(%rax)
jne    1158 <append+0x28>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    1167 <append+0x37>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1152 <append+0x22>
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    (%r15),%r12
jmp    1157 <append+0x27>
xor    %r12d,%r12d
xor    %ebx,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%esi
add    $0x1,%esi
mov    %r12,%rdi
call   1050 <realloc@plt>
mov    %rax,(%r15)
movslq %ebx,%rdi
add    %rax,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
define void @append(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
store i8** %0, i8*** %3
store i8* %1, i8** %4
%6 = load i8**, i8*** %3
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
br label %14
10: ; preds = %2
%11 = load i8**, i8*** %3
%12 = load i8*, i8** %11
%13 = call i32 @strlen(i8* %12)
br label %14
14: ; preds = %10, %9
%15 = phi i32 [ 0, %9 ], [ %13, %10 ]
store i32 %15, i32* %5
%16 = load i8**, i8*** %3
%17 = load i8*, i8** %16
%18 = load i32, i32* %5
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %18, %20
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 1
%25 = trunc i64 %24 to i32
%26 = call i64 @realloc(i8* %17, i32 %25)
%27 = inttoptr i64 %26 to i8*
%28 = load i8**, i8*** %3
store i8* %27, i8** %28
%29 = load i8**, i8*** %3
%30 = load i8*, i8** %29
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8*, i8** %4
%35 = call i32 @strcpy(i8* %33, i8* %34)
ret void
}

LLVM IR (-O2):
define void @append(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %3)
%7 = load i8*, i8** %0
br label %8
8: ; preds = %2, %5
%9 = phi i8* [ %7, %5 ], [ null, %2 ]
%10 = phi i32 [ %6, %5 ], [ 0, %2 ]
%11 = tail call i32 @strlen(i8* %1)
%12 = add i32 %10, 1
%13 = add i32 %12, %11
%14 = tail call i64 @realloc(i8* %9, i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %0
%16 = sext i32 %10 to i64
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = tail call i32 @strcpy(i8* %17, i8* %1)
ret void
}