#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 strmlen(char *);
char *strmrchr(char *str, char searchFor) {
  char *pointer = NULL;
  register int counter = strmlen(str);
  for (; counter >= 0; --counter)
    if (str[counter] == searchFor) {
      pointer = &str[counter];
      break;
    }
  return pointer;
}


x86 assembly (clang, -O0):
<strmrchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strmlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     117f <strmrchr+0x6f>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    116c <strmrchr+0x5c>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    117f <strmrchr+0x6f>
jmp    1171 <strmrchr+0x61>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1136 <strmrchr+0x26>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strmrchr>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strmlen@plt>
test   %eax,%eax
js     1145 <strmrchr+0x35>
mov    %eax,%ecx
mov    %eax,%eax
add    %rbx,%rax
nopl   0x0(%rax,%rax,1)
mov    %ecx,%edx
cmp    %bpl,(%rbx,%rdx,1)
je     1147 <strmrchr+0x37>
lea    -0x1(%rcx),%edx
add    $0xffffffffffffffff,%rax
test   %ecx,%ecx
mov    %edx,%ecx
jg     1130 <strmrchr+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @strmrchr(i8* %0, i8 signext %1) {
%3 = tail call i32 @strmlen(i8* %0)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %17
5: ; preds = %2, %11
%6 = phi i32 [ %12, %11 ], [ %3, %2 ]
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, %1
br i1 %10, label %14, label %11
11: ; preds = %5
%12 = add nsw i32 %6, -1
%13 = icmp sgt i32 %6, 0
br i1 %13, label %5, label %17
14: ; preds = %5
%15 = zext i32 %6 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
br label %17
17: ; preds = %11, %14, %2
%18 = phi i8* [ null, %2 ], [ %16, %14 ], [ null, %11 ]
ret i8* %18
}