#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) {
  if (n != 0) {
    wchar_t *d = dst;
    const wchar_t *s = src;
    do {
      if ((*d++ = *s++) == L'\0') {
        while (--n != 0)
          *d++ = L'\0';
        break;
      }
    } while (--n != 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)
cmpq   $0x0,-0x18(%rbp)
je     11b0 <wcsncpy+0xb0>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
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
jne    1190 <wcsncpy+0x90>
jmp    115b <wcsncpy+0x5b>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     118b <wcsncpy+0x8b>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
movl   $0x0,(%rax)
jmp    115b <wcsncpy+0x5b>
jmp    11ab <wcsncpy+0xab>
jmp    1195 <wcsncpy+0x95>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    112b <wcsncpy+0x2b>
jmp    11b0 <wcsncpy+0xb0>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsncpy>:
push   %rbx
mov    %rdi,%rbx
test   %rdx,%rdx
je     1156 <wcsncpy+0x46>
xor    %eax,%eax
mov    %rdx,%rcx
xchg   %ax,%ax
mov    (%rsi,%rax,1),%edi
mov    %edi,(%rbx,%rax,1)
test   %edi,%edi
je     1136 <wcsncpy+0x26>
add    $0x4,%rax
add    $0xffffffffffffffff,%rcx
jne    1120 <wcsncpy+0x10>
jmp    1156 <wcsncpy+0x46>
cmp    $0x1,%rcx
je     1156 <wcsncpy+0x46>
lea    (%rbx,%rax,1),%rdi
add    $0x4,%rdi
shl    $0x2,%rdx
sub    %rax,%rdx
add    $0xfffffffffffffffc,%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*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
%9 = load i64, i64* %6
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %36
11: ; preds = %3
%12 = load i32*, i32** %4
store i32* %12, i32** %7
%13 = load i32*, i32** %5
store i32* %13, i32** %8
br label %14
14: ; preds = %31, %11
%15 = load i32*, i32** %8
%16 = getelementptr inbounds i32, i32* %15, i32 1
store i32* %16, i32** %8
%17 = load i32, i32* %15
%18 = load i32*, i32** %7
%19 = getelementptr inbounds i32, i32* %18, i32 1
store i32* %19, i32** %7
store i32 %17, i32* %18
%20 = icmp eq i32 %17, 0
br i1 %20, label %21, label %30
21: ; preds = %14
br label %22
22: ; preds = %26, %21
%23 = load i64, i64* %6
%24 = add i64 %23, -1
store i64 %24, i64* %6
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32*, i32** %7
%28 = getelementptr inbounds i32, i32* %27, i32 1
store i32* %28, i32** %7
store i32 0, i32* %27
br label %22
29: ; preds = %22
br label %35
30: ; preds = %14
br label %31
31: ; preds = %30
%32 = load i64, i64* %6
%33 = add i64 %32, -1
store i64 %33, i64* %6
%34 = icmp ne i64 %33, 0
br i1 %34, label %14, label %35
35: ; preds = %31, %29
br label %36
36: ; preds = %35, %3
%37 = load i32*, i32** %4
ret i32* %37
}

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