#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 *dst, const wchar_t *src, size_t n) {
  wchar_t *ret = dst;
  do {
    if (!n--) {
      return ret;
    }
  } while ((*dst++ = *src++));
  while (n--) {
    *dst++ = '\0';
  }
  return ret;
}


x86 assembly (clang, -O0):
<wcsncpy>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
jne    113e <wcsncpy+0x3e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <wcsncpy+0xae>
jmp    1143 <wcsncpy+0x43>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %eax,(%rcx)
cmp    $0x0,%eax
jne    1118 <wcsncpy+0x18>
jmp    1173 <wcsncpy+0x73>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     11a6 <wcsncpy+0xa6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movl   $0x0,(%rax)
jmp    1173 <wcsncpy+0x73>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsncpy>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
mov    %rdx,%rcx
nopl   0x0(%rax)
sub    $0x1,%rcx
jb     114b <wcsncpy+0x3b>
mov    (%rsi,%rax,1),%edi
mov    %edi,(%rbx,%rax,1)
add    $0x4,%rax
test   %edi,%edi
jne    1120 <wcsncpy+0x10>
test   %rcx,%rcx
je     114b <wcsncpy+0x3b>
lea    (%rbx,%rax,1),%rdi
shl    $0x2,%rdx
sub    %rax,%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32* @wcsncpy(i32* returned writeonly %0, i32* 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 i64 %7, -1
%9 = icmp eq i64 %7, 0
br i1 %9, label %20, label %10
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 eq i64 %8, 0
br i1 %16, label %20, label %17
17: ; preds = %15
%18 = bitcast i32* %13 to i8*
%19 = shl nuw i64 %8, 2
br label %20
20: ; preds = %4, %17, %15
ret i32* %0
}