#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 */
scalar_t__ strrchr(char const *, char);
const char *get_filename_no_directory(const char *filename) {
  char *p = NULL;
  if (!filename)
    return NULL;
  p = (char *)strrchr(filename, '/');
  if (!p)
    return filename;
  if (p[1] == '\0')
    return NULL;
  return p + 1;
}


x86 assembly (clang, -O0):
<get_filename_no_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113c <get_filename_no_directory+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    1190 <get_filename_no_directory+0x80>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1166 <get_filename_no_directory+0x56>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1190 <get_filename_no_directory+0x80>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1184 <get_filename_no_directory+0x74>
movq   $0x0,-0x8(%rbp)
jmp    1190 <get_filename_no_directory+0x80>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename_no_directory>:
push   %rbx
test   %rdi,%rdi
je     113b <get_filename_no_directory+0x2b>
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     113d <get_filename_no_directory+0x2d>
mov    %rax,%rcx
add    $0x1,%rcx
xor    %ebx,%ebx
cmpb   $0x0,0x1(%rax)
cmovne %rcx,%rbx
jmp    113d <get_filename_no_directory+0x2d>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @get_filename_no_directory(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i8* null, i8** %2
br label %26
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i64 @strrchr(i8* %9, i8 signext 47)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = load i8*, i8** %3
store i8* %15, i8** %2
br label %26
16: ; preds = %8
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16
store i8* null, i8** %2
br label %26
23: ; preds = %16
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %2
br label %26
26: ; preds = %23, %22, %14, %7
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
define i8* @get_filename_no_directory(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = tail call i64 @strrchr(i8* %0, i8 signext 47)
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = inttoptr i64 %4 to i8*
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
%11 = select i1 %10, i8* null, i8* %8
br label %12
12: ; preds = %6, %3, %1
%13 = phi i8* [ null, %1 ], [ %0, %3 ], [ %11, %6 ]
ret i8* %13
}