#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*/ fail(char *);
char *strrchr(char *, char);
char *xbasename(char *path) {
  char *cp;
  if (!path || !path[0])
    fail("Null pointer or empty string passed to xbasename()");
  while ((cp = strrchr(path, '/')) && cp[1] == '\0')
    *cp = '\0';
  if (!cp)
    return path;
  return cp + 1;
}


x86 assembly (clang, -O0):
<xbasename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1144 <xbasename+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1150 <xbasename+0x30>
lea    0xeb5(%rip),%rdi
call   1030 <fail@plt>
jmp    1155 <xbasename+0x35>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     118a <xbasename+0x6a>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119a <xbasename+0x7a>
jmp    11a6 <xbasename+0x86>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1155 <xbasename+0x35>
cmpq   $0x0,-0x18(%rbp)
jne    11be <xbasename+0x9e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ca <xbasename+0xaa>
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):
<xbasename>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     112e <xbasename+0xe>
cmpb   $0x0,(%rbx)
jne    1149 <xbasename+0x29>
lea    0xecb(%rip),%rdi
call   1030 <fail@plt>
jmp    1149 <xbasename+0x29>
nopl   0x0(%rax)
cmpb   $0x0,0x1(%rax)
jne    115d <xbasename+0x3d>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
jne    1140 <xbasename+0x20>
jmp    1164 <xbasename+0x44>
add    $0x1,%rax
mov    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Null pointer or empty string passed to xbasename()\00"
define i8* @xbasename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %7, %1
%13 = call i32 @fail(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %7
br label %15
15: ; preds = %27, %14
%16 = load i8*, i8** %3
%17 = call i8* @strrchr(i8* %16, i8 signext 47)
store i8* %17, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br label %25
25: ; preds = %19, %15
%26 = phi i1 [ false, %15 ], [ %24, %19 ]
br i1 %26, label %27, label %29
27: ; preds = %25
%28 = load i8*, i8** %4
store i8 0, i8* %28
br label %15
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = icmp ne i8* %30, null
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = load i8*, i8** %3
store i8* %33, i8** %2
br label %37
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 1
store i8* %36, i8** %2
br label %37
37: ; preds = %34, %32
%38 = load i8*, i8** %2
ret i8* %38
}

LLVM IR (-O2):
@.str = [51 x i8] c"Null pointer or empty string passed to xbasename()\00"
define i8* @xbasename(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3, %1
%7 = tail call i32 @fail(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
%9 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%10 = icmp eq i8* %9, null
br i1 %10, label %21, label %11
11: ; preds = %8, %16
%12 = phi i8* [ %17, %16 ], [ %9, %8 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
store i8 0, i8* %12
%17 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%18 = icmp eq i8* %17, null
br i1 %18, label %21, label %11
19: ; preds = %11
%20 = getelementptr inbounds i8, i8* %12, i64 1
br label %21
21: ; preds = %16, %19, %8
%22 = phi i8* [ %0, %8 ], [ %20, %19 ], [ %0, %16 ]
ret i8* %22
}