char *add(this, that)
register char *this, *that;
{
  register char *r;
  if (!this)
    this = "";
  if (!that)
    that = "";
  r = (char *)malloc(strlen(this) + strlen(that) + 1);
  sprintf(r, "%s%s", that, this);
  if (*that)
    cndfree(that);
  return (r);
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1166 <add+0x26>
lea    0xea2(%rip),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117c <add+0x3c>
lea    0xe8c(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d8 <add+0x98>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1050 <cndfree@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rdi,%rdi
lea    0xeb2(%rip),%rax
cmove  %rax,%r14
mov    %rsi,%rbx
test   %rsi,%rsi
cmove  %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,%r15
lea    0xe76(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <sprintf@plt>
cmpb   $0x0,(%rbx)
je     11a9 <add+0x69>
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <cndfree@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @add(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %9
9: ; preds = %8, %2
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
br label %13
13: ; preds = %12, %9
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = load i8*, i8** %4
%17 = call i64 @strlen(i8* %16)
%18 = add i64 %15, %17
%19 = add i64 %18, 1
%20 = call i8* @malloc(i64 %19)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = load i8*, i8** %4
%23 = load i8*, i8** %3
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %23)
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %13
%29 = load i8*, i8** %4
%30 = call i32 (i8*, ...) bitcast (i32 (...)* @cndfree to i32 (i8*, ...)*)(i8* %29)
br label %31
31: ; preds = %28, %13
%32 = load i8*, i8** %5
ret i8* %32
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @add(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = select i1 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%5 = icmp eq i8* %1, null
%6 = select i1 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %1
%7 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%9 = add i64 %7, 1
%10 = add i64 %9, %8
%11 = tail call i8* @malloc(i64 %10)
%12 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %4)
%13 = load i8, i8* %6
%14 = icmp eq i8 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = tail call i32 (i8*, ...) bitcast (i32 (...)* @cndfree to i32 (i8*, ...)*)(i8* %6)
br label %17
17: ; preds = %15, %2
ret i8* %11
}