#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 strlen(char const *);
size_t path_filename_index(const char *path) {
  int i;
  if (strlen(path) == 0)
    return 0;
  for (i = strlen(path) - 1; i >= 0; i--) {
    if (path[i] == '/')
      return i + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<path_filename_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    113b <path_filename_index+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    1195 <path_filename_index+0x85>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     118d <path_filename_index+0x7d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    117a <path_filename_index+0x6a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    1195 <path_filename_index+0x85>
jmp    117f <path_filename_index+0x6f>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    114a <path_filename_index+0x3a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_filename_index>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
je     114b <path_filename_index+0x3b>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
nopl   0x0(%rax)
test   %ecx,%ecx
jle    1149 <path_filename_index+0x39>
lea    -0x1(%rcx),%rdx
cmpb   $0x2f,-0x1(%rbx,%rcx,1)
mov    %rdx,%rcx
jne    1130 <path_filename_index+0x20>
add    $0x1,%rdx
mov    %rdx,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

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