#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*/ file_IsDirectorySeparator(char const);
int strlen(char const *);
int file_LatestSlash(const char *path) {
  int i = strlen(path) - 1;
  while (!file_IsDirectorySeparator(path[i]) && i > 0) {
    i--;
  }
  if (i <= 0) {
    i = -1;
  }
  return i;
}


x86 assembly (clang, -O0):
<file_LatestSlash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <file_IsDirectorySeparator@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
jne    1166 <file_LatestSlash+0x46>
cmpl   $0x0,-0xc(%rbp)
setg   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1176 <file_LatestSlash+0x56>
jmp    1184 <file_LatestSlash+0x64>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <file_LatestSlash+0x1b>
cmpl   $0x0,-0xc(%rbp)
jg     1195 <file_LatestSlash+0x75>
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_LatestSlash>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
movslq %eax,%rbx
lea    -0x1(%rbx),%r15
movsbl -0x1(%r14,%rbx,1),%edi
call   1040 <file_IsDirectorySeparator@plt>
test   %eax,%eax
jne    114c <file_LatestSlash+0x2c>
cmp    $0x1,%rbx
mov    %r15,%rbx
jg     1130 <file_LatestSlash+0x10>
lea    0x1(%r15),%eax
cmp    $0x2,%eax
mov    $0xffffffff,%eax
cmovge %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @file_LatestSlash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = sub nsw i32 %5, 1
store i32 %6, i32* %3
br label %7
7: ; preds = %20, %1
%8 = load i8*, i8** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = call i32 @file_IsDirectorySeparator(i8 signext %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %7
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 0
br label %18
18: ; preds = %15, %7
%19 = phi i1 [ false, %7 ], [ %17, %15 ]
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = load i32, i32* %3
%22 = add nsw i32 %21, -1
store i32 %22, i32* %3
br label %7
23: ; preds = %18
%24 = load i32, i32* %3
%25 = icmp sle i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 -1, i32* %3
br label %27
27: ; preds = %26, %23
%28 = load i32, i32* %3
ret i32 %28
}

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