#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 /*<<< orphan*/ _DIAGASSERT(int /*<<< orphan*/);
scalar_t__ const *__UNCONST(scalar_t__ const *);
wchar_t *wcsrchr(const wchar_t *s, wchar_t c) {
  const wchar_t *p;
  _DIAGASSERT(s != NULL);
  p = s;
  while (*p)
    p++;
  while (s <= p) {
    if (*p == c)
      return __UNCONST(p);
    p--;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<wcsrchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <_DIAGASSERT@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1169 <wcsrchr+0x49>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    114a <wcsrchr+0x2a>
jmp    116e <wcsrchr+0x4e>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     11b0 <wcsrchr+0x90>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jne    119f <wcsrchr+0x7f>
mov    -0x20(%rbp),%rdi
call   1040 <__UNCONST@plt>
mov    %rax,-0x8(%rbp)
jmp    11b8 <wcsrchr+0x98>
mov    -0x20(%rbp),%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x20(%rbp)
jmp    116e <wcsrchr+0x4e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsrchr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <_DIAGASSERT@plt>
lea    -0x8(%rbx),%rdi
nopl   0x0(%rax)
cmpq   $0x0,0x8(%rdi)
lea    0x8(%rdi),%rdi
jne    1140 <wcsrchr+0x20>
cmp    %rbx,%rdi
jae    115a <wcsrchr+0x3a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
test   %r14,%r14
je     1188 <wcsrchr+0x68>
add    $0xfffffffffffffff8,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %rbx,%rdi
jb     1150 <wcsrchr+0x30>
lea    -0x8(%rdi),%rax
cmp    %r14,(%rdi)
mov    %rax,%rdi
jne    1170 <wcsrchr+0x50>
add    $0x8,%rax
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <__UNCONST@plt>

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

LLVM IR (-O2):
define i64* @wcsrchr(i64* %0, i64 %1) {
%3 = icmp ne i64* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @_DIAGASSERT(i32 %4)
br label %6
6: ; preds = %6, %2
%7 = phi i64* [ %0, %2 ], [ %10, %6 ]
%8 = load i64, i64* %7
%9 = icmp eq i64 %8, 0
%10 = getelementptr inbounds i64, i64* %7, i64 1
br i1 %9, label %11, label %6
11: ; preds = %6
%12 = icmp ult i64* %7, %0
br i1 %12, label %25, label %13
13: ; preds = %11
%14 = icmp eq i64 %1, 0
br i1 %14, label %15, label %18
15: ; preds = %22, %13
%16 = phi i64* [ %7, %13 ], [ %20, %22 ]
%17 = tail call i64* @__UNCONST(i64* %16)
br label %25
18: ; preds = %13, %22
%19 = phi i64* [ %20, %22 ], [ %7, %13 ]
%20 = getelementptr inbounds i64, i64* %19, i64 -1
%21 = icmp ult i64* %20, %0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i64, i64* %20
%24 = icmp eq i64 %23, %1
br i1 %24, label %15, label %18
25: ; preds = %18, %11, %15
%26 = phi i64* [ %17, %15 ], [ null, %11 ], [ null, %18 ]
ret i64* %26
}