#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*/ strcpy(char *, char *);
int strlen(char *);
void basenamecpy(char *str1, char *str2) {
  char *p = str1 + (strlen(str1) - 1);
  while (*--p != '/' && p != str1)
    continue;
  if (p != str1)
    p++;
  strcpy(str2, p);
}


x86 assembly (clang, -O0):
<basenamecpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movsbl -0x1(%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x21(%rbp)
je     1183 <basenamecpy+0x63>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1193 <basenamecpy+0x73>
jmp    1198 <basenamecpy+0x78>
jmp    1154 <basenamecpy+0x34>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11b2 <basenamecpy+0x92>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basenamecpy>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
movslq %eax,%rcx
mov    $0x1,%eax
sub    %rcx,%rax
add    $0xfffffffffffffffe,%rcx
xchg   %ax,%ax
mov    %rax,%rdx
add    $0x1,%rax
cmpb   $0x2f,(%rbx,%rcx,1)
je     1157 <basenamecpy+0x37>
add    $0xffffffffffffffff,%rcx
cmp    $0xffffffffffffffff,%rdx
jne    1140 <basenamecpy+0x20>
lea    0x1(%rbx),%rsi
cmp    $0xffffffffffffffff,%rdx
cmove  %rbx,%rsi
sub    %rax,%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>

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

LLVM IR (-O2):
define void @basenamecpy(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
br label %7
7: ; preds = %7, %2
%8 = phi i8* [ %6, %2 ], [ %9, %7 ]
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 47
%12 = icmp ne i8* %9, %0
%13 = and i1 %11, %12
br i1 %13, label %7, label %14
14: ; preds = %7
%15 = select i1 %12, i8* %8, i8* %9
%16 = tail call i32 @strcpy(i8* %1, i8* %15)
ret void
}