#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*/ const wchar_t;

/* Variables and functions */
size_t wcslen(int /*<<< orphan*/ const *);
scalar_t__ wmemcasecmp(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
                       size_t);
wchar_t *(wcscaseends)(const wchar_t *string, const wchar_t *desired) {
  size_t n = wcslen(string);
  size_t m = wcslen(desired);
  if (n < m)
    return NULL;
  return wmemcasecmp(string + (n - m), desired, m) ? NULL : (string + n);
}


x86 assembly (clang, -O0):
<wcscaseends>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1165 <wcscaseends+0x45>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <wcscaseends+0x95>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
sub    -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <wmemcasecmp@plt>
cmp    $0x0,%rax
je     119a <wcscaseends+0x7a>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11ad <wcscaseends+0x8d>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcscaseends>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <wcslen@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <wcslen@plt>
mov    %r14,%rcx
sub    %rax,%rcx
jae    1147 <wcscaseends+0x27>
xor    %eax,%eax
jmp    1166 <wcscaseends+0x46>
lea    (%rbx,%rcx,4),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <wmemcasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
lea    (%rbx,%r14,4),%rcx
cmove  %rcx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32* @wcscaseends(i32* %0, i32* %1) {
%3 = tail call i64 @wcslen(i32* %0)
%4 = tail call i64 @wcslen(i32* %1)
%5 = icmp ult i64 %3, %4
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = sub i64 %3, %4
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = tail call i64 @wmemcasecmp(i32* %8, i32* %1, i64 %4)
%10 = icmp eq i64 %9, 0
%11 = getelementptr inbounds i32, i32* %0, i64 %3
%12 = select i1 %10, i32* %11, i32* null
br label %13
13: ; preds = %2, %6
%14 = phi i32* [ %12, %6 ], [ null, %2 ]
ret i32* %14
}