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

/* Variables and functions */
int wcslen(scalar_t__ const *);
wchar_t *wcsrchr(const wchar_t *s, wchar_t c) {
  const wchar_t *p;
  for (p = s + wcslen(s); p >= s && *p != c; p--)
    ;
  return p >= s ? (wchar_t *)p : 0;
}


x86 assembly (clang, -O0):
<wcsrchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x21(%rbp)
jb     1169 <wcsrchr+0x59>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmp    -0x10(%rbp),%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1179 <wcsrchr+0x69>
jmp    118f <wcsrchr+0x7f>
jmp    117e <wcsrchr+0x6e>
mov    -0x18(%rbp),%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x18(%rbp)
jmp    1145 <wcsrchr+0x35>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     11aa <wcsrchr+0x9a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11b5 <wcsrchr+0xa5>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11b5 <wcsrchr+0xa5>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsrchr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <wcslen@plt>
test   %eax,%eax
js     113e <wcsrchr+0x2e>
mov    %eax,%eax
lea    (%rbx,%rax,8),%rax
nopl   0x0(%rax)
cmp    %r14,(%rax)
je     1140 <wcsrchr+0x30>
add    $0xfffffffffffffff8,%rax
cmp    %rbx,%rax
jae    1130 <wcsrchr+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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