#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 */
int /*<<< orphan*/ wcscpy(scalar_t__ *, scalar_t__ const *);
size_t wcslen(scalar_t__ const *);
int /*<<< orphan*/ wmemcpy(scalar_t__ *, scalar_t__ const *, size_t);
size_t wcsxfrm(wchar_t *restrict dest, const wchar_t *restrict src, size_t n) {
  size_t l = wcslen(src);
  if (l >= n) {
    wmemcpy(dest, src, n - 1);
    dest[n - 1] = 0;
  } else
    wcscpy(dest, src);
  return l;
}


x86 assembly (clang, -O0):
<wcsxfrm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <wcslen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     118d <wcsxfrm+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <wmemcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    119a <wcsxfrm+0x6a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <wcscpy@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsxfrm>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <wcslen@plt>
mov    %rax,%r15
cmp    %r12,%rax
jae    115e <wcsxfrm+0x2e>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <wcscpy@plt>
jmp    1177 <wcsxfrm+0x47>
lea    -0x1(%r12),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <wmemcpy@plt>
movq   $0x0,-0x8(%r14,%r12,8)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @wcsxfrm(i64* noalias %0, i64* noalias %1, i64 %2) {
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
store i64* %0, i64** %4
store i64* %1, i64** %5
store i64 %2, i64* %6
%8 = load i64*, i64** %5
%9 = call i64 @wcslen(i64* %8)
store i64 %9, i64* %7
%10 = load i64, i64* %7
%11 = load i64, i64* %6
%12 = icmp uge i64 %10, %11
br i1 %12, label %13, label %23
13: ; preds = %3
%14 = load i64*, i64** %4
%15 = load i64*, i64** %5
%16 = load i64, i64* %6
%17 = sub i64 %16, 1
%18 = call i32 @wmemcpy(i64* %14, i64* %15, i64 %17)
%19 = load i64*, i64** %4
%20 = load i64, i64* %6
%21 = sub i64 %20, 1
%22 = getelementptr inbounds i64, i64* %19, i64 %21
store i64 0, i64* %22
br label %27
23: ; preds = %3
%24 = load i64*, i64** %4
%25 = load i64*, i64** %5
%26 = call i32 @wcscpy(i64* %24, i64* %25)
br label %27
27: ; preds = %23, %13
%28 = load i64, i64* %7
ret i64 %28
}

LLVM IR (-O2):
define i64 @wcsxfrm(i64* noalias %0, i64* noalias %1, i64 %2) {
%4 = tail call i64 @wcslen(i64* %1)
%5 = icmp ult i64 %4, %2
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = add i64 %2, -1
%8 = tail call i32 @wmemcpy(i64* %0, i64* %1, i64 %7)
%9 = getelementptr inbounds i64, i64* %0, i64 %7
store i64 0, i64* %9
br label %12
10: ; preds = %3
%11 = tail call i32 @wcscpy(i64* %0, i64* %1)
br label %12
12: ; preds = %10, %6
ret i64 %4
}