#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 *basename(char *path) {
  char *c;
again:
  if (!(c = strrchr(path, '/')))
    return path;
  if (c[1] == 0) {
    if (c == path)
      return c;
    else {
      *c = 0;
      goto again;
    }
  }
  return c + 1;
}


x86 assembly (clang, -O0):
<basename>:
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,-0x18(%rbp)
cmp    $0x0,%rax
jne    1145 <basename+0x35>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1189 <basename+0x79>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    117d <basename+0x6d>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1171 <basename+0x61>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1189 <basename+0x79>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    111c <basename+0xc>
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):
<basename>:
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     1149 <basename+0x39>
cmpb   $0x0,0x1(%rax)
jne    1142 <basename+0x32>
cmp    %rbx,%rax
je     1149 <basename+0x39>
movb   $0x0,(%rax)
mov    %rbx,%rdi
jmp    1120 <basename+0x10>
add    $0x1,%rax
mov    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @basename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
br label %5
5: ; preds = %23, %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 %11, label %9
9: ; preds = %5
%10 = load i8*, i8** %3
store i8* %10, i8** %2
br label %28
11: ; preds = %5
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = load i8*, i8** %3
%20 = icmp eq i8* %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i8*, i8** %4
store i8* %22, i8** %2
br label %28
23: ; preds = %17
%24 = load i8*, i8** %4
store i8 0, i8* %24
br label %5
25: ; preds = %11
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8* %27, i8** %2
br label %28
28: ; preds = %25, %21, %9
%29 = load i8*, i8** %2
ret i8* %29
}

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