#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*/ is_seperator(char const);
int strlen(char const *);
const char *file_base(const char *path) {
  const char *src = path + strlen(path) - 1;
  if (src >= path) {
    while (src != path && !is_seperator(*(src - 1)))
      src--;
    return src;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<file_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     11bd <file_base+0x9d>
jmp    1164 <file_base+0x44>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x21(%rbp)
je     118f <file_base+0x6f>
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1030 <is_seperator@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    119f <file_base+0x7f>
jmp    11b0 <file_base+0x90>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1164 <file_base+0x44>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c5 <file_base+0xa5>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_base>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
movslq %eax,%rbx
lea    (%r14,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
cmp    %r14,%rax
jae    1150 <file_base+0x30>
xor    %r14d,%r14d
jmp    116c <file_base+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x1,%rbx
je     116c <file_base+0x4c>
movsbl -0x2(%r14,%rbx,1),%edi
call   1030 <is_seperator@plt>
add    $0xffffffffffffffff,%rbx
test   %eax,%eax
je     1150 <file_base+0x30>
add    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @file_base(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %5, i64 %8
%10 = getelementptr inbounds i8, i8* %9, i64 -1
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = load i8*, i8** %3
%13 = icmp uge i8* %11, %12
br i1 %13, label %14, label %33
14: ; preds = %1
br label %15
15: ; preds = %28, %14
%16 = load i8*, i8** %4
%17 = load i8*, i8** %3
%18 = icmp ne i8* %16, %17
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 -1
%22 = load i8, i8* %21
%23 = call i32 @is_seperator(i8 signext %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br label %26
26: ; preds = %19, %15
%27 = phi i1 [ false, %15 ], [ %25, %19 ]
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %4
br label %15
31: ; preds = %26
%32 = load i8*, i8** %4
store i8* %32, i8** %2
br label %34
33: ; preds = %1
store i8* null, i8** %2
br label %34
34: ; preds = %33, %31
%35 = load i8*, i8** %2
ret i8* %35
}

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