#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 */
char *strrchr(char *, char);
char *xbasename(char *path) {
  char *cp;
  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)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     1151 <xbasename+0x41>
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    1161 <xbasename+0x51>
jmp    116d <xbasename+0x5d>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    111c <xbasename+0xc>
cmpq   $0x0,-0x18(%rbp)
jne    1185 <xbasename+0x75>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1191 <xbasename+0x81>
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
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1144 <xbasename+0x34>
cmpb   $0x0,0x1(%rax)
jne    113d <xbasename+0x2d>
movb   $0x0,(%rax)
mov    %rbx,%rdi
jmp    1120 <xbasename+0x10>
add    $0x1,%rax
mov    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

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