#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 */
wchar_t *wcsncpy(wchar_t *__restrict dst, const wchar_t *__restrict src,
                 size_t n) {
  register wchar_t *dscan;
  register const wchar_t *sscan;
  register long count;
  dscan = dst;
  sscan = src;
  count = n;
  while (--count >= 0 && (*dscan++ = *sscan++) != L'\0')
    continue;
  while (--count >= 0)
    *dscan++ = L'\0';
  return (dst);
}


x86 assembly (clang, -O0):
<wcsncpy>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x30(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x31(%rbp)
jl     116e <wcsncpy+0x6e>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x4,%rdx
mov    %rdx,-0x20(%rbp)
mov    %eax,(%rcx)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    117e <wcsncpy+0x7e>
jmp    1183 <wcsncpy+0x83>
jmp    1128 <wcsncpy+0x28>
jmp    1188 <wcsncpy+0x88>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jl     11b8 <wcsncpy+0xb8>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
movl   $0x0,(%rax)
jmp    1188 <wcsncpy+0x88>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsncpy>:
push   %rbx
mov    %rdx,%r8
mov    %rdi,%rbx
lea    0x4(,%rdx,4),%rdx
xor    %ecx,%ecx
mov    %r8,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %rax,%rax
jle    1176 <wcsncpy+0x66>
mov    (%rsi,%rcx,4),%edi
mov    %edi,(%rbx,%rcx,4)
add    $0x1,%rcx
add    $0xfffffffffffffffc,%rdx
add    $0xffffffffffffffff,%rax
test   %edi,%edi
jne    1130 <wcsncpy+0x20>
sub    %rcx,%r8
add    $0x1,%r8
cmp    $0x2,%r8
jb     1176 <wcsncpy+0x66>
lea    (%rbx,%rcx,4),%rdi
test   %rax,%rax
mov    $0x1,%ecx
cmovle %rax,%rcx
shl    $0x2,%rcx
sub    %rcx,%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i32* @wcsncpy(i32* noalias %0, i32* noalias %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
%10 = load i32*, i32** %4
store i32* %10, i32** %7
%11 = load i32*, i32** %5
store i32* %11, i32** %8
%12 = load i64, i64* %6
store i64 %12, i64* %9
br label %13
13: ; preds = %26, %3
%14 = load i64, i64* %9
%15 = add nsw i64 %14, -1
store i64 %15, i64* %9
%16 = icmp sge i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i32*, i32** %8
%19 = getelementptr inbounds i32, i32* %18, i32 1
store i32* %19, i32** %8
%20 = load i32, i32* %18
%21 = load i32*, i32** %7
%22 = getelementptr inbounds i32, i32* %21, i32 1
store i32* %22, i32** %7
store i32 %20, i32* %21
%23 = icmp ne i32 %20, 0
br label %24
24: ; preds = %17, %13
%25 = phi i1 [ false, %13 ], [ %23, %17 ]
br i1 %25, label %26, label %27
26: ; preds = %24
br label %13
27: ; preds = %24
br label %28
28: ; preds = %32, %27
%29 = load i64, i64* %9
%30 = add nsw i64 %29, -1
store i64 %30, i64* %9
%31 = icmp sge i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32*, i32** %7
%34 = getelementptr inbounds i32, i32* %33, i32 1
store i32* %34, i32** %7
store i32 0, i32* %33
br label %28
35: ; preds = %28
%36 = load i32*, i32** %4
ret i32* %36
}

LLVM IR (-O2):
define i32* @wcsncpy(i32* noalias returned writeonly %0, i32* noalias nocapture %1, i64 %2) {
br label %4
4: ; preds = %10, %3
%5 = phi i32* [ %0, %3 ], [ %13, %10 ]
%6 = phi i32* [ %1, %3 ], [ %11, %10 ]
%7 = phi i64 [ %2, %3 ], [ %8, %10 ]
%8 = add nsw i64 %7, -1
%9 = icmp sgt i64 %7, 0
br i1 %9, label %10, label %22
10: ; preds = %4
%11 = getelementptr inbounds i32, i32* %6, i64 1
%12 = load i32, i32* %6
%13 = getelementptr inbounds i32, i32* %5, i64 1
store i32 %12, i32* %5
%14 = icmp eq i32 %12, 0
br i1 %14, label %15, label %4
15: ; preds = %10
%16 = icmp ugt i64 %7, 1
br i1 %16, label %17, label %22
17: ; preds = %15
%18 = bitcast i32* %13 to i8*
%19 = call i64 @llvm.smin.i64(i64 %8, i64 1)
%20 = sub nuw nsw i64 %7, %19
%21 = shl nuw i64 %20, 2
br label %22
22: ; preds = %4, %17, %15
ret i32* %0
}