#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 int /*<<< orphan*/ wchar_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ *calloc(int, int);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int swprintf(int /*<<< orphan*/ *, int, char *, int /*<<< orphan*/ const *,
             int /*<<< orphan*/, int /*<<< orphan*/ const *);
int wcslen(int /*<<< orphan*/ const *);
wchar_t *wcsjoin(wchar_t sep, const wchar_t *base, const wchar_t *suffix) {
  wchar_t *s;
  int i;
  i = wcslen(base) + wcslen(suffix) + 1;
  s = calloc(i + 1, sizeof(wchar_t));
  i = swprintf(s, i + 1, L"%ls%lc%ls", base, sep, suffix);
  if (i < 0) {
    err(EXIT_FAILURE, "wsprintf failed");
  }
  return (s);
}


x86 assembly (clang, -O0):
<wcsjoin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rcx
mov    -0x4(%rbp),%r8d
mov    -0x18(%rbp),%r9
lea    0xe5a(%rip),%rdx
call   1050 <swprintf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11cd <wcsjoin+0x8d>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <err@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsjoin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%r12d
mov    %rsi,%rdi
call   1030 <wcslen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <wcslen@plt>
lea    (%rbx,%rax,1),%ebp
add    $0x2,%ebp
mov    %ebp,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
lea    0xe81(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r15,%rcx
mov    %r12d,%r8d
mov    %r14,%r9
call   1050 <swprintf@plt>
test   %eax,%eax
jns    11ab <wcsjoin+0x6b>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1060 <err@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i32] [i32 37, i32 108, i32 115, i32 37, i32 108, i32 99, i32 37, i32 108, i32 115, i32 0]
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"wsprintf failed\00"
define i32* @wcsjoin(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%9 = load i32*, i32** %5
%10 = call i32 @wcslen(i32* %9)
%11 = load i32*, i32** %6
%12 = call i32 @wcslen(i32* %11)
%13 = add nsw i32 %10, %12
%14 = add nsw i32 %13, 1
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = add nsw i32 %15, 1
%17 = call i32* @calloc(i32 %16, i32 4)
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 1
%21 = load i32*, i32** %5
%22 = load i32, i32* %4
%23 = load i32*, i32** %6
%24 = call i32 @swprintf(i32* %18, i32 %20, i8* bitcast ([10 x i32]* @.str to i8*), i32* %21, i32 %22, i32* %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %3
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @err(i32 %28, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %27, %3
%31 = load i32*, i32** %7
ret i32* %31
}

LLVM IR (-O2):
@.str = [10 x i32] [i32 37, i32 108, i32 115, i32 37, i32 108, i32 99, i32 37, i32 108, i32 115, i32 0]
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"wsprintf failed\00"
define i32* @wcsjoin(i32 %0, i32* %1, i32* %2) {
%4 = tail call i32 @wcslen(i32* %1)
%5 = tail call i32 @wcslen(i32* %2)
%6 = add i32 %4, 2
%7 = add i32 %6, %5
%8 = tail call i32* @calloc(i32 %7, i32 4)
%9 = tail call i32 @swprintf(i32* %8, i32 %7, i8* bitcast ([10 x i32]* @.str to i8*), i32* %1, i32 %0, i32* %2)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @err(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %11, %3
ret i32* %8
}