#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 */
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *xmalloc(scalar_t__);
char *xstrconcat3(const char *s, const char *t, const char *u) {
  char *res;
  if (!s)
    s = "";
  if (!t)
    t = "";
  if (!u)
    u = "";
  res = xmalloc(strlen(s) + strlen(t) + strlen(u) + 1);
  strcpy(res, s);
  strcat(res, t);
  strcat(res, u);
  free((void *)s);
  return res;
}


x86 assembly (clang, -O0):
<xstrconcat3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117a <xstrconcat3+0x2a>
lea    0xe8a(%rip),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1190 <xstrconcat3+0x40>
lea    0xe74(%rip),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a6 <xstrconcat3+0x56>
lea    0xe5e(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrconcat3>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
test   %rdi,%rdi
lea    0xe9a(%rip),%r13
cmove  %r13,%r14
mov    %rsi,%r15
test   %rsi,%rsi
cmove  %r13,%r15
test   %rdx,%rdx
cmovne %rdx,%r13
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1050 <strlen@plt>
add    %r12,%rbx
lea    (%rax,%rbx,1),%rdi
add    $0x1,%rdi
call   1060 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <strcat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @xstrconcat3(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %0, null
%5 = select i1 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%6 = icmp eq i8* %1, null
%7 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %1
%8 = icmp eq i8* %2, null
%9 = select i1 %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %2
%10 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%11 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %9)
%13 = add i64 %10, 1
%14 = add i64 %13, %11
%15 = add i64 %14, %12
%16 = tail call i8* @xmalloc(i64 %15)
%17 = tail call i32 @strcpy(i8* %16, i8* %5)
%18 = tail call i32 @strcat(i8* %16, i8* %7)
%19 = tail call i32 @strcat(i8* %16, i8* %9)
%20 = tail call i32 @free(i8* %5)
ret i8* %16
}