#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 *strrchr(char const *, char);
size_t dirpath_len(const char *str) {
  const char *lastslash = strrchr(str, '/');
  const char *lastbslash = strrchr(str, '\\');
  const char *last_path_sep = (lastslash < lastbslash) ? lastbslash : lastslash;
  ;
  if (last_path_sep == NULL)
    return 0;
  last_path_sep++;
  return (size_t)(last_path_sep - str);
}


x86 assembly (clang, -O0):
<dirpath_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    115b <dirpath_len+0x4b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1163 <dirpath_len+0x53>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1183 <dirpath_len+0x73>
movq   $0x0,-0x8(%rbp)
jmp    119e <dirpath_len+0x8e>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirpath_len>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
cmp    %rax,%r14
cmovae %r14,%rax
mov    %rax,%rcx
sub    %rbx,%rcx
add    $0x1,%rcx
test   %rax,%rax
cmovne %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @dirpath_len(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %4
%9 = load i8*, i8** %3
%10 = call i8* @strrchr(i8* %9, i8 signext 92)
store i8* %10, i8** %5
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = icmp ult i8* %11, %12
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = load i8*, i8** %5
br label %18
16: ; preds = %1
%17 = load i8*, i8** %4
br label %18
18: ; preds = %16, %14
%19 = phi i8* [ %15, %14 ], [ %17, %16 ]
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %18
store i64 0, i64* %2
br label %31
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = load i8*, i8** %3
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
store i64 %30, i64* %2
br label %31
31: ; preds = %23, %22
%32 = load i64, i64* %2
ret i64 %32
}

LLVM IR (-O2):
define i64 @dirpath_len(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 92)
%4 = icmp ult i8* %2, %3
%5 = select i1 %4, i8* %3, i8* %2
%6 = icmp eq i8* %5, null
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = ptrtoint i8* %7 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = select i1 %6, i64 0, i64 %10
ret i64 %11
}