char *executable_name(char *argv0) {
  char *p;
  for (p = argv0; *p; p++)
    ;
  for (; p >= argv0; p--) {
    if (*p == '/')
      return (p + 1);
  }
  return argv0;
}


x86 assembly (clang, -O0):
<executable_name>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1133 <executable_name+0x33>
jmp    1122 <executable_name+0x22>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1110 <executable_name+0x10>
jmp    1138 <executable_name+0x38>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     117d <executable_name+0x7d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1167 <executable_name+0x67>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1185 <executable_name+0x85>
jmp    116c <executable_name+0x6c>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <executable_name+0x38>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<executable_name>:
mov    %rdi,%rax
lea    -0x1(%rdi),%rcx
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%rcx)
lea    0x1(%rcx),%rcx
jne    1110 <executable_name+0x10>
cmp    %rax,%rcx
jb     1148 <executable_name+0x48>
add    $0xffffffffffffffff,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %rax,%rcx
jb     1148 <executable_name+0x48>
lea    -0x1(%rcx),%rdx
cmpb   $0x2f,(%rcx)
mov    %rdx,%rcx
jne    1130 <executable_name+0x30>
add    $0x2,%rdx
mov    %rdx,%rax
ret

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

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