#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 const *, char const);
int strlen(char const *);
char *strrset(const char *p, const char *set) {
  int i;
  for (i = strlen(p); i >= 0; i--) {
    if (strchr(set, p[i]))
      return ((char *)(&p[i]));
  }
  return (0);
}


x86 assembly (clang, -O0):
<strrset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     118c <strrset+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1179 <strrset+0x59>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1194 <strrset+0x74>
jmp    117e <strrset+0x5e>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <strrset+0x1c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrset>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
test   %eax,%eax
js     1160 <strrset+0x40>
mov    %eax,%ebx
xor    %r15d,%r15d
nopl   0x0(%rax)
movsbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1165 <strrset+0x45>
lea    -0x1(%rbx),%rax
test   %rbx,%rbx
mov    %rax,%rbx
jg     1140 <strrset+0x20>
jmp    116d <strrset+0x4d>
xor    %r15d,%r15d
jmp    116d <strrset+0x4d>
mov    %ebx,%eax
add    %rax,%r12
mov    %r12,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strrset(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %19
5: ; preds = %2
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %13
%8 = phi i64 [ %6, %5 ], [ %14, %13 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = tail call i64 @strchr(i8* %1, i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = add nsw i64 %8, -1
%15 = icmp sgt i64 %8, 0
br i1 %15, label %7, label %19
16: ; preds = %7
%17 = and i64 %8, 4294967295
%18 = getelementptr inbounds i8, i8* %0, i64 %17
br label %19
19: ; preds = %13, %2, %16
%20 = phi i8* [ %18, %16 ], [ null, %2 ], [ null, %13 ]
ret i8* %20
}