#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 */
struct string {
  int dummy;
};

/* Variables and functions */
char *string_get(struct string const *);
int strlen(char const *);
int string_find_last_of(struct string const *src, char const *delim) {
  char const *str_beg = string_get(src);
  char const *str = str_beg + (strlen(str_beg) - 1);
  if (!strlen(str_beg))
    return -1;
  do {
    char const *delim_cur = delim;
    while (*delim_cur) {
      if (*str == *delim_cur)
        return str - str_beg;
      delim_cur++;
    }
  } while (str-- != str_beg);
  return -1;
}


x86 assembly (clang, -O0):
<string_find_last_of>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <string_get@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    117f <string_find_last_of+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <string_find_last_of+0xd8>
jmp    1184 <string_find_last_of+0x64>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d3 <string_find_last_of+0xb3>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    -0x30(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11c2 <string_find_last_of+0xa2>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
jmp    11f8 <string_find_last_of+0xd8>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    118c <string_find_last_of+0x6c>
jmp    11d8 <string_find_last_of+0xb8>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
cmp    -0x20(%rbp),%rax
jne    1184 <string_find_last_of+0x64>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_find_last_of>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
call   1040 <string_get@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     1195 <string_find_last_of+0x75>
movslq %ebx,%rcx
add    %rbp,%rcx
add    $0xffffffffffffffff,%rcx
mov    (%r14),%sil
add    $0x1,%r14
jmp    116c <string_find_last_of+0x4c>
nop
lea    -0x1(%rcx),%rdx
cmp    %rbp,%rcx
mov    %rdx,%rcx
je     1195 <string_find_last_of+0x75>
test   %sil,%sil
je     1160 <string_find_last_of+0x40>
mov    (%rcx),%dl
mov    %r14,%rdi
mov    %esi,%ebx
nopl   0x0(%rax,%rax,1)
cmp    %bl,%dl
je     1191 <string_find_last_of+0x71>
movzbl (%rdi),%ebx
add    $0x1,%rdi
test   %bl,%bl
jne    1180 <string_find_last_of+0x60>
jmp    1160 <string_find_last_of+0x40>
sub    %ebp,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.string = type { i32 }
define i32 @string_find_last_of(%struct.string* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.string*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store %struct.string* %0, %struct.string** %4
store i8* %1, i8** %5
%9 = load %struct.string*, %struct.string** %4
%10 = call i8* @string_get(%struct.string* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = load i8*, i8** %6
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %11, i64 %15
store i8* %16, i8** %7
%17 = load i8*, i8** %6
%18 = call i32 @strlen(i8* %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %2
store i32 -1, i32* %3
br label %53
21: ; preds = %2
br label %22
22: ; preds = %47, %21
%23 = load i8*, i8** %5
store i8* %23, i8** %8
br label %24
24: ; preds = %43, %22
%25 = load i8*, i8** %8
%26 = load i8, i8* %25
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %46
28: ; preds = %24
%29 = load i8*, i8** %7
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = load i8*, i8** %8
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %31, %34
br i1 %35, label %36, label %43
36: ; preds = %28
%37 = load i8*, i8** %7
%38 = load i8*, i8** %6
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = trunc i64 %41 to i32
store i32 %42, i32* %3
br label %53
43: ; preds = %28
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %8
br label %24
46: ; preds = %24
br label %47
47: ; preds = %46
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i32 -1
store i8* %49, i8** %7
%50 = load i8*, i8** %6
%51 = icmp ne i8* %48, %50
br i1 %51, label %22, label %52
52: ; preds = %47
store i32 -1, i32* %3
br label %53
53: ; preds = %52, %36, %20
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
%struct.string = type { i32 }
define i32 @string_find_last_of(%struct.string* %0, i8* nocapture %1) {
%3 = tail call i8* @string_get(%struct.string* %0)
%4 = tail call i32 @strlen(i8* %3)
%5 = tail call i32 @strlen(i8* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %33, label %7
7: ; preds = %2
%8 = add nsw i32 %4, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %3, i64 %9
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 0
br label %13
13: ; preds = %7, %30
%14 = phi i8* [ %31, %30 ], [ %10, %7 ]
br i1 %12, label %30, label %15
15: ; preds = %13
%16 = load i8, i8* %14
br label %20
17: ; preds = %20
%18 = load i8, i8* %24
%19 = icmp eq i8 %18, 0
br i1 %19, label %30, label %20
20: ; preds = %15, %17
%21 = phi i8 [ %11, %15 ], [ %18, %17 ]
%22 = phi i8* [ %1, %15 ], [ %24, %17 ]
%23 = icmp eq i8 %16, %21
%24 = getelementptr inbounds i8, i8* %22, i64 1
br i1 %23, label %25, label %17
25: ; preds = %20
%26 = ptrtoint i8* %14 to i64
%27 = ptrtoint i8* %3 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
br label %33
30: ; preds = %17, %13
%31 = getelementptr inbounds i8, i8* %14, i64 -1
%32 = icmp eq i8* %14, %3
br i1 %32, label %33, label %13
33: ; preds = %30, %25, %2
%34 = phi i32 [ %29, %25 ], [ -1, %2 ], [ -1, %30 ]
ret i32 %34
}