char *nameonly(char *s) {
  static char tmp[256 + 1];
  int i = 0;
  while (*s != '/' && *s != '\0') {
    tmp[i++] = *s++;
  }
  tmp[i] = '\0';
  return &tmp[0];
}


x86 assembly (clang, -O0):
<nameonly>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0xd(%rbp)
je     1134 <nameonly+0x34>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1144 <nameonly+0x44>
jmp    1172 <nameonly+0x72>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%dl
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
movslq %eax,%rcx
lea    0x2ec6(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    110f <nameonly+0xf>
movslq -0xc(%rbp),%rcx
lea    0x2eb3(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ea8(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<nameonly>:
xor    %ecx,%ecx
lea    0x2f27(%rip),%rax
nopl   0x0(%rax)
movzbl (%rdi,%rcx,1),%edx
test   %dl,%dl
je     1126 <nameonly+0x26>
cmp    $0x2f,%dl
je     1126 <nameonly+0x26>
mov    %dl,(%rcx,%rax,1)
add    $0x1,%rcx
jmp    1110 <nameonly+0x10>
mov    %ecx,%ecx
movb   $0x0,(%rcx,%rax,1)
ret

LLVM IR (-O0):
@nameonly.tmp = internal global [257 x i8] zeroinitializer
define i8* @nameonly(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %16, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 47
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br label %14
14: ; preds = %9, %4
%15 = phi i1 [ false, %4 ], [ %13, %9 ]
br i1 %15, label %16, label %24
16: ; preds = %14
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %2
%19 = load i8, i8* %17
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds [257 x i8], [257 x i8]* @nameonly.tmp, i64 0, i64 %22
store i8 %19, i8* %23
br label %4
24: ; preds = %14
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [257 x i8], [257 x i8]* @nameonly.tmp, i64 0, i64 %26
store i8 0, i8* %27
ret i8* getelementptr inbounds ([257 x i8], [257 x i8]* @nameonly.tmp, i64 0, i64 0)
}

LLVM IR (-O2):
@nameonly.tmp = internal global [257 x i8] zeroinitializer
define i8* @nameonly(i8* nocapture %0) {
br label %2
2: ; preds = %6, %1
%3 = phi i64 [ %8, %6 ], [ 0, %1 ]
%4 = phi i8* [ %7, %6 ], [ %0, %1 ]
%5 = load i8, i8* %4
switch i8 %5, label %6 [
i8 47, label %10
i8 0, label %10
]
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = add nuw i64 %3, 1
%9 = getelementptr inbounds [257 x i8], [257 x i8]* @nameonly.tmp, i64 0, i64 %3
store i8 %5, i8* %9
br label %2
10: ; preds = %2, %2
%11 = and i64 %3, 4294967295
%12 = getelementptr inbounds [257 x i8], [257 x i8]* @nameonly.tmp, i64 0, i64 %11
store i8 0, i8* %12
ret i8* getelementptr inbounds ([257 x i8], [257 x i8]* @nameonly.tmp, i64 0, i64 0)
}