#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 wind_strlen(char const *);
char *wind_strrchr(const char *s, char c) {
  const char *p = (const char *)(s + wind_strlen(s));
  do {
    if (*p == (char)c)
      return (char *)p;
  } while (--p >= s);
  return (char *)((void *)0);
}


x86 assembly (clang, -O0):
<wind_strrchr>:
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 <wind_strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    1163 <wind_strrchr+0x53>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1186 <wind_strrchr+0x76>
jmp    1168 <wind_strrchr+0x58>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
cmp    -0x10(%rbp),%rax
jae    1143 <wind_strrchr+0x33>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wind_strrchr>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <wind_strlen@plt>
cltq
add    %rbx,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %bpl,(%rax)
je     1140 <wind_strrchr+0x30>
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jae    1130 <wind_strrchr+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @wind_strrchr(i8* %0, i8 signext %1) {
%3 = tail call i32 @wind_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 ], [ %11, %10 ]
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, %1
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %7, i64 -1
%12 = icmp ult i8* %11, %0
br i1 %12, label %13, label %6
13: ; preds = %10, %6
%14 = phi i8* [ %7, %6 ], [ null, %10 ]
ret i8* %14
}