#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 mstring_get_length(char *);
int mstring_rfind(char *in, char find) {
  int size = mstring_get_length(in);
  int curr = size;
  for (; curr != 0; curr--) {
    char c = in[curr];
    if (c == find) {
      return curr;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<mstring_rfind>:
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 <mstring_get_length@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     117a <mstring_rfind+0x6a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    1167 <mstring_rfind+0x57>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <mstring_rfind+0x71>
jmp    116c <mstring_rfind+0x5c>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1134 <mstring_rfind+0x24>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mstring_rfind>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <mstring_get_length@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     1142 <mstring_rfind+0x32>
movslq %ecx,%rdx
add    %rdx,%rbx
xchg   %ax,%ax
cmp    %bpl,(%rbx)
je     1140 <mstring_rfind+0x30>
add    $0xffffffffffffffff,%rbx
add    $0xffffffff,%ecx
jne    1130 <mstring_rfind+0x20>
jmp    1142 <mstring_rfind+0x32>
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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