#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__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *appendChar(char *word, char c) {
  char *new_word = NULL;
  if (word) {
    int length = strlen(word);
    new_word = (char *)malloc(sizeof(char) * (length + 2));
    if (length)
      strcpy(new_word, word);
    new_word[length] = c;
    new_word[length + 1] = 0;
  } else {
    new_word = (char *)malloc(sizeof(char) * (2));
    new_word[0] = c;
    new_word[1] = 0;
  }
  return new_word;
}


x86 assembly (clang, -O0):
<appendChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11b3 <appendChar+0x83>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     118f <appendChar+0x5f>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x9(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11d2 <appendChar+0xa2>
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appendChar>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
test   %rdi,%rdi
je     1176 <appendChar+0x46>
mov    %rdi,%rbp
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0x2(%r15),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %r15d,%r15d
je     1166 <appendChar+0x36>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
movslq %r15d,%rax
mov    %r14b,(%rbx,%rax,1)
add    %rbx,%rax
add    $0x1,%rax
jmp    118a <appendChar+0x5a>
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r14b,(%rax)
add    $0x1,%rax
movb   $0x0,(%rax)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @appendChar(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
store i8* null, i8** %5
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %36
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 2
%14 = sext i32 %13 to i64
%15 = mul i64 1, %14
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %5
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %9
%22 = load i8*, i8** %5
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %22, i8* %23)
br label %25
25: ; preds = %21, %9
%26 = load i8, i8* %4
%27 = load i8*, i8** %5
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 0, i8* %35
br label %44
36: ; preds = %2
%37 = call i64 @malloc(i32 2)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %5
%39 = load i8, i8* %4
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i64 0
store i8 %39, i8* %41
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 1
store i8 0, i8* %43
br label %44
44: ; preds = %36, %25
%45 = load i8*, i8** %5
ret i8* %45
}

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