#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 crStrlen(char const *);
char *crStrrchr(const char *str, char c) {
  const char *temp = str + crStrlen(str);
  for (; temp >= str; temp--) {
    if (*temp == c)
      return (char *)temp;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<crStrrchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <crStrlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     1187 <crStrrchr+0x77>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    1171 <crStrrchr+0x61>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <crStrrchr+0x7f>
jmp    1176 <crStrrchr+0x66>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1143 <crStrrchr+0x33>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crStrrchr>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <crStrlen@plt>
test   %eax,%eax
js     113e <crStrrchr+0x2e>
mov    %eax,%eax
add    %rbx,%rax
cs nopw 0x0(%rax,%rax,1)
cmp    %bpl,(%rax)
je     1140 <crStrrchr+0x30>
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jae    1130 <crStrrchr+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @crStrrchr(i8* %0, i8 signext %1) {
%3 = tail call i32 @crStrlen(i8* %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 i8, i8* %0, i64 %6
br label %8
8: ; preds = %5, %12
%9 = phi i8* [ %13, %12 ], [ %7, %5 ]
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, %1
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %9, i64 -1
%14 = icmp ult i8* %13, %0
br i1 %14, label %15, label %8
15: ; preds = %8, %12, %2
%16 = phi i8* [ null, %2 ], [ null, %12 ], [ %9, %8 ]
ret i8* %16
}