#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ wcscat(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ wcscpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int wcslen(int /*<<< orphan*/ *);
wchar_t *mergewcs(wchar_t *s1, wchar_t *s2) {
  wchar_t *s;
  int len = wcslen(s1) + wcslen(s2);
  s = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
  if (s == NULL)
    return NULL;
  wcscpy(s, s1);
  wcscat(s, s2);
  return s;
}


x86 assembly (clang, -O0):
<mergewcs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <wcslen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <wcslen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119e <mergewcs+0x5e>
movq   $0x0,-0x8(%rbp)
jmp    11c0 <mergewcs+0x80>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <wcscpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <wcscat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergewcs>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <wcslen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <wcslen@plt>
add    %ebx,%eax
lea    0x4(,%rax,4),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1188 <mergewcs+0x48>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <wcscpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <wcscat@plt>
jmp    118a <mergewcs+0x4a>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @mergewcs(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %4
%9 = call i32 @wcslen(i32* %8)
%10 = load i32*, i32** %5
%11 = call i32 @wcslen(i32* %10)
%12 = add nsw i32 %9, %11
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %2
store i32* null, i32** %3
br label %31
23: ; preds = %2
%24 = load i32*, i32** %6
%25 = load i32*, i32** %4
%26 = call i32 @wcscpy(i32* %24, i32* %25)
%27 = load i32*, i32** %6
%28 = load i32*, i32** %5
%29 = call i32 @wcscat(i32* %27, i32* %28)
%30 = load i32*, i32** %6
store i32* %30, i32** %3
br label %31
31: ; preds = %23, %22
%32 = load i32*, i32** %3
ret i32* %32
}

LLVM IR (-O2):
define i32* @mergewcs(i32* %0, i32* %1) {
%3 = tail call i32 @wcslen(i32* %0)
%4 = tail call i32 @wcslen(i32* %1)
%5 = add nsw i32 %4, %3
%6 = shl i32 %5, 2
%7 = add i32 %6, 4
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i32*
%10 = icmp eq i64 %8, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = tail call i32 @wcscpy(i32* %9, i32* %0)
%13 = tail call i32 @wcscat(i32* %9, i32* %1)
br label %14
14: ; preds = %2, %11
%15 = phi i32* [ %9, %11 ], [ null, %2 ]
ret i32* %15
}