#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 *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strrchr(char const *, char);
void make_cache_name(char *cached, const char *filename) {
  char *rslash = strrchr(filename, '/');
  if (rslash) {
    unsigned int len = rslash - filename + 1;
    memcpy(cached, filename, len);
    cached += len;
    filename += len;
  }
  memcpy(cached, ".fmdc.", 6);
  cached += 6;
  strcpy(cached, filename);
}


x86 assembly (clang, -O0):
<make_cache_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119f <make_cache_name+0x6f>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0x6,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_cache_name>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1169 <make_cache_name+0x39>
mov    %rax,%rbx
sub    %r14d,%ebx
add    $0x1,%ebx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
add    %rbx,%r15
add    %rbx,%r14
lea    0xe90(%rip),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <memcpy@plt>
add    $0x6,%r15
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

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

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