#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 */
int /*<<< orphan*/ assert(int);
char const *memrchr(char const *, char, int);
int main() {
  const char *test = "blubber";
  assert(memrchr("aaaa", 'x', 4) == 0);
  assert(memrchr(0, 'x', 0) == 0);
  assert(memrchr(test, 'u', 7) == test + 2);
  assert(memrchr(test, 'b', 7) == test + 4);
  assert(memrchr(test + 6, 'r', 1) == test + 6);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x78,%esi
mov    $0x4,%edx
call   1040 <memrchr@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
mov    $0x78,%esi
xor    %edx,%edx
call   1040 <memrchr@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x75,%esi
mov    $0x7,%edx
call   1040 <memrchr@plt>
mov    -0x10(%rbp),%rcx
add    $0x2,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x62,%esi
mov    $0x7,%edx
call   1040 <memrchr@plt>
mov    -0x10(%rbp),%rcx
add    $0x4,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
add    $0x6,%rdi
mov    $0x72,%esi
mov    $0x1,%edx
call   1040 <memrchr@plt>
mov    -0x10(%rbp),%rcx
add    $0x6,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xee0(%rip),%rdi
mov    $0x78,%esi
mov    $0x4,%edx
call   1040 <memrchr@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
mov    $0x78,%esi
xor    %edx,%edx
call   1040 <memrchr@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
lea    0xe98(%rip),%rbx
mov    %rbx,%rdi
mov    $0x75,%esi
mov    $0x7,%edx
call   1040 <memrchr@plt>
lea    0xe81(%rip),%rcx
xor    %edi,%edi
cmp    %rcx,%rax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    $0x62,%esi
mov    $0x7,%edx
call   1040 <memrchr@plt>
lea    0xe5c(%rip),%rcx
xor    %edi,%edi
cmp    %rcx,%rax
sete   %dil
call   1030 <assert@plt>
lea    0xe49(%rip),%rbx
mov    %rbx,%rdi
mov    $0x72,%esi
mov    $0x1,%edx
call   1040 <memrchr@plt>
xor    %edi,%edi
cmp    %rbx,%rax
sete   %dil
call   1030 <assert@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"blubber\00"
@.str.1 = [5 x i8] c"aaaa\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %2
%3 = call i8* @memrchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 signext 120, i32 4)
%4 = icmp eq i8* %3, null
%5 = zext i1 %4 to i32
%6 = call i32 @assert(i32 %5)
%7 = call i8* @memrchr(i8* null, i8 signext 120, i32 0)
%8 = icmp eq i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %2
%12 = call i8* @memrchr(i8* %11, i8 signext 117, i32 7)
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 2
%15 = icmp eq i8* %12, %14
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %2
%19 = call i8* @memrchr(i8* %18, i8 signext 98, i32 7)
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 4
%22 = icmp eq i8* %19, %21
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i64 6
%27 = call i8* @memrchr(i8* %26, i8 signext 114, i32 1)
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i64 6
%30 = icmp eq i8* %27, %29
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"blubber\00"
@.str.1 = [5 x i8] c"aaaa\00"
define i32 @main() {
%1 = tail call i8* @memrchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 signext 120, i32 4)
%2 = icmp eq i8* %1, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i8* @memrchr(i8* null, i8 signext 120, i32 0)
%6 = icmp eq i8* %5, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i8* @memrchr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 signext 117, i32 7)
%10 = icmp eq i8* %9, getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 2)
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i8* @memrchr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 signext 98, i32 7)
%14 = icmp eq i8* %13, getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 4)
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i8* @memrchr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 6), i8 signext 114, i32 1)
%18 = icmp eq i8* %17, getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 6)
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
ret i32 0
}