#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__ wmemcmp;
typedef int /*<<< orphan*/ const wchar_t;

/* Variables and functions */
size_t wcscnlen(int /*<<< orphan*/ const *, int /*<<< orphan*/ const, size_t);
wchar_t *(wcscnends)(const wchar_t *string, const wchar_t *desired,
                     wchar_t stop, size_t maxlen) {
  size_t n = wcscnlen(string, stop, maxlen);
  size_t m = wcscnlen(desired, stop, maxlen);
  if (n < m)
    return NULL;
  return (wmemcmp)(string + (n - m), desired, m) ? NULL : (string + n);
}


x86 assembly (clang, -O0):
<wcscnends>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1030 <wcscnlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1030 <wcscnlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    116a <wcscnends+0x5a>
movq   $0x0,-0x8(%rbp)
jmp    119b <wcscnends+0x8b>
cmpq   $0x0,-0x38(%rbp)
je     1180 <wcscnends+0x70>
xor    %eax,%eax
mov    %rax,-0x40(%rbp)
jmp    1193 <wcscnends+0x83>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcscnends>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%esi
mov    %rcx,%rdx
call   1030 <wcscnlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1030 <wcscnlen@plt>
xor    %edx,%edx
test   %rax,%rax
lea    (%r15,%r12,4),%rcx
cmovne %rdx,%rcx
cmp    %rax,%r12
cmovb  %rdx,%rcx
mov    %rcx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32* @wcscnends(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 = icmp eq i64 %6, 0
%9 = getelementptr inbounds i32, i32* %0, i64 %5
%10 = select i1 %8, i32* %9, i32* null
%11 = select i1 %7, i32* null, i32* %10
ret i32* %11
}