#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 */
size_t wcscnlen(int /*<<< orphan*/ const *, int /*<<< orphan*/, size_t);
int wmemcmp(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *, size_t);
int wcscncmp(const wchar_t *a, const wchar_t *b, wchar_t stop, size_t length) {
  size_t n = wcscnlen(a, stop, length);
  size_t m = wcscnlen(b, stop, length);
  int r = wmemcmp(a, b, (n < m ? n : m));
  return r ? r : n == m ? 0 : n < m ? -1 : +1;
}


x86 assembly (clang, -O0):
<wcscncmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <wcscnlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <wcscnlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    118a <wcscncmp+0x6a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    1192 <wcscncmp+0x72>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rdx
call   1040 <wmemcmp@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11bb <wcscncmp+0x9b>
mov    -0x34(%rbp),%eax
mov    %eax,-0x54(%rbp)
jmp    11f4 <wcscncmp+0xd4>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    11d3 <wcscncmp+0xb3>
xor    %eax,%eax
mov    %eax,-0x58(%rbp)
jmp    11ee <wcscncmp+0xce>
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rsi
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    %rsi,%rdx
cmovb  %ecx,%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcscncmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%esi
mov    %rcx,%rdx
call   1030 <wcscnlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   1030 <wcscnlen@plt>
xor    %ecx,%ecx
xor    %edx,%edx
cmp    %rax,%rbx
cmovae %rax,%rbx
setae  %dl
lea    -0x1(%rdx,%rdx,1),%ebp
cmove  %ecx,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <wmemcmp@plt>
test   %eax,%eax
cmove  %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @wcscncmp(i32* %0, i32* %1, i32 %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i64 %3, i64* %8
%12 = load i32*, i32** %5
%13 = load i32, i32* %7
%14 = load i64, i64* %8
%15 = call i64 @wcscnlen(i32* %12, i32 %13, i64 %14)
store i64 %15, i64* %9
%16 = load i32*, i32** %6
%17 = load i32, i32* %7
%18 = load i64, i64* %8
%19 = call i64 @wcscnlen(i32* %16, i32 %17, i64 %18)
store i64 %19, i64* %10
%20 = load i32*, i32** %5
%21 = load i32*, i32** %6
%22 = load i64, i64* %9
%23 = load i64, i64* %10
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %4
%26 = load i64, i64* %9
br label %29
27: ; preds = %4
%28 = load i64, i64* %10
br label %29
29: ; preds = %27, %25
%30 = phi i64 [ %26, %25 ], [ %28, %27 ]
%31 = call i32 @wmemcmp(i32* %20, i32* %21, i64 %30)
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i32, i32* %11
br label %49
36: ; preds = %29
%37 = load i64, i64* %9
%38 = load i64, i64* %10
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %36
br label %47
41: ; preds = %36
%42 = load i64, i64* %9
%43 = load i64, i64* %10
%44 = icmp ult i64 %42, %43
%45 = zext i1 %44 to i64
%46 = select i1 %44, i32 -1, i32 1
br label %47
47: ; preds = %41, %40
%48 = phi i32 [ 0, %40 ], [ %46, %41 ]
br label %49
49: ; preds = %47, %34
%50 = phi i32 [ %35, %34 ], [ %48, %47 ]
ret i32 %50
}

LLVM IR (-O2):
define i32 @wcscncmp(i32* %0, i32* %1, i32 %2, i64 %3) {
%5 = tail call i64 @wcscnlen(i32* %0, i32 %2, i64 %3)
%6 = tail call i64 @wcscnlen(i32* %1, i32 %2, i64 %3)
%7 = icmp ult i64 %5, %6
%8 = select i1 %7, i64 %5, i64 %6
%9 = tail call i32 @wmemcmp(i32* %0, i32* %1, i64 %8)
%10 = icmp eq i32 %9, 0
%11 = icmp eq i64 %5, %6
%12 = select i1 %7, i32 -1, i32 1
%13 = select i1 %11, i32 0, i32 %12
%14 = select i1 %10, i32 %13, i32 %9
ret i32 %14
}