#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*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *strrchr(char const *, char);
void displayName(const char *filename, char *destination, size_t size) {
  memset(destination, 0, size);
  const char *nameStart = filename;
  char *slash = strrchr(filename, '/');
  if (slash) {
    nameStart = slash + 1;
  }
  strncpy(destination, nameStart, size - 1);
  char *dot = strrchr(nameStart, '.');
  if (dot) {
    int dotIndex = (int)(dot - nameStart);
    if (dotIndex < size) {
      destination[dotIndex] = 0;
    }
  }
}


x86 assembly (clang, -O0):
<displayName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1184 <displayName+0x54>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11e3 <displayName+0xb3>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11de <displayName+0xae>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11e3 <displayName+0xb3>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<displayName>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r12,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r12,%rbx
lea    -0x1(%r15),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1192 <displayName+0x62>
sub    %ebx,%eax
cltq
cmp    %r15,%rax
jae    1192 <displayName+0x62>
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @displayName(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @memset(i8* %1, i32 0, i64 %2)
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%6 = icmp eq i8* %5, null
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = select i1 %6, i8* %0, i8* %7
%9 = add i64 %2, -1
%10 = tail call i32 @strncpy(i8* %1, i8* %8, i64 %9)
%11 = tail call i8* @strrchr(i8* dereferenceable(1) %8, i8 signext 46)
%12 = icmp eq i8* %11, null
br i1 %12, label %22, label %13
13: ; preds = %3
%14 = ptrtoint i8* %11 to i64
%15 = ptrtoint i8* %8 to i64
%16 = sub i64 %14, %15
%17 = shl i64 %16, 32
%18 = ashr exact i64 %17, 32
%19 = icmp ult i64 %18, %2
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %21
br label %22
22: ; preds = %13, %20, %3
ret void
}