#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 *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *appendString(char *destStr, char *srcStr) {
  char *newStr;
  int destLen = 0;
  if (srcStr != NULL) {
    if (destStr != NULL)
      destLen = strlen(destStr);
    newStr = malloc(destLen + strlen(srcStr) + 1);
    newStr[0] = '\0';
    if (destStr != NULL)
      strcat(newStr, destStr);
    strcat(newStr, srcStr);
  } else
    return NULL;
  return newStr;
}


x86 assembly (clang, -O0):
<appendString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ba <appendString+0x8a>
cmpq   $0x0,-0x10(%rbp)
je     1169 <appendString+0x39>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     11a8 <appendString+0x78>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
jmp    11c7 <appendString+0x97>
movq   $0x0,-0x8(%rbp)
jmp    11cf <appendString+0x9f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appendString>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     1154 <appendString+0x24>
mov    %rsi,%r14
mov    %rdi,%r15
test   %rdi,%rdi
je     1158 <appendString+0x28>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
add    $0x1,%ebx
jmp    115d <appendString+0x2d>
xor    %ebx,%ebx
jmp    118f <appendString+0x5f>
mov    $0x1,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %eax,%ebx
mov    %ebx,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
test   %r15,%r15
je     1184 <appendString+0x54>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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