#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);
int strlen(char *);
char *gs_r_accept(char *str, const char *accept) {
  char *end;
  end = str + strlen(str);
  while (--end >= str) {
    if (strchr(accept, *end))
      return end;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<gs_r_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%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
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
cmp    -0x10(%rbp),%rax
jb     1193 <gs_r_accept+0x73>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     118e <gs_r_accept+0x6e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119b <gs_r_accept+0x7b>
jmp    1151 <gs_r_accept+0x31>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gs_r_accept>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
cltq
lea    (%rax,%r12,1),%rbx
add    $0xffffffffffffffff,%rbx
xor    %r15d,%r15d
cmp    %r12,%rbx
jb     1160 <gs_r_accept+0x40>
movsbl (%rbx),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
je     1140 <gs_r_accept+0x20>
add    $0x1,%rbx
mov    %rbx,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @gs_r_accept(i8* %0, i8* %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
store i8* %11, i8** %6
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** %4
%16 = icmp uge i8* %14, %15
br i1 %16, label %17, label %26
17: ; preds = %12
%18 = load i8*, i8** %5
%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** %3
br label %27
25: ; preds = %17
br label %12
26: ; preds = %12
store i8* null, i8** %3
br label %27
27: ; preds = %26, %23
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
define i8* @gs_r_accept(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 ult 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 = %6, %10
%15 = phi i8* [ %8, %10 ], [ null, %6 ]
ret i8* %15
}