#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 *UTIL_mallocStr(size_t);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
char *addStr(char *str, char *addOn) {
  size_t length = (str ? strlen(str) : 0) + strlen(addOn);
  char *newStr = UTIL_mallocStr(length);
  if (str) {
    strcpy(newStr, str);
    strcat(newStr, addOn);
  } else
    strcpy(newStr, addOn);
  return newStr;
}


x86 assembly (clang, -O0):
<addStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     116d <addStr+0x2d>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
jmp    1178 <addStr+0x38>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    1178 <addStr+0x38>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <UTIL_mallocStr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ce <addStr+0x8e>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
jmp    11db <addStr+0x9b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addStr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
test   %rdi,%rdi
je     115d <addStr+0x1d>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
jmp    115f <addStr+0x1f>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %rax,%rbx
mov    %rbx,%rdi
call   1050 <UTIL_mallocStr@plt>
mov    %rax,%rbx
mov    %rax,%rdi
test   %r15,%r15
je     1192 <addStr+0x52>
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
jmp    119a <addStr+0x5a>
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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