#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 /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
char *get_filename(const char *abs_path) {
  static char filename[4096 + 1];
  size_t len, i;
  len = strlen(abs_path);
  strcpy(filename, abs_path);
  for (i = len - 1; i >= 0; i--) {
    if (filename[i] == '/') {
      return &filename[i + 1];
    }
  }
  return filename;
}


x86 assembly (clang, -O0):
<get_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0x2efc(%rip),%rdi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jb     11a9 <get_filename+0x89>
mov    -0x20(%rbp),%rcx
lea    0x2ed5(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1193 <get_filename+0x73>
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
lea    0x2eb9(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11b4 <get_filename+0x94>
jmp    1198 <get_filename+0x78>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1155 <get_filename+0x35>
lea    0x2e90(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rax,%r14
lea    0x2f09(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    (%r14,%r15,1),%rax
add    $0x1,%rax
nopw   0x0(%rax,%rax,1)
cmpb   $0x2f,-0x2(%rax)
lea    -0x1(%rax),%rax
jne    1150 <get_filename+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@get_filename.filename = internal global [4097 x i8] zeroinitializer
define i8* @get_filename(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call i32 @strcpy(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @get_filename.filename, i64 0, i64 0), i8* %0)
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ %2, %1 ], [ %6, %4 ]
%6 = add i64 %5, -1
%7 = getelementptr inbounds [4097 x i8], [4097 x i8]* @get_filename.filename, i64 0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = getelementptr inbounds [4097 x i8], [4097 x i8]* @get_filename.filename, i64 0, i64 %5
ret i8* %11
}