#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void append_char(char **str, char c) {
  char *new_str = NULL;
  new_str = (char *)malloc((strlen(*str) + 2) * sizeof(char));
  strcpy(new_str, *str);
  new_str[strlen(*str)] = c;
  new_str[strlen(*str) + 1] = '\0';
  free(*str);
  *str = new_str;
}


x86 assembly (clang, -O0):
<append_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <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,-0x29(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x29(%rbp),%dl
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%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):
<append_char>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    (%rbx),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    (%rbx),%rdi
call   1050 <strlen@plt>
cltq
mov    %r14b,0x0(%rbp,%rax,1)
mov    (%rbx),%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,0x1(%rax,%rbp,1)
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    %rbp,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @append_char(i8** nocapture %0, i8 signext %1) {
%3 = load i8*, i8** %0
%4 = tail call i32 @strlen(i8* %3)
%5 = add nsw i32 %4, 2
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = load i8*, i8** %0
%9 = tail call i32 @strcpy(i8* %7, i8* %8)
%10 = load i8*, i8** %0
%11 = tail call i32 @strlen(i8* %10)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %7, i64 %12
store i8 %1, i8* %13
%14 = load i8*, i8** %0
%15 = tail call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %7, i64 %17
store i8 0, i8* %18
%19 = load i8*, i8** %0
%20 = tail call i32 @free(i8* %19)
store i8* %7, i8** %0
ret void
}