#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 *, unsigned int);
char *strrchr(char const *, char);
void make_path_copy(const char *filename, char *path) {
  const char *last_slash = strrchr(filename, '/');
  if (!last_slash) {
    *path = 0;
  } else {
    unsigned int len = last_slash - filename;
    memcpy(path, filename, len);
    path[len] = 0;
    if (len == 1 && path[0] == '.') {
      path[0] = 0;
    }
  }
}


x86 assembly (clang, -O0):
<make_path_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1159 <make_path_copy+0x39>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11a8 <make_path_copy+0x88>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x1,-0x1c(%rbp)
jne    11a3 <make_path_copy+0x83>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11a3 <make_path_copy+0x83>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11a8 <make_path_copy+0x88>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_path_copy>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     115f <make_path_copy+0x3f>
mov    %rax,%rbx
sub    %r15,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
cmp    $0x1,%ebx
jne    1163 <make_path_copy+0x43>
cmpb   $0x2e,(%r14)
jne    1163 <make_path_copy+0x43>
movb   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @make_path_copy(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** %3
%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 %13, label %11
11: ; preds = %2
%12 = load i8*, i8** %4
store i8 0, i8* %12
br label %40
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = load i8*, i8** %3
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
store i32 %19, i32* %6
%20 = load i8*, i8** %4
%21 = load i8*, i8** %3
%22 = load i32, i32* %6
%23 = call i32 @memcpy(i8* %20, i8* %21, i32 %22)
%24 = load i8*, i8** %4
%25 = load i32, i32* %6
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 0, i8* %27
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %39
30: ; preds = %13
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 46
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i64 0
store i8 0, i8* %38
br label %39
39: ; preds = %36, %30, %13
br label %40
40: ; preds = %39, %11
ret void
}

LLVM IR (-O2):
define void @make_path_copy(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = ptrtoint i8* %3 to i64
%7 = ptrtoint i8* %0 to i64
%8 = sub i64 %6, %7
%9 = trunc i64 %8 to i32
%10 = tail call i32 @memcpy(i8* %1, i8* %0, i32 %9)
%11 = and i64 %8, 4294967295
%12 = getelementptr inbounds i8, i8* %1, i64 %11
store i8 0, i8* %12
%13 = icmp eq i32 %9, 1
br i1 %13, label %14, label %18
14: ; preds = %5
%15 = load i8, i8* %1
%16 = icmp eq i8 %15, 46
br i1 %16, label %17, label %18
17: ; preds = %14, %2
store i8 0, i8* %1
br label %18
18: ; preds = %17, %5, %14
ret void
}