#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 */

/* Variables and functions */
const void *zend_memrchr(const void *s, int c, size_t n) {
  register const unsigned char *e;
  if (n <= 0) {
    return NULL;
  }
  for (e = (const unsigned char *)s + n - 1; e >= (const unsigned char *)s;
       e--) {
    if (*e == (const unsigned char)c) {
      return (const void *)e;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<zend_memrchr>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
ja     1127 <zend_memrchr+0x27>
movq   $0x0,-0x8(%rbp)
jmp    1185 <zend_memrchr+0x85>
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     117d <zend_memrchr+0x7d>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
mov    -0x14(%rbp),%ecx
movzbl %cl,%ecx
cmp    %ecx,%eax
jne    1167 <zend_memrchr+0x67>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1185 <zend_memrchr+0x85>
jmp    116c <zend_memrchr+0x6c>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    1137 <zend_memrchr+0x37>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<zend_memrchr>:
test   %rdx,%rdx
je     1129 <zend_memrchr+0x29>
lea    (%rdx,%rdi,1),%rcx
add    $0xffffffffffffffff,%rcx
xor    %eax,%eax
nop
cmp    %rdi,%rcx
jb     1128 <zend_memrchr+0x28>
lea    -0x1(%rcx),%rdx
cmp    %sil,(%rcx)
mov    %rdx,%rcx
jne    1110 <zend_memrchr+0x10>
add    $0x1,%rdx
mov    %rdx,%rax
ret
xor    %eax,%eax
ret

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

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