#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 */
int strlen(char *);
char *filename(char *name) {
  long i;
  for (i = strlen(name) - 1; (name[i] != '/') && (i > 0); i--)
    ;
  if (i == 0)
    return name;
  else
    return &name[i + 1];
}


x86 assembly (clang, -O0):
<filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x19(%rbp)
je     1153 <filename+0x43>
cmpq   $0x0,-0x18(%rbp)
setg   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1163 <filename+0x53>
jmp    1179 <filename+0x69>
jmp    1168 <filename+0x58>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    112e <filename+0x1e>
cmpq   $0x0,-0x18(%rbp)
jne    1191 <filename+0x81>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a4 <filename+0x94>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filename>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
add    $0xffffffff,%eax
movslq %eax,%rcx
nop
lea    -0x1(%rcx),%rax
cmpb   $0x2f,(%rbx,%rcx,1)
je     1132 <filename+0x22>
test   %rcx,%rcx
mov    %rax,%rcx
jg     1120 <filename+0x10>
lea    0x2(%rax),%rcx
xor    %edx,%edx
cmp    $0xffffffffffffffff,%rax
cmovne %rcx,%rdx
add    %rdx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
%7 = sub nsw i32 %6, 1
%8 = sext i32 %7 to i64
store i64 %8, i64* %4
br label %9
9: ; preds = %22, %1
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 47
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = load i64, i64* %4
%18 = icmp sgt i64 %17, 0
br label %19
19: ; preds = %16, %9
%20 = phi i1 [ false, %9 ], [ %18, %16 ]
br i1 %20, label %21, label %25
21: ; preds = %19
br label %22
22: ; preds = %21
%23 = load i64, i64* %4
%24 = add nsw i64 %23, -1
store i64 %24, i64* %4
br label %9
25: ; preds = %19
%26 = load i64, i64* %4
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i8*, i8** %3
store i8* %29, i8** %2
br label %35
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = load i64, i64* %4
%33 = add nsw i64 %32, 1
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8* %34, i8** %2
br label %35
35: ; preds = %30, %28
%36 = load i8*, i8** %2
ret i8* %36
}

LLVM IR (-O2):
define i8* @filename(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -1
%4 = sext i32 %3 to i64
br label %5
5: ; preds = %5, %1
%6 = phi i64 [ %4, %1 ], [ %12, %5 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 47
%10 = icmp sgt i64 %6, 0
%11 = select i1 %9, i1 %10, i1 false
%12 = add nsw i64 %6, -1
br i1 %11, label %5, label %13
13: ; preds = %5
%14 = icmp eq i64 %6, 0
%15 = add nsw i64 %6, 1
%16 = select i1 %14, i64 0, i64 %15
%17 = getelementptr i8, i8* %0, i64 %16
ret i8* %17
}