#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 */
size_t strlen(char *);
char *strrindex(char *string, const char character) {
  const char *original = string;
  if (original != NULL) {
    string = (char *)&string[strlen(string)];
    while (*string != character) {
      if (string == original) {
        return (NULL);
      }
      string--;
    }
    return (string);
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<strrindex>:
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,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a0 <strrindex+0x90>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     1193 <strrindex+0x83>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1182 <strrindex+0x72>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <strrindex+0x98>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1154 <strrindex+0x44>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <strrindex+0x98>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrindex>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1148 <strrindex+0x38>
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    %bpl,(%rbx,%rax,1)
jne    1130 <strrindex+0x20>
add    %rax,%rbx
jmp    114a <strrindex+0x3a>
nopl   (%rax)
test   %rax,%rax
je     1148 <strrindex+0x38>
lea    -0x1(%rax),%rcx
cmp    %bpl,-0x1(%rbx,%rax,1)
mov    %rcx,%rax
jne    1130 <strrindex+0x20>
add    %rcx,%rbx
jmp    114a <strrindex+0x3a>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @strrindex(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
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %32
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8* %14, i8** %4
br label %15
15: ; preds = %27, %10
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = load i8, i8* %5
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %18, %20
br i1 %21, label %22, label %30
22: ; preds = %15
%23 = load i8*, i8** %4
%24 = load i8*, i8** %6
%25 = icmp eq i8* %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
store i8* null, i8** %3
br label %33
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 -1
store i8* %29, i8** %4
br label %15
30: ; preds = %15
%31 = load i8*, i8** %4
store i8* %31, i8** %3
br label %33
32: ; preds = %2
store i8* null, i8** %3
br label %33
33: ; preds = %32, %30, %26
%34 = load i8*, i8** %3
ret i8* %34
}

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