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

/* Variables and functions */
void *memrchr16(void const *, int /*<<< orphan*/, size_t);
void *memrchr32(void const *, int /*<<< orphan*/, size_t);
void *memrchr64(void const *, int /*<<< orphan*/, size_t);
void *memrchr8(void const *, int /*<<< orphan*/, size_t);
void *memrchr(const void *s, uint8_t c, size_t n) {
  switch ((n < sizeof(unsigned long)) ? n : sizeof(unsigned long)) {
  case 8:
    return (memrchr64(s, c, n));
  case 4:
    return (memrchr32(s, c, n));
  case 2:
    return (memrchr16(s, c, n));
  }
  return (memrchr8(s, c, n));
}


x86 assembly (clang, -O0):
<memrchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x8,-0x20(%rbp)
jae    116b <memrchr+0x2b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1179 <memrchr+0x39>
mov    $0x8,%eax
mov    %rax,-0x28(%rbp)
jmp    1179 <memrchr+0x39>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
sub    $0x2,%rax
je     11e8 <memrchr+0xa8>
jmp    1190 <memrchr+0x50>
mov    -0x30(%rbp),%rax
sub    $0x4,%rax
je     11cf <memrchr+0x8f>
jmp    11a3 <memrchr+0x63>
mov    -0x30(%rbp),%rax
sub    $0x8,%rax
jne    1201 <memrchr+0xc1>
jmp    11b6 <memrchr+0x76>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <memrchr64@plt>
mov    %rax,-0x8(%rbp)
jmp    1215 <memrchr+0xd5>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <memrchr32@plt>
mov    %rax,-0x8(%rbp)
jmp    1215 <memrchr+0xd5>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <memrchr16@plt>
mov    %rax,-0x8(%rbp)
jmp    1215 <memrchr+0xd5>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <memrchr8@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memrchr>:
cmp    $0x8,%rdx
mov    $0x8,%eax
cmovb  %rdx,%rax
cmp    $0x2,%rax
je     1164 <memrchr+0x24>
cmp    $0x4,%rax
je     1169 <memrchr+0x29>
cmp    $0x8,%rax
jne    116e <memrchr+0x2e>
jmp    1040 <memrchr64@plt>
jmp    1030 <memrchr16@plt>
jmp    1050 <memrchr32@plt>
jmp    1060 <memrchr8@plt>

LLVM IR (-O0):
define i8* @memrchr(i8* %0, i32 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64 %2, i64* %7
%8 = load i64, i64* %7
%9 = icmp ult i64 %8, 8
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = load i64, i64* %7
br label %13
12: ; preds = %3
br label %13
13: ; preds = %12, %10
%14 = phi i64 [ %11, %10 ], [ 8, %12 ]
switch i64 %14, label %30 [
i64 8, label %15
i64 4, label %20
i64 2, label %25
]
15: ; preds = %13
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = load i64, i64* %7
%19 = call i8* @memrchr64(i8* %16, i32 %17, i64 %18)
store i8* %19, i8** %4
br label %35
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = load i64, i64* %7
%24 = call i8* @memrchr32(i8* %21, i32 %22, i64 %23)
store i8* %24, i8** %4
br label %35
25: ; preds = %13
%26 = load i8*, i8** %5
%27 = load i32, i32* %6
%28 = load i64, i64* %7
%29 = call i8* @memrchr16(i8* %26, i32 %27, i64 %28)
store i8* %29, i8** %4
br label %35
30: ; preds = %13
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = load i64, i64* %7
%34 = call i8* @memrchr8(i8* %31, i32 %32, i64 %33)
store i8* %34, i8** %4
br label %35
35: ; preds = %30, %25, %20, %15
%36 = load i8*, i8** %4
ret i8* %36
}

LLVM IR (-O2):
define i8* @memrchr(i8* %0, i32 %1, i64 %2) {
%4 = icmp ult i64 %2, 8
%5 = select i1 %4, i64 %2, i64 8
switch i64 %5, label %12 [
i64 8, label %6
i64 4, label %8
i64 2, label %10
]
6: ; preds = %3
%7 = tail call i8* @memrchr64(i8* %0, i32 %1, i64 %2)
br label %14
8: ; preds = %3
%9 = tail call i8* @memrchr32(i8* %0, i32 %1, i64 %2)
br label %14
10: ; preds = %3
%11 = tail call i8* @memrchr16(i8* %0, i32 %1, i64 %2)
br label %14
12: ; preds = %3
%13 = tail call i8* @memrchr8(i8* %0, i32 %1, i64 %2)
br label %14
14: ; preds = %12, %10, %8, %6
%15 = phi i8* [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %7, %6 ]
ret i8* %15
}