#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 */
typedef size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ strchr(char *, char);
int strlen(char *);
ssize_t strFindLastOf(char *string, char *search) {
  char *pos;
  assert(string != NULL);
  assert(search != NULL);
  pos = string + strlen(string) - 1;
  while (pos >= string) {
    if (strchr(search, *pos))
      break;
    pos--;
  }
  return pos >= string ? (size_t)(pos - string) : -1;
}


x86 assembly (clang, -O0):
<strFindLastOf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
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
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     11c7 <strFindLastOf+0x97>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11b6 <strFindLastOf+0x86>
jmp    11c7 <strFindLastOf+0x97>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1189 <strFindLastOf+0x59>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     11e9 <strFindLastOf+0xb9>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    11f9 <strFindLastOf+0xc9>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    11f9 <strFindLastOf+0xc9>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strFindLastOf>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1050 <assert@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
add    $0xffffffffffffffff,%rcx
nopl   0x0(%rax)
mov    %rcx,%r12
lea    (%r15,%rcx,1),%rbx
cmp    %r15,%rbx
jb     1191 <strFindLastOf+0x61>
movsbl (%rbx),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
lea    -0x1(%r12),%rcx
test   %rax,%rax
je     1170 <strFindLastOf+0x40>
cmp    %r15,%rbx
mov    $0xffffffffffffffff,%rax
cmovb  %rax,%r12
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @strFindLastOf(i8* %0, i8* %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 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %3
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 -1
store i8* %19, i8** %5
br label %20
20: ; preds = %31, %2
%21 = load i8*, i8** %5
%22 = load i8*, i8** %3
%23 = icmp uge i8* %21, %22
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = call i64 @strchr(i8* %25, i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
br label %34
31: ; preds = %24
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 -1
store i8* %33, i8** %5
br label %20
34: ; preds = %30, %20
%35 = load i8*, i8** %5
%36 = load i8*, i8** %3
%37 = icmp uge i8* %35, %36
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i8*, i8** %5
%40 = load i8*, i8** %3
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
br label %45
44: ; preds = %34
br label %45
45: ; preds = %44, %38
%46 = phi i64 [ %43, %38 ], [ -1, %44 ]
ret i64 %46
}

LLVM IR (-O2):
define i64 @strFindLastOf(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne i8* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @strlen(i8* %0)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
br label %12
12: ; preds = %16, %2
%13 = phi i8* [ %11, %2 ], [ %14, %16 ]
%14 = getelementptr inbounds i8, i8* %13, i64 -1
%15 = icmp ult i8* %14, %0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i8, i8* %14
%18 = tail call i64 @strchr(i8* %1, i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %12, label %20
20: ; preds = %16, %12
%21 = ptrtoint i8* %14 to i64
%22 = ptrtoint i8* %0 to i64
%23 = sub i64 %21, %22
%24 = select i1 %15, i64 -1, i64 %23
ret i64 %24
}