#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 */
scalar_t__ malloc(size_t);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char const *);
char *strrchr(char const *, char);
char *FN_file_name(const char *path_name) {
  size_t len;
  char *str;
  char *ret;
  if (!path_name || strlen(path_name) == 0)
    return 0;
  str = strrchr(path_name, '/');
  if (!str)
    return 0;
  str += 1;
  len = strlen(str);
  ret = (char *)malloc(len + 1);
  if (!ret)
    return 0;
  strcpy(ret, str);
  return ret;
}


x86 assembly (clang, -O0):
<FN_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116a <FN_file_name+0x2a>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    1177 <FN_file_name+0x37>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <FN_file_name+0xb8>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a1 <FN_file_name+0x61>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <FN_file_name+0xb8>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e3 <FN_file_name+0xa3>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <FN_file_name+0xb8>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FN_file_name>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     118a <FN_file_name+0x4a>
cmpb   $0x0,(%rdi)
je     118a <FN_file_name+0x4a>
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     118a <FN_file_name+0x4a>
mov    %rax,%r14
add    $0x1,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     118a <FN_file_name+0x4a>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    118c <FN_file_name+0x4c>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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