char *basename(name)
register char *name;
{
  static char buf[1024];
  register char *bp;
  for (bp = buf; *bp = *name++;)
    ++bp;
  while (--bp >= buf && (*bp == '/'))
    *bp = '\0';
  while (bp >= buf && (*bp != '/'))
    --bp;
  return (++bp);
}


x86 assembly (clang, -O0):
<basename>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
lea    0x2f21(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    %al,(%rcx)
cmp    $0x0,%al
je     1143 <basename+0x43>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1113 <basename+0x13>
jmp    1148 <basename+0x48>
mov    -0x10(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
lea    0x2ed3(%rip),%rdx
cmp    %rdx,%rcx
mov    %al,-0x11(%rbp)
jb     1179 <basename+0x79>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1189 <basename+0x89>
jmp    1195 <basename+0x95>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1148 <basename+0x48>
jmp    119a <basename+0x9a>
xor    %eax,%eax
lea    0x2e8d(%rip),%rcx
cmp    %rcx,-0x10(%rbp)
mov    %al,-0x12(%rbp)
jb     11c0 <basename+0xc0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    11d0 <basename+0xd0>
jmp    11e1 <basename+0xe1>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    119a <basename+0x9a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
pop    %rbp
ret

x86 assembly (clang, -O2):
<basename>:
mov    (%rdi),%dl
mov    %dl,0x2f28(%rip)
lea    0x2f21(%rip),%rcx
mov    %rcx,%rax
test   %dl,%dl
je     1142 <basename+0x42>
add    $0x1,%rdi
lea    0x2f0f(%rip),%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rdi),%edx
mov    %dl,0x1(%rax)
add    $0x1,%rax
add    $0x1,%rdi
test   %dl,%dl
jne    1130 <basename+0x30>
add    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jb     1171 <basename+0x71>
lea    0x2ede(%rip),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x2f,(%rax)
jne    1171 <basename+0x71>
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jae    1160 <basename+0x60>
lea    0x2eb8(%rip),%rcx
cmp    %rcx,%rax
jb     118e <basename+0x8e>
nopl   (%rax)
cmpb   $0x2f,(%rax)
je     118e <basename+0x8e>
add    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jae    1180 <basename+0x80>
add    $0x1,%rax
ret

LLVM IR (-O0):
@basename.buf = internal global [1024 x i8] zeroinitializer
define i8* @basename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @basename.buf, i64 0, i64 0), i8** %3
br label %4
4: ; preds = %10, %1
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i32 1
store i8* %6, i8** %2
%7 = load i8, i8* %5
%8 = load i8*, i8** %3
store i8 %7, i8* %8
%9 = icmp ne i8 %7, 0
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %3
br label %4
13: ; preds = %4
br label %14
14: ; preds = %25, %13
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 -1
store i8* %16, i8** %3
%17 = icmp uge i8* %16, getelementptr inbounds ([1024 x i8], [1024 x i8]* @basename.buf, i64 0, i64 0)
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br label %23
23: ; preds = %18, %14
%24 = phi i1 [ false, %14 ], [ %22, %18 ]
br i1 %24, label %25, label %27
25: ; preds = %23
%26 = load i8*, i8** %3
store i8 0, i8* %26
br label %14
27: ; preds = %23
br label %28
28: ; preds = %38, %27
%29 = load i8*, i8** %3
%30 = icmp uge i8* %29, getelementptr inbounds ([1024 x i8], [1024 x i8]* @basename.buf, i64 0, i64 0)
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i8*, i8** %3
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 47
br label %36
36: ; preds = %31, %28
%37 = phi i1 [ false, %28 ], [ %35, %31 ]
br i1 %37, label %38, label %41
38: ; preds = %36
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i32 -1
store i8* %40, i8** %3
br label %28
41: ; preds = %36
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@basename.buf = internal global [1024 x i8] zeroinitializer
define i8* @basename(i8* nocapture %0) {
%2 = load i8, i8* %0
store i8 %2, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @basename.buf, i64 0, i64 0)
%3 = icmp eq i8 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %8, %1
%5 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @basename.buf, i64 0, i64 0), %1 ], [ %12, %8 ]
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = icmp ult i8* %6, getelementptr inbounds ([1024 x i8], [1024 x i8]* @basename.buf, i64 0, i64 0)
br i1 %7, label %22, label %15
8: ; preds = %1, %8
%9 = phi i8* [ %12, %8 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @basename.buf, i64 0, i64 0), %1 ]
%10 = phi i8* [ %11, %8 ], [ %0, %1 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = load i8, i8* %11
store i8 %13, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %4, label %8
15: ; preds = %4, %19
%16 = phi i8* [ %20, %19 ], [ %6, %4 ]
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 47
br i1 %18, label %19, label %22
19: ; preds = %15
store i8 0, i8* %16
%20 = getelementptr inbounds i8, i8* %16, i64 -1
%21 = icmp ult i8* %20, getelementptr inbounds ([1024 x i8], [1024 x i8]* @basename.buf, i64 0, i64 0)
br i1 %21, label %22, label %15
22: ; preds = %15, %19, %4
%23 = phi i8* [ %6, %4 ], [ %20, %19 ], [ %16, %15 ]
%24 = icmp ult i8* %23, getelementptr inbounds ([1024 x i8], [1024 x i8]* @basename.buf, i64 0, i64 0)
br i1 %24, label %32, label %25
25: ; preds = %22, %29
%26 = phi i8* [ %30, %29 ], [ %23, %22 ]
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 47
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = getelementptr inbounds i8, i8* %26, i64 -1
%31 = icmp ult i8* %30, getelementptr inbounds ([1024 x i8], [1024 x i8]* @basename.buf, i64 0, i64 0)
br i1 %31, label %32, label %25
32: ; preds = %25, %29, %22
%33 = phi i8* [ %23, %22 ], [ %30, %29 ], [ %26, %25 ]
%34 = getelementptr inbounds i8, i8* %33, i64 1
ret i8* %34
}