#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 */
scalar_t__ string_equal(char const *, char const *);
size_t string_list_length(char const **);
ssize_t string_list_rfind(const char **list, const char *string) {
  if (list) {
    ssize_t i = string_list_length(list);
    while (i >= 0) {
      if (string_equal(list[i], string))
        return i;
      else
        --i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<string_list_rfind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1195 <string_list_rfind+0x75>
mov    -0x10(%rbp),%rdi
call   1030 <string_list_length@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jb     1190 <string_list_rfind+0x70>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <string_equal@plt>
cmp    $0x0,%rax
je     117f <string_list_rfind+0x5f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119d <string_list_rfind+0x7d>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1148 <string_list_rfind+0x28>
jmp    1195 <string_list_rfind+0x75>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_list_rfind>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1158 <string_list_rfind+0x38>
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <string_list_length@plt>
mov    %rax,%rbx
add    $0x1,%rbx
nopl   0x0(%rax)
mov    -0x8(%r15,%rbx,8),%rdi
mov    %r14,%rsi
call   1040 <string_equal@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
je     1140 <string_list_rfind+0x20>
jmp    115f <string_list_rfind+0x3f>
mov    $0xffffffffffffffff,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @string_list_rfind(i8** %0, i8* %1) {
%3 = icmp eq i8** %0, null
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = tail call i64 @string_list_length(i8** %0)
br label %6
6: ; preds = %6, %4
%7 = phi i64 [ %5, %4 ], [ %12, %6 ]
%8 = getelementptr inbounds i8*, i8** %0, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i64 @string_equal(i8* %9, i8* %1)
%11 = icmp eq i64 %10, 0
%12 = add i64 %7, -1
br i1 %11, label %6, label %13
13: ; preds = %6, %2
%14 = phi i64 [ -1, %2 ], [ %7, %6 ]
ret i64 %14
}