#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__ Length(char const *);
scalar_t__ malloc(int);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ strcat(char *, char const *);
int strlen(char const *);
void AppendToStr(char *currentWord, const char *strToAppend) {
  if (strToAppend == NULL || Length(strToAppend) == 0) {
    return;
  }
  int valLen = strlen(strToAppend);
  if (currentWord == NULL) {
    currentWord = (char *)malloc(valLen);
  } else {
    currentWord = (char *)realloc(currentWord, strlen(currentWord) + valLen);
  }
  strcat(currentWord, strToAppend);
}


x86 assembly (clang, -O0):
<AppendToStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117e <AppendToStr+0x2e>
mov    -0x10(%rbp),%rdi
call   1060 <Length@plt>
cmp    $0x0,%rax
jne    1183 <AppendToStr+0x33>
jmp    11db <AppendToStr+0x8b>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11ab <AppendToStr+0x5b>
mov    -0x14(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11ce <AppendToStr+0x7e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
add    -0x14(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AppendToStr>:
push   %rbp
push   %r14
push   %rbx
test   %rsi,%rsi
je     1191 <AppendToStr+0x41>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1060 <Length@plt>
test   %rax,%rax
je     1191 <AppendToStr+0x41>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
test   %r14,%r14
je     1196 <AppendToStr+0x46>
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %eax,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <realloc@plt>
jmp    119d <AppendToStr+0x4d>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <strcat@plt>

LLVM IR (-O0):
define void @AppendToStr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = call i64 @Length(i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8, %2
br label %34
13: ; preds = %8
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %5
%16 = load i8*, i8** %3
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* %5
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %3
br label %30
22: ; preds = %13
%23 = load i8*, i8** %3
%24 = load i8*, i8** %3
%25 = call i32 @strlen(i8* %24)
%26 = load i32, i32* %5
%27 = add nsw i32 %25, %26
%28 = call i64 @realloc(i8* %23, i32 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %3
br label %30
30: ; preds = %22, %18
%31 = load i8*, i8** %3
%32 = load i8*, i8** %4
%33 = call i32 @strcat(i8* %31, i8* %32)
br label %34
34: ; preds = %30, %12
ret void
}

LLVM IR (-O2):
define void @AppendToStr(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = tail call i64 @Length(i8* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %1)
%9 = icmp eq i8* %0, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i64 @malloc(i32 %8)
br label %16
12: ; preds = %7
%13 = tail call i32 @strlen(i8* %0)
%14 = add nsw i32 %13, %8
%15 = tail call i64 @realloc(i8* %0, i32 %14)
br label %16
16: ; preds = %12, %10
%17 = phi i64 [ %11, %10 ], [ %15, %12 ]
%18 = inttoptr i64 %17 to i8*
%19 = tail call i32 @strcat(i8* %18, i8* %1)
br label %20
20: ; preds = %2, %4, %16
ret void
}