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


x86 assembly (clang, -O0):
<extract_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1192 <extract_filename+0x82>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     117a <extract_filename+0x6a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     117a <extract_filename+0x6a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    117f <extract_filename+0x6f>
jmp    1192 <extract_filename+0x82>
jmp    1184 <extract_filename+0x74>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1131 <extract_filename+0x21>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_filename>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%edx
xor    %ecx,%ecx
test   %eax,%eax
cmovs  %eax,%ecx
add    $0xffffffff,%ecx
movabs $0x200000000801,%rsi
nop
test   %edx,%edx
jle    114f <extract_filename+0x3f>
add    $0xffffffffffffffff,%rdx
mov    %edx,%eax
movzbl (%rbx,%rax,1),%eax
add    $0xd1,%al
cmp    $0x2d,%al
ja     1130 <extract_filename+0x20>
movzbl %al,%eax
bt     %rax,%rsi
jae    1130 <extract_filename+0x20>
mov    %edx,%ecx
movslq %ecx,%rax
add    %rbx,%rax
add    $0x1,%rax
pop    %rbx
ret

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

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