#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 strlen(char const *);
char *reverse_strchr(const char *s, char c) {
  char *pt;
  for (pt = s + strlen(s) - 1; pt >= s; pt--) {
    if (*pt == c)
      return pt;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<reverse_strchr>:
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 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     118b <reverse_strchr+0x7b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    1175 <reverse_strchr+0x65>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1193 <reverse_strchr+0x83>
jmp    117a <reverse_strchr+0x6a>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1147 <reverse_strchr+0x37>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_strchr>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rcx
add    $0xffffffffffffffff,%rcx
xor    %eax,%eax
nopl   0x0(%rax)
cmp    %rbx,%rcx
jb     1148 <reverse_strchr+0x38>
lea    -0x1(%rcx),%rdx
cmp    %bpl,(%rcx)
mov    %rdx,%rcx
jne    1130 <reverse_strchr+0x20>
add    $0x1,%rdx
mov    %rdx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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