#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 *path) {
  int len = strlen(path);
  char *p = path + len - 1;
  while (p >= path) {
    if (*p == '/')
      return (p + 1);
    p--;
  }
  return path;
}


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>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     117b <filename+0x6b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    116a <filename+0x5a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1183 <filename+0x73>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    113b <filename+0x2b>
mov    -0x10(%rbp),%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>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %rbx,%rax
jb     1148 <filename+0x38>
lea    -0x1(%rax),%rcx
cmpb   $0x2f,(%rax)
mov    %rcx,%rax
jne    1130 <filename+0x20>
add    $0x2,%rcx
mov    %rcx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

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