#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*/ __chk_fail();
wchar_t *__wcpcpy_chk(wchar_t *dest, const wchar_t *src, size_t destlen) {
  do
    if (destlen-- == 0)
      __chk_fail();
  while ((*dest++ = *src++));
  return dest - 1;
}


x86 assembly (clang, -O0):
<__wcpcpy_chk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
jne    1144 <__wcpcpy_chk+0x34>
mov    $0x0,%al
call   1030 <__chk_fail@plt>
jmp    1149 <__wcpcpy_chk+0x39>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %eax,(%rcx)
cmp    $0x0,%eax
jne    1124 <__wcpcpy_chk+0x14>
mov    -0x8(%rbp),%rax
add    $0xfffffffffffffffc,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__wcpcpy_chk>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
add    $0xfffffffffffffffc,%r12
xor    %ebx,%ebx
jmp    1145 <__wcpcpy_chk+0x35>
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%eax
mov    %eax,0x4(%r12)
add    $0x4,%r12
add    $0x1,%rbx
test   %eax,%eax
je     1153 <__wcpcpy_chk+0x43>
cmp    %rbx,%r14
jne    1130 <__wcpcpy_chk+0x20>
xor    %eax,%eax
call   1030 <__chk_fail@plt>
jmp    1130 <__wcpcpy_chk+0x20>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @__wcpcpy_chk(i32* %0, i32* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
br label %7
7: ; preds = %14, %3
%8 = load i64, i64* %6
%9 = add i64 %8, -1
store i64 %9, i64* %6
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 (...) @__chk_fail()
br label %13
13: ; preds = %11, %7
br label %14
14: ; preds = %13
%15 = load i32*, i32** %5
%16 = getelementptr inbounds i32, i32* %15, i32 1
store i32* %16, i32** %5
%17 = load i32, i32* %15
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i32 1
store i32* %19, i32** %4
store i32 %17, i32* %18
%20 = icmp ne i32 %17, 0
br i1 %20, label %7, label %21
21: ; preds = %14
%22 = load i32*, i32** %4
%23 = getelementptr inbounds i32, i32* %22, i64 -1
ret i32* %23
}

LLVM IR (-O2):
define i32* @__wcpcpy_chk(i32* writeonly %0, i32* nocapture %1, i64 %2) {
br label %4
4: ; preds = %12, %3
%5 = phi i32* [ %0, %3 ], [ %15, %12 ]
%6 = phi i32* [ %1, %3 ], [ %13, %12 ]
%7 = phi i64 [ %2, %3 ], [ %8, %12 ]
%8 = add i64 %7, -1
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 (...) @__chk_fail()
br label %12
12: ; preds = %4, %10
%13 = getelementptr inbounds i32, i32* %6, i64 1
%14 = load i32, i32* %6
%15 = getelementptr inbounds i32, i32* %5, i64 1
store i32 %14, i32* %5
%16 = icmp eq i32 %14, 0
br i1 %16, label %17, label %4
17: ; preds = %12
ret i32* %5
}