#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 */
char *appendChar(char *, char);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
void testAppendChar() {
  char *vowels = "aeiou", *word_heap = NULL, *new_word = NULL;
  for (int i = 0; i < 5; i++) {
    new_word = appendChar(word_heap, vowels[i]);
    printf("%s, %s\n", word_heap, new_word);
    free(word_heap);
    word_heap = new_word;
    new_word = NULL;
  }
  if (word_heap)
    free(word_heap);
  if (new_word)
    free(new_word);
}


x86 assembly (clang, -O0):
<testAppendChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rax
mov    %rax,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    11b8 <testAppendChar+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1050 <appendChar@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115a <testAppendChar+0x2a>
cmpq   $0x0,-0x10(%rbp)
je     11cc <testAppendChar+0x9c>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
je     11e0 <testAppendChar+0xb0>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testAppendChar>:
push   %r15
push   %r14
push   %rbx
xor    %edi,%edi
mov    $0x61,%esi
call   1050 <appendChar@plt>
mov    %rax,%r15
lea    0xeb5(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
xor    %edi,%edi
call   1030 <free@plt>
mov    %r15,%rdi
mov    $0x65,%esi
call   1050 <appendChar@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    $0x69,%esi
call   1050 <appendChar@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
mov    $0x6f,%esi
call   1050 <appendChar@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    $0x75,%esi
call   1050 <appendChar@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     1209 <testAppendChar+0xd9>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"aeiou\00"
@.str.1 = [8 x i8] c"%s, %s\0A\00"
define void @testAppendChar() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* null, i8** %2
store i8* null, i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %22, %0
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 5
br i1 %7, label %8, label %25
8: ; preds = %5
%9 = load i8*, i8** %2
%10 = load i8*, i8** %1
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = call i8* @appendChar(i8* %9, i8 signext %14)
store i8* %15, i8** %3
%16 = load i8*, i8** %2
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
%19 = load i8*, i8** %2
%20 = call i32 @free(i8* %19)
%21 = load i8*, i8** %3
store i8* %21, i8** %2
store i8* null, i8** %3
br label %22
22: ; preds = %8
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %5
25: ; preds = %5
%26 = load i8*, i8** %2
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %2
%30 = call i32 @free(i8* %29)
br label %31
31: ; preds = %28, %25
%32 = load i8*, i8** %3
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8*, i8** %3
%36 = call i32 @free(i8* %35)
br label %37
37: ; preds = %34, %31
ret void
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"%s, %s\0A\00"
define void @testAppendChar() {
%1 = tail call i8* @appendChar(i8* null, i8 signext 97)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* null, i8* %1)
%3 = tail call i32 @free(i8* null)
%4 = tail call i8* @appendChar(i8* %1, i8 signext 101)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %4)
%6 = tail call i32 @free(i8* %1)
%7 = tail call i8* @appendChar(i8* %4, i8 signext 105)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %7)
%9 = tail call i32 @free(i8* %4)
%10 = tail call i8* @appendChar(i8* %7, i8 signext 111)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %10)
%12 = tail call i32 @free(i8* %7)
%13 = tail call i8* @appendChar(i8* %10, i8 signext 117)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %13)
%15 = tail call i32 @free(i8* %10)
%16 = icmp eq i8* %13, null
br i1 %16, label %19, label %17
17: ; preds = %0
%18 = tail call i32 @free(i8* %13)
br label %19
19: ; preds = %0, %17
ret void
}