#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 */
char *strrchr1(const char *s, int c) {
  size_t length = 0;
  while (*s++ != '\0')
    length++;
  while (length-- >= 0) {
    if (*s == c)
      return s;
    s--;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<strrchr1>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
je     113f <strrchr1+0x3f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1113 <strrchr1+0x13>
jmp    1144 <strrchr1+0x44>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
jb     118b <strrchr1+0x8b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x14(%rbp),%eax
jne    117a <strrchr1+0x7a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1193 <strrchr1+0x93>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <strrchr1+0x44>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrchr1>:
mov    %rdi,%rax
add    $0x1,%rax
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,-0x1(%rax)
lea    0x1(%rax),%rax
jne    1110 <strrchr1+0x10>
nopw   0x0(%rax,%rax,1)
movsbl -0x1(%rax),%ecx
add    $0xffffffffffffffff,%rax
cmp    %esi,%ecx
jne    1120 <strrchr1+0x20>
ret

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

LLVM IR (-O2):
define i8* @strrchr1(i8* %0, i32 %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i8* [ %0, %2 ], [ %5, %3 ]
%5 = getelementptr inbounds i8, i8* %4, i64 1
%6 = load i8, i8* %4
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %3
8: ; preds = %3, %8
%9 = phi i8* [ %13, %8 ], [ %5, %3 ]
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, %1
%13 = getelementptr inbounds i8, i8* %9, i64 -1
br i1 %12, label %14, label %8
14: ; preds = %8
ret i8* %9
}