#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*/ enough_mem(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char const *);
char *strdup(char const *);
int strlen(char const *);
char *strrchr(char const *, char);
char *extract_file(const char *pathfile) {
  const char *last_slash = strrchr(pathfile, '/');
  char *file;
  size_t size;
  if (!last_slash) {
    return strdup(pathfile);
  }
  size = strlen(pathfile) - (last_slash - pathfile + 1) + 1;
  file = (char *)malloc(size);
  enough_mem(file);
  snprintf(file, size, "%s", last_slash + 1);
  return file;
}


x86 assembly (clang, -O0):
<extract_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119b <extract_file+0x3b>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11fa <extract_file+0x9a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
add    $0x1,%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <enough_mem@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
lea    0xe13(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_file>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11bf <extract_file+0x5f>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
sub    %r14,%rbx
add    %rax,%rbx
mov    %rbx,%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1060 <enough_mem@plt>
add    $0x1,%r14
lea    0xe58(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rcx
call   1040 <snprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <strdup@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i8* @extract_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %2
br label %37
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = load i8*, i8** %4
%19 = load i8*, i8** %3
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = add nsw i64 %22, 1
%24 = sub nsw i64 %17, %23
%25 = add nsw i64 %24, 1
store i64 %25, i64* %6
%26 = load i64, i64* %6
%27 = call i64 @malloc(i64 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %5
%29 = load i8*, i8** %5
%30 = call i32 @enough_mem(i8* %29)
%31 = load i8*, i8** %5
%32 = load i64, i64* %6
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = call i32 @snprintf(i8* %31, i64 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %5
store i8* %36, i8** %2
br label %37
37: ; preds = %14, %11
%38 = load i8*, i8** %2
ret i8* %38
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i8* @extract_file(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %0)
br label %18
6: ; preds = %1
%7 = tail call i32 @strlen(i8* %0)
%8 = sext i32 %7 to i64
%9 = ptrtoint i8* %2 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %10, %9
%12 = add i64 %11, %8
%13 = tail call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @enough_mem(i8* %14)
%16 = getelementptr inbounds i8, i8* %2, i64 1
%17 = tail call i32 @snprintf(i8* %14, i64 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %6, %4
%19 = phi i8* [ %14, %6 ], [ %5, %4 ]
ret i8* %19
}