#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 */
int strlen(char *);
int find_last_index_of_char_in_string(char *s, char c) {
  int i = strlen(s) - 1;
  while (i > -1) {
    if (c == s[i])
      return i;
    i--;
  }
  return i;
}


x86 assembly (clang, -O0):
<find_last_index_of_char_in_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jle    116c <find_last_index_of_char_in_string+0x5c>
movsbl -0x11(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    115e <find_last_index_of_char_in_string+0x4e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1172 <find_last_index_of_char_in_string+0x62>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1131 <find_last_index_of_char_in_string+0x21>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_last_index_of_char_in_string>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    %eax,%edx
xor    %eax,%eax
test   %ecx,%ecx
cmovs  %ecx,%eax
add    $0xffffffff,%eax
nopl   0x0(%rax,%rax,1)
test   %edx,%edx
jle    1142 <find_last_index_of_char_in_string+0x32>
add    $0xffffffffffffffff,%rdx
mov    %edx,%ecx
cmp    %bpl,(%rbx,%rcx,1)
jne    1130 <find_last_index_of_char_in_string+0x20>
mov    %edx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @find_last_index_of_char_in_string(i8* %0, i8 signext %1) {
%3 = alloca i32
%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)
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %6
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = load i8*, i8** %4
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %15, %21
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = load i32, i32* %6
store i32 %24, i32* %3
br label %30
25: ; preds = %13
%26 = load i32, i32* %6
%27 = add nsw i32 %26, -1
store i32 %27, i32* %6
br label %10
28: ; preds = %10
%29 = load i32, i32* %6
store i32 %29, i32* %3
br label %30
30: ; preds = %28, %23
%31 = load i32, i32* %3
ret i32 %31
}

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