#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(int);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
char *getName(const char *pathSrc) {
  char *result;
  int result_len;
  const char *filename_begin = strrchr(pathSrc, '/');
  if (filename_begin == NULL) {
    filename_begin = pathSrc;
  } else {
    filename_begin++;
  }
  const char *filename_end = strrchr(pathSrc, '.');
  if (filename_end != NULL) {
    result_len = filename_end - filename_begin;
  } else {
    result_len = strlen(filename_begin);
  }
  result = (char *)malloc(result_len + 1);
  strncpy(result, filename_begin, result_len);
  result[result_len] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<getName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1176 <getName+0x36>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1182 <getName+0x42>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b2 <getName+0x72>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    11be <getName+0x7e>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getName>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%r14
test   %rax,%rax
cmove  %rbx,%r14
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1177 <getName+0x37>
mov    %rax,%rbx
sub    %r14d,%ebx
jmp    1181 <getName+0x41>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @getName(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
%4 = getelementptr inbounds i8, i8* %2, i64 1
%5 = select i1 %3, i8* %0, i8* %4
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = ptrtoint i8* %6 to i64
%10 = ptrtoint i8* %5 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
br label %15
13: ; preds = %1
%14 = tail call i32 @strlen(i8* %5)
br label %15
15: ; preds = %13, %8
%16 = phi i32 [ %12, %8 ], [ %14, %13 ]
%17 = add nsw i32 %16, 1
%18 = tail call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
%20 = tail call i32 @strncpy(i8* %19, i8* %5, i32 %16)
%21 = sext i32 %16 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
ret i8* %19
}