// File: /workspace/github_c_makefile_star2_O3/aerospike[P]aerospike-common/src/main/aerospike/as_string.c
// Function: as_basename
const char* as_basename(as_string * filename, const char* path)
{
	if (path == 0 || *path == 0) {
		// Found empty string.  Return current directory constant.
		char* value = ".";
		as_string_cons(filename, false, value, 1, false);
		return value;
	}

	const char* p = path;
	const char* begin = 0;

	// Skip till end of string.
	while (*p) {
		if (as_is_file_separator(*p)) {
			begin = p + 1;
		}
		p++;
	}

	if (begin == 0) {
		// No slashes found.  Return original string.
		as_string_cons(filename, false, (char*)path, p - path, false);
		return path;
	}

	if (begin == p) {
		// Found trailing slashes.
		// Create new string to hold filename without slashes.
		p--;

		while (as_is_file_separator(*p)) {
			if (p == path) {
				// String contains all slashes. Return slash constant.
				char* value = "/";
				as_string_cons(filename, false, value, 1, false);
				return value;
			}
			p--;
		}
		const char* end = p;

		while (p != path && !as_is_file_separator(*p)) {
			p--;
		}

		if (as_is_file_separator(*p)) {
			p++;
		}

		size_t len = (end - p) + 1;
		char* str = cf_malloc(len + 1);
		memcpy(str, p, len);
		*(str + len) = 0;
		as_string_cons(filename, false, str, len, true);
		return str;
	}

	// Return begin of filename.
	as_string_cons(filename, false, (char*)begin, p - begin, false);
	return begin;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
testq %rsi, %rsi
je 0x1096c
movb (%rsi), %al
movq %rsi, %r14
testb %al, %al
je 0x1096c
movl $0x1, %ecx
xorl %r15d, %r15d
xorl %r12d, %r12d
movl %eax, %edx
leaq (%r14,%rcx), %rsi
cmpb $0x5c, %dl
cmoveq %rsi, %r12
cmpb $0x2f, %dl
movb (%r14,%rcx), %dl
cmoveq %rsi, %r12
incq %rcx
decq %r15
testb %dl, %dl
jne 0x10927
testq %r12, %r12
je 0x109ac
movq %r14, %rcx
subq %r15, %rcx
cmpq %r12, %rcx
je 0x109b6
testq %rbx, %rbx
je 0x1099a
subq %r12, %r14
xorl %eax, %eax
subq %r15, %r14
movq %r14, %r15
movq %r12, %r14
jmp 0x10980
leaq 0x7a84(%rip), %r14      # 0x183f7
testq %rbx, %rbx
je 0x10997
movl $0x1, %r15d
xorl %eax, %eax
movw $0x4, 0x4(%rbx)
movl $0x1, (%rbx)
movb %al, 0x8(%rbx)
movq %r14, 0x10(%rbx)
movq %r15, 0x18(%rbx)
movq %r14, %r12
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rbx, %rbx
je 0x10997
negq %r15
jmp 0x1097e
negq %r15
movq %r15, %rbp
movzbl -0x1(%r14,%rbp), %ecx
cmpl $0x2f, %ecx
je 0x109cc
cmpl $0x5c, %ecx
jne 0x109da
decq %rbp
jne 0x109bc
leaq 0x7a21(%rip), %r14      # 0x183f9
jmp 0x10973
cmpq $0x1, %rbp
je 0x10a09
movl $0x2, %esi
leaq -0x1(%r14,%rbp), %rdx
subq %rbp, %rsi
cmpb $0x2f, %cl
je 0x10a0e
movzbl %cl, %edi
cmpl $0x5c, %edi
je 0x10a0e
testq %rsi, %rsi
je 0x10a09
decq %rdx
incq %rsi
movb (%rdx), %cl
jmp 0x109ed
movl %eax, %ecx
movq %r14, %rdx
cmpb $0x2f, %cl
movq %r14, %r15
sete %al
cmpb $0x5c, %cl
sete %cl
orb %al, %cl
movzbl %cl, %r13d
addq %rdx, %r13
subq %r13, %r15
leaq 0x1(%r15,%rbp), %rdi
addq %rbp, %r15
callq 0x8080
movq %rax, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rax, %r12
callq 0x85c0
movq %r12, %rax
subq %r13, %rax
addq %r14, %rax
testq %rbx, %rbx
movq %r12, %r14
movb $0x0, (%rbp,%rax)
movb $0x1, %al
jne 0x10980
jmp 0x1099a