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


x86 assembly (clang, -O0):
<find_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     117b <find_filename+0x6b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1168 <find_filename+0x58>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1183 <find_filename+0x73>
jmp    116d <find_filename+0x5d>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1130 <find_filename+0x20>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_filename>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
js     1139 <find_filename+0x29>
nopl   (%rax)
mov    %eax,%ecx
cmpb   $0x2f,(%rbx,%rcx,1)
je     1133 <find_filename+0x23>
lea    -0x1(%rax),%ecx
test   %eax,%eax
mov    %ecx,%eax
jg     1120 <find_filename+0x10>
jmp    1139 <find_filename+0x29>
add    $0x1,%eax
add    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

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