#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 scalar_t__ wchar_t;

/* Variables and functions */
size_t wcslen(scalar_t__ const *);
scalar_t__ *wcsstr(scalar_t__ const *, scalar_t__ const *);
int /*<<< orphan*/ wmemcpy(scalar_t__ *, scalar_t__ const *, size_t);
wchar_t *wcsstrcpy(wchar_t *restrict whither, const wchar_t *restrict whence,
                   const wchar_t *restrict str) {
  const wchar_t *stop = str == NULL ? NULL : wcsstr(whence, str);
  size_t n = stop == NULL ? wcslen(whence) : (size_t)(stop - whence);
  wchar_t *r = stop == NULL ? NULL : (whither + n);
  wmemcpy(whither, whence, n);
  whither[n] = 0;
  return r;
}


x86 assembly (clang, -O0):
<wcsstrcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115a <wcsstrcpy+0x2a>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    116b <wcsstrcpy+0x3b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <wcsstr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1190 <wcsstrcpy+0x60>
mov    -0x10(%rbp),%rdi
call   1040 <wcslen@plt>
mov    %rax,-0x40(%rbp)
jmp    11a3 <wcsstrcpy+0x73>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c1 <wcsstrcpy+0x91>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    11d4 <wcsstrcpy+0xa4>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <wmemcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsstrcpy>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
test   %rdx,%rdx
je     1163 <wcsstrcpy+0x33>
mov    %r15,%rdi
mov    %rdx,%rsi
call   1050 <wcsstr@plt>
test   %rax,%rax
je     1163 <wcsstrcpy+0x33>
mov    %rax,%rbx
sub    %r15,%rbx
lea    (%r14,%rbx,1),%r12
sar    $0x3,%rbx
jmp    1171 <wcsstrcpy+0x41>
mov    %r15,%rdi
call   1040 <wcslen@plt>
mov    %rax,%rbx
xor    %r12d,%r12d
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <wmemcpy@plt>
movq   $0x0,(%r14,%rbx,8)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64* @wcsstrcpy(i64* noalias %0, i64* noalias %1, i64* noalias %2) {
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i64*
store i64* %0, i64** %4
store i64* %1, i64** %5
store i64* %2, i64** %6
%10 = load i64*, i64** %6
%11 = icmp eq i64* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
br label %17
13: ; preds = %3
%14 = load i64*, i64** %5
%15 = load i64*, i64** %6
%16 = call i64* @wcsstr(i64* %14, i64* %15)
br label %17
17: ; preds = %13, %12
%18 = phi i64* [ null, %12 ], [ %16, %13 ]
store i64* %18, i64** %7
%19 = load i64*, i64** %7
%20 = icmp eq i64* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i64*, i64** %5
%23 = call i64 @wcslen(i64* %22)
br label %31
24: ; preds = %17
%25 = load i64*, i64** %7
%26 = load i64*, i64** %5
%27 = ptrtoint i64* %25 to i64
%28 = ptrtoint i64* %26 to i64
%29 = sub i64 %27, %28
%30 = sdiv exact i64 %29, 8
br label %31
31: ; preds = %24, %21
%32 = phi i64 [ %23, %21 ], [ %30, %24 ]
store i64 %32, i64* %8
%33 = load i64*, i64** %7
%34 = icmp eq i64* %33, null
br i1 %34, label %35, label %36
35: ; preds = %31
br label %40
36: ; preds = %31
%37 = load i64*, i64** %4
%38 = load i64, i64* %8
%39 = getelementptr inbounds i64, i64* %37, i64 %38
br label %40
40: ; preds = %36, %35
%41 = phi i64* [ null, %35 ], [ %39, %36 ]
store i64* %41, i64** %9
%42 = load i64*, i64** %4
%43 = load i64*, i64** %5
%44 = load i64, i64* %8
%45 = call i32 @wmemcpy(i64* %42, i64* %43, i64 %44)
%46 = load i64*, i64** %4
%47 = load i64, i64* %8
%48 = getelementptr inbounds i64, i64* %46, i64 %47
store i64 0, i64* %48
%49 = load i64*, i64** %9
ret i64* %49
}

LLVM IR (-O2):
define i64* @wcsstrcpy(i64* noalias %0, i64* noalias %1, i64* noalias %2) {
%4 = icmp eq i64* %2, null
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = tail call i64* @wcsstr(i64* %1, i64* %2)
%7 = icmp eq i64* %6, null
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = ptrtoint i64* %6 to i64
%10 = ptrtoint i64* %1 to i64
%11 = sub i64 %9, %10
%12 = ashr exact i64 %11, 3
%13 = getelementptr inbounds i64, i64* %0, i64 %12
br label %17
14: ; preds = %5, %3
%15 = tail call i64 @wcslen(i64* %1)
%16 = getelementptr inbounds i64, i64* %0, i64 %15
br label %17
17: ; preds = %8, %14
%18 = phi i64* [ %16, %14 ], [ %13, %8 ]
%19 = phi i64 [ %15, %14 ], [ %12, %8 ]
%20 = phi i64* [ null, %14 ], [ %13, %8 ]
%21 = tail call i32 @wmemcpy(i64* %0, i64* %1, i64 %19)
store i64 0, i64* %18
ret i64* %20
}