#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 */
typedef char wchar_t;

/* Variables and functions */
int /*<<< orphan*/ _wperror(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ wcscat(char *, char const *);
int /*<<< orphan*/ wcscpy(char *, char const *);
size_t wcslen(char const *);
wchar_t *concat(const wchar_t *s, const wchar_t *t) {
  const wchar_t *sNotNull;
  const wchar_t *tNotNull;
  wchar_t *result;
  size_t length;
  if (s == NULL) {
    sNotNull = L"";
  } else {
    sNotNull = s;
  }
  if (t == NULL) {
    tNotNull = L"";
  } else {
    tNotNull = t;
  }
  length = wcslen(sNotNull) + wcslen(tNotNull);
  result = (wchar_t *)malloc((length + 1) * sizeof(wchar_t));
  if (result != NULL) {
    wcscpy(result, sNotNull);
    wcscat(result, tNotNull);
  } else {
    _wperror(L"concat");
  }
  return result;
}


x86 assembly (clang, -O0):
<concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117b <concat+0x2b>
lea    0xea6(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1183 <concat+0x33>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <concat+0x4e>
lea    0xe83(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11a6 <concat+0x56>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <wcslen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <wcslen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1209 <concat+0xb9>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <wcscpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <wcscat@plt>
jmp    1215 <concat+0xc5>
lea    0xdf0(%rip),%rdi
call   1070 <_wperror@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
lea    0xeb6(%rip),%rax
cmove  %rax,%rbx
mov    %rsi,%r14
test   %rsi,%rsi
cmove  %rax,%r14
mov    %rbx,%rdi
call   1040 <wcslen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <wcslen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11b0 <concat+0x60>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <wcscpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <wcscat@plt>
jmp    11bc <concat+0x6c>
lea    0xe49(%rip),%rdi
call   1070 <_wperror@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i32] zeroinitializer
@.str.1 = [7 x i32] [i32 99, i32 111, i32 110, i32 99, i32 97, i32 116, i32 0]
define i8* @concat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i8* bitcast ([1 x i32]* @.str to i8*), i8** %5
br label %14
12: ; preds = %2
%13 = load i8*, i8** %3
store i8* %13, i8** %5
br label %14
14: ; preds = %12, %11
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14
store i8* bitcast ([1 x i32]* @.str to i8*), i8** %6
br label %20
18: ; preds = %14
%19 = load i8*, i8** %4
store i8* %19, i8** %6
br label %20
20: ; preds = %18, %17
%21 = load i8*, i8** %5
%22 = call i64 @wcslen(i8* %21)
%23 = load i8*, i8** %6
%24 = call i64 @wcslen(i8* %23)
%25 = add i64 %22, %24
store i64 %25, i64* %8
%26 = load i64, i64* %8
%27 = add i64 %26, 1
%28 = mul i64 %27, 1
%29 = call i64 @malloc(i64 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %40
33: ; preds = %20
%34 = load i8*, i8** %7
%35 = load i8*, i8** %5
%36 = call i32 @wcscpy(i8* %34, i8* %35)
%37 = load i8*, i8** %7
%38 = load i8*, i8** %6
%39 = call i32 @wcscat(i8* %37, i8* %38)
br label %42
40: ; preds = %20
%41 = call i32 @_wperror(i8* bitcast ([7 x i32]* @.str.1 to i8*))
br label %42
42: ; preds = %40, %33
%43 = load i8*, i8** %7
ret i8* %43
}

LLVM IR (-O2):
@.str = [1 x i32] zeroinitializer
@.str.1 = [7 x i32] [i32 99, i32 111, i32 110, i32 99, i32 97, i32 116, i32 0]
define i8* @concat(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = select i1 %3, i8* bitcast ([1 x i32]* @.str to i8*), i8* %0
%5 = icmp eq i8* %1, null
%6 = select i1 %5, i8* bitcast ([1 x i32]* @.str to i8*), i8* %1
%7 = tail call i64 @wcslen(i8* %4)
%8 = tail call i64 @wcslen(i8* %6)
%9 = add i64 %7, 1
%10 = add i64 %9, %8
%11 = tail call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = tail call i32 @wcscpy(i8* %12, i8* %4)
%16 = tail call i32 @wcscat(i8* %12, i8* %6)
br label %19
17: ; preds = %2
%18 = tail call i32 @_wperror(i8* bitcast ([7 x i32]* @.str.1 to i8*))
br label %19
19: ; preds = %17, %14
ret i8* %12
}