#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 */
scalar_t__ ch_is_slash(char const);
const char *find_last_slash(const char *__attribute__((nonnull)) const path,
                            const char *__attribute__((nonnull)) const end) {
  const char *iter = end - 1;
  const char *const rev_end = path - 1;
  for (; iter != rev_end; --iter) {
    if (ch_is_slash(*iter)) {
      return iter;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_last_slash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     117f <find_last_slash+0x6f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <ch_is_slash@plt>
cmp    $0x0,%rax
je     1169 <find_last_slash+0x59>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1187 <find_last_slash+0x77>
jmp    116e <find_last_slash+0x5e>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1138 <find_last_slash+0x28>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_last_slash>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
nopw   0x0(%rax,%rax,1)
cmp    %r14,%rbx
je     1139 <find_last_slash+0x29>
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1030 <ch_is_slash@plt>
test   %rax,%rax
je     1120 <find_last_slash+0x10>
jmp    113b <find_last_slash+0x2b>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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