#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*/ assert(char *);
int strlen(char *);
char *filenameFromPath(char *path) {
  assert(path);
  char *endPtr = path + (strlen(path) - 1);
  char *carrot = endPtr;
  do {
    carrot--;
  } while (carrot > path && *carrot != '\\');
  if (*carrot == '\\')
    return carrot + 1;
  else
    return carrot;
}


x86 assembly (clang, -O0):
<filenameFromPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x29(%rbp)
jbe    1190 <filenameFromPath+0x70>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1161 <filenameFromPath+0x41>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11bc <filenameFromPath+0x9c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11c4 <filenameFromPath+0xa4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filenameFromPath>:
push   %rbx
mov    %rdi,%rbx
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rcx
add    $0xfffffffffffffffe,%rcx
nopl   0x0(%rax,%rax,1)
movzbl (%rcx),%edx
cmp    %rbx,%rcx
jbe    115a <filenameFromPath+0x3a>
add    $0xffffffffffffffff,%rcx
cmp    $0x5c,%dl
jne    1140 <filenameFromPath+0x20>
add    $0x2,%rcx
mov    %rcx,%rax
pop    %rbx
ret
lea    0x1(%rcx),%rax
cmp    $0x5c,%dl
cmovne %rcx,%rax
pop    %rbx
ret

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

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