#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 /*<<< orphan*/ *strchr(char const *, char const);
int strlen(char const *);
int find_last_path_separator(const char *path) {
  const char *PATH_SEPARATORS = "/";
  const char *p;
  p = path + strlen(path) - 1;
  while (p >= path) {
    if (strchr(PATH_SEPARATORS, *p) != NULL)
      return (int)(p - path);
    p--;
  }
  return -1;
}


x86 assembly (clang, -O0):
<find_last_path_separator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xecd(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     11a8 <find_last_path_separator+0x88>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1197 <find_last_path_separator+0x77>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
jmp    11af <find_last_path_separator+0x8f>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    115c <find_last_path_separator+0x3c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_last_path_separator>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebp
cltq
lea    (%rax,%r15,1),%rbx
add    $0xffffffffffffffff,%rbx
lea    0xebe(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %r15,%rbx
jb     116e <find_last_path_separator+0x4e>
movsbl (%rbx),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
je     1150 <find_last_path_separator+0x30>
jmp    1173 <find_last_path_separator+0x53>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @find_last_path_separator(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 -1
store i8* %11, i8** %5
br label %12
12: ; preds = %29, %1
%13 = load i8*, i8** %5
%14 = load i8*, i8** %3
%15 = icmp uge i8* %13, %14
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = call i32* @strchr(i8* %17, i8 signext %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %29
22: ; preds = %16
%23 = load i8*, i8** %5
%24 = load i8*, i8** %3
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
store i32 %28, i32* %2
br label %33
29: ; preds = %16
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %5
br label %12
32: ; preds = %12
store i32 -1, i32* %2
br label %33
33: ; preds = %32, %22
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @find_last_path_separator(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
br label %5
5: ; preds = %9, %1
%6 = phi i8* [ %4, %1 ], [ %7, %9 ]
%7 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = icmp ult i8* %7, %0
br i1 %8, label %18, label %9
9: ; preds = %5
%10 = load i8, i8* %7
%11 = tail call i32* @strchr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %5, label %13
13: ; preds = %9
%14 = ptrtoint i8* %7 to i64
%15 = ptrtoint i8* %0 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
br label %18
18: ; preds = %5, %13
%19 = phi i32 [ %17, %13 ], [ -1, %5 ]
ret i32 %19
}