#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*/ free(char *);
char *my_str_malloc(scalar_t__);
char *parse_name_from_path(char const *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *strrchr(char *, char);
char *get_prefix_name(const char *fullname, int isfolder) {
  char *parse_name = NULL;
  char *p = NULL;
  char *filename = NULL;
  filename = parse_name_from_path(fullname);
  p = strrchr(filename, '.');
  if (p && filename[0] != '.' && !isfolder) {
    parse_name = my_str_malloc(strlen(filename) - strlen(p) + 1);
    strncpy(parse_name, filename, strlen(filename) - strlen(p));
  } else {
    parse_name = my_str_malloc(strlen(filename) + 1);
    strcpy(parse_name, filename);
  }
  free(filename);
  filename = NULL;
  ;
  return parse_name;
}


x86 assembly (clang, -O0):
<get_prefix_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <parse_name_from_path@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2e,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1244 <get_prefix_name+0xd4>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1244 <get_prefix_name+0xd4>
cmpl   $0x0,-0xc(%rbp)
jne    1244 <get_prefix_name+0xd4>
mov    -0x28(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x48(%rbp),%rdi
sub    %rax,%rdi
add    $0x1,%rdi
call   1090 <my_str_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
sub    %rax,%rdx
call   1040 <strncpy@plt>
jmp    126a <get_prefix_name+0xfa>
mov    -0x28(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1090 <my_str_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_prefix_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
call   1060 <parse_name_from_path@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2e,%esi
call   1080 <strrchr@plt>
test   %rax,%rax
je     11ea <get_prefix_name+0x7a>
test   %ebp,%ebp
jne    11ea <get_prefix_name+0x7a>
cmpb   $0x2e,(%rbx)
je     11ea <get_prefix_name+0x7a>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1070 <strlen@plt>
sub    %rax,%rbp
add    $0x1,%rbp
mov    %rbp,%rdi
call   1090 <my_str_malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1070 <strlen@plt>
sub    %rax,%rbp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <strncpy@plt>
jmp    1209 <get_prefix_name+0x99>
mov    %rbx,%rdi
call   1070 <strlen@plt>
lea    0x1(%rax),%rdi
call   1090 <my_str_malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @get_prefix_name(i8* %0, i32 %1) {
%3 = tail call i8* @parse_name_from_path(i8* %0)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %3, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 46
%9 = icmp ne i32 %1, 0
%10 = or i1 %9, %8
br i1 %10, label %21, label %11
11: ; preds = %6
%12 = tail call i64 @strlen(i8* %3)
%13 = tail call i64 @strlen(i8* %4)
%14 = add i64 %12, 1
%15 = sub i64 %14, %13
%16 = tail call i8* @my_str_malloc(i64 %15)
%17 = tail call i64 @strlen(i8* %3)
%18 = tail call i64 @strlen(i8* %4)
%19 = sub nsw i64 %17, %18
%20 = tail call i32 @strncpy(i8* %16, i8* %3, i64 %19)
br label %26
21: ; preds = %6, %2
%22 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%23 = add nsw i64 %22, 1
%24 = tail call i8* @my_str_malloc(i64 %23)
%25 = tail call i32 @strcpy(i8* %24, i8* %3)
br label %26
26: ; preds = %21, %11
%27 = phi i8* [ %24, %21 ], [ %16, %11 ]
%28 = tail call i32 @free(i8* %3)
ret i8* %27
}