#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*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
void sp_parse_file_basename(const char *filename, char *basename) {
  const char *ptr;
  size_t count, size;
  count = size = strlen(filename);
  ptr = filename + count;
  while (count) {
    ptr--, count--;
    if (*ptr == '.')
      break;
  }
  if (!count)
    count = size;
  memcpy(basename, filename, count);
  basename[count] = 0;
}


x86 assembly (clang, -O0):
<sp_parse_file_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118a <sp_parse_file_basename+0x6a>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1185 <sp_parse_file_basename+0x65>
jmp    118a <sp_parse_file_basename+0x6a>
jmp    114d <sp_parse_file_basename+0x2d>
cmpq   $0x0,-0x20(%rbp)
jne    119d <sp_parse_file_basename+0x7d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sp_parse_file_basename>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %rax,%rax
je     115a <sp_parse_file_basename+0x3a>
mov    %rax,%rcx
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rcx),%rbx
cmpb   $0x2e,-0x1(%r15,%rcx,1)
je     1155 <sp_parse_file_basename+0x35>
cmp    $0x1,%rcx
mov    %rbx,%rcx
jne    1140 <sp_parse_file_basename+0x20>
test   %rbx,%rbx
jne    115d <sp_parse_file_basename+0x3d>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%r14,%rbx,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @sp_parse_file_basename(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 %3
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ %11, %7 ], [ %3, %5 ]
%9 = phi i8* [ %10, %7 ], [ %6, %5 ]
%10 = getelementptr inbounds i8, i8* %9, i64 -1
%11 = add i64 %8, -1
%12 = load i8, i8* %10
%13 = icmp ne i8 %12, 46
%14 = icmp ne i64 %11, 0
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %7, label %16
16: ; preds = %7
%17 = icmp eq i64 %11, 0
br i1 %17, label %18, label %19
18: ; preds = %2, %16
br label %19
19: ; preds = %16, %18
%20 = phi i64 [ %3, %18 ], [ %11, %16 ]
%21 = tail call i32 @memcpy(i8* %1, i8* %0, i64 %20)
%22 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 0, i8* %22
ret void
}