#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__ strchr(char *, char);
int strlen(char *);
char *strrpbrk(char *str, char *pat) {
  char *q, *p;
  q = p = str + strlen(str);
  while (--p != str) {
    if (strchr(pat, *p)) {
      q = p;
      break;
    }
  }
  return q;
}


x86 assembly (clang, -O0):
<strrpbrk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
cmp    -0x8(%rbp),%rax
je     1197 <strrpbrk+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1192 <strrpbrk+0x72>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1197 <strrpbrk+0x77>
jmp    1155 <strrpbrk+0x35>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrpbrk>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
movslq %eax,%rbx
lea    (%r12,%rbx,1),%r15
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%rbx
je     1163 <strrpbrk+0x43>
movsbl -0x1(%r12,%rbx,1),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
je     1140 <strrpbrk+0x20>
add    %rbx,%r12
mov    %r12,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strrpbrk(i8* %0, i8* %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 eq i8* %8, %0
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = load i8, i8* %8
%12 = tail call i64 @strchr(i8* %1, i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %10, %6
%15 = phi i8* [ %5, %6 ], [ %8, %10 ]
ret i8* %15
}