#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 *dstrdup(char const *);
char *dstrinit(char, scalar_t__);
char *strcat(char *, char const *);
scalar_t__ strlen(char const *);
char *dstrcat(const char *a, const char *b) {
  if (a == NULL)
    return dstrdup(b);
  return strcat(strcat(dstrinit('\0', strlen(a) + strlen(b)), a), b);
}


x86 assembly (clang, -O0):
<dstrcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <dstrcat+0x2d>
mov    -0x18(%rbp),%rdi
call   1040 <dstrdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11ad <dstrcat+0x6d>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rsi
add    %rax,%rsi
xor    %edi,%edi
call   1060 <dstrinit@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dstrcat>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     118b <dstrcat+0x4b>
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %rax,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <dstrinit@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <strcat@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <dstrdup@plt>

LLVM IR (-O0):
define i8* @dstrcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %5
%10 = call i8* @dstrdup(i8* %9)
store i8* %10, i8** %3
br label %22
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %13, %15
%17 = call i8* @dstrinit(i8 signext 0, i64 %16)
%18 = load i8*, i8** %4
%19 = call i8* @strcat(i8* %17, i8* %18)
%20 = load i8*, i8** %5
%21 = call i8* @strcat(i8* %19, i8* %20)
store i8* %21, i8** %3
br label %22
22: ; preds = %11, %8
%23 = load i8*, i8** %3
ret i8* %23
}

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