#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 *tail(char *filename) {
  char *s;
  while (*filename) {
    s = strrchr(filename, '/');
    if (s == NULL)
      break;
    if (s[1])
      return s + 1;
    *s = '\0';
  }
  return filename;
}


x86 assembly (clang, -O0):
<tail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1176 <tail+0x66>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114b <tail+0x3b>
jmp    1176 <tail+0x66>
mov    -0x18(%rbp),%rax
cmpb   $0x0,0x1(%rax)
je     116a <tail+0x5a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    117e <tail+0x6e>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    111c <tail+0xc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tail>:
push   %rbx
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1149 <tail+0x39>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1149 <tail+0x39>
cmpb   $0x0,0x1(%rax)
jne    1142 <tail+0x32>
movb   $0x0,(%rax)
cmpb   $0x0,(%rbx)
jne    1120 <tail+0x10>
jmp    1149 <tail+0x39>
add    $0x1,%rax
mov    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @tail(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 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = call i8* @strrchr(i8* %10, i8 signext 47)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %9
br label %25
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %2
br label %27
23: ; preds = %15
%24 = load i8*, i8** %4
store i8 0, i8* %24
br label %5
25: ; preds = %14, %5
%26 = load i8*, i8** %3
store i8* %26, i8** %2
br label %27
27: ; preds = %25, %20
%28 = load i8*, i8** %2
ret i8* %28
}

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