#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 *, int);
char *realloc(char *, int);
int strlen(char const *);
void str_append(char **str, const char *add) {
  int s1 = strlen(*str);
  int s2 = strlen(add);
  *str = realloc(*str, sizeof(char) * (s1 + s2 + 1));
  memcpy(*str + (sizeof(char) * s1), add, s2 + 1);
}


x86 assembly (clang, -O0):
<str_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%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
shl    $0x0,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_append>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    (%rbx),%rdi
lea    0x1(%rax),%ebp
lea    (%rax,%r15,1),%esi
add    $0x1,%esi
call   1050 <realloc@plt>
mov    %rax,(%rbx)
movslq %r15d,%rdi
add    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <memcpy@plt>

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

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