#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 */
scalar_t__ chrlcaps(char);
int strlen(char *);
char *strrcasechr(char *in, char c) {
  char *last = in + strlen(in);
  while (*in) {
    if (chrlcaps(*in) == chrlcaps(c))
      last = in;
    in++;
  }
  return last;
}


x86 assembly (clang, -O0):
<strrcasechr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a2 <strrcasechr+0x82>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <chrlcaps@plt>
mov    %rax,-0x28(%rbp)
movsbl -0x9(%rbp),%edi
call   1040 <chrlcaps@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jne    1191 <strrcasechr+0x71>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1153 <strrcasechr+0x33>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrcasechr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%r14
add    %rbx,%r14
mov    (%rbx),%al
test   %al,%al
je     1176 <strrcasechr+0x56>
movsbl %bpl,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <chrlcaps@plt>
mov    %rax,%rbp
mov    %r15d,%edi
call   1040 <chrlcaps@plt>
cmp    %rax,%rbp
cmove  %rbx,%r14
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <strrcasechr+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @strrcasechr(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
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %2, %8
%9 = phi i8 [ %17, %8 ], [ %6, %2 ]
%10 = phi i8* [ %15, %8 ], [ %5, %2 ]
%11 = phi i8* [ %16, %8 ], [ %0, %2 ]
%12 = tail call i64 @chrlcaps(i8 signext %9)
%13 = tail call i64 @chrlcaps(i8 signext %1)
%14 = icmp eq i64 %12, %13
%15 = select i1 %14, i8* %11, i8* %10
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %8
19: ; preds = %8, %2
%20 = phi i8* [ %5, %2 ], [ %15, %8 ]
ret i8* %20
}