#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 */
char *fcitx_utils_backward_search(char const *, int, char const *, int,
                                  int /*<<< orphan*/);
int strlen(char const *);
char *strrchr(char const *, char const);
__attribute__((visibility("default"))) char *
fcitx_utils_strrstr(const char *haystack, const char *needle) {
  if (needle[0] == '\0') {
    return NULL;
  }
  if (needle[1] == '\0') {
    return strrchr(haystack, needle[0]);
  }
  int l = strlen(haystack);
  int ol = strlen(needle);
  return fcitx_utils_backward_search(haystack, l, needle, ol, 0);
}


x86 assembly (clang, -O0):
<fcitx_utils_strrstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    115d <fcitx_utils_strrstr+0x2d>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <fcitx_utils_strrstr+0x89>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1187 <fcitx_utils_strrstr+0x57>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1050 <strrchr@plt>
mov    %rax,-0x8(%rbp)
jmp    11b9 <fcitx_utils_strrstr+0x89>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
xor    %r8d,%r8d
call   1030 <fcitx_utils_backward_search@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcitx_utils_strrstr>:
push   %rbp
push   %r14
push   %rbx
mov    (%rsi),%al
test   %al,%al
je     116e <fcitx_utils_strrstr+0x3e>
mov    %rsi,%rbx
mov    %rdi,%r14
cmpb   $0x0,0x1(%rsi)
je     1175 <fcitx_utils_strrstr+0x45>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fcitx_utils_backward_search@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
movsbl %al,%esi
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <strrchr@plt>

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

LLVM IR (-O2):
define i8* @fcitx_utils_strrstr(i8* %0, i8* %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %1, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext %3)
br label %15
11: ; preds = %5
%12 = tail call i32 @strlen(i8* %0)
%13 = tail call i32 @strlen(i8* %1)
%14 = tail call i8* @fcitx_utils_backward_search(i8* %0, i32 %12, i8* %1, i32 %13, i32 0)
br label %15
15: ; preds = %2, %11, %9
%16 = phi i8* [ %10, %9 ], [ %14, %11 ], [ null, %2 ]
ret i8* %16
}