#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*/ free(char *);
char *str_malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
void str_append(char **str, char c) {
  char *tmp = str_malloc(strlen(*str) + 1);
  strcpy(tmp, *str);
  tmp[strlen(*str)] = c;
  free(*str);
  *str = tmp;
}


x86 assembly (clang, -O0):
<str_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
mov    %eax,%edi
call   1060 <str_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x9(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x21(%rbp),%dl
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_append>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <str_malloc@plt>
mov    %rax,%rbp
mov    (%rbx),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    (%rbx),%rdi
call   1050 <strlen@plt>
mov    %r14b,0x0(%rbp,%rax,1)
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    %rbp,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @str_append(i8** %0, i8 signext %1) {
%3 = alloca i8**
%4 = alloca i8
%5 = alloca i8*
store i8** %0, i8*** %3
store i8 %1, i8* %4
%6 = load i8**, i8*** %3
%7 = load i8*, i8** %6
%8 = call i64 @strlen(i8* %7)
%9 = add i64 %8, 1
%10 = trunc i64 %9 to i32
%11 = call i8* @str_malloc(i32 %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = load i8**, i8*** %3
%14 = load i8*, i8** %13
%15 = call i32 @strcpy(i8* %12, i8* %14)
%16 = load i8, i8* %4
%17 = load i8*, i8** %5
%18 = load i8**, i8*** %3
%19 = load i8*, i8** %18
%20 = call i64 @strlen(i8* %19)
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 %16, i8* %21
%22 = load i8**, i8*** %3
%23 = load i8*, i8** %22
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %5
%26 = load i8**, i8*** %3
store i8* %25, i8** %26
ret void
}

LLVM IR (-O2):
define void @str_append(i8** nocapture %0, i8 signext %1) {
%3 = load i8*, i8** %0
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = trunc i64 %4 to i32
%6 = add i32 %5, 1
%7 = tail call i8* @str_malloc(i32 %6)
%8 = load i8*, i8** %0
%9 = tail call i32 @strcpy(i8* %7, i8* %8)
%10 = load i8*, i8** %0
%11 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%12 = getelementptr inbounds i8, i8* %7, i64 %11
store i8 %1, i8* %12
%13 = load i8*, i8** %0
%14 = tail call i32 @free(i8* %13)
store i8* %7, i8** %0
ret void
}