// File: /workspace/github_c_makefile_star2_O2/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 0xea21
movb (%rsi), %al
movq %rsi, %r14
testb %al, %al
je 0xea21
pushq $0x1
popq %rcx
xorl %r15d, %r15d
movl %eax, %edx
xorl %r12d, %r12d
testb %dl, %dl
je 0xea5f
leaq (%r14,%rcx), %rsi
cmpb $0x5c, %dl
cmoveq %rsi, %r12
cmpb $0x2f, %dl
movb (%r14,%rcx), %dl
cmoveq %rsi, %r12
decq %r15
incq %rcx
jmp 0xe9ff
leaq 0x69cf(%rip), %r14      # 0x153f7
testq %rbx, %rbx
je 0xea4a
pushq $0x1
popq %r15
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 %r12, %r12
je 0xea84
movq %r14, %rcx
subq %r15, %rcx
cmpq %r12, %rcx
je 0xea8e
testq %rbx, %rbx
je 0xea4d
subq %r12, %r14
xorl %eax, %eax
subq %r15, %r14
movq %r14, %r15
movq %r12, %r14
jmp 0xea33
testq %rbx, %rbx
je 0xea4a
negq %r15
jmp 0xea31
negq %r15
movq %r15, %rbp
movzbl -0x1(%r14,%rbp), %ecx
cmpl $0x2f, %ecx
je 0xeaa4
cmpl $0x5c, %ecx
jne 0xeab5
decq %rbp
jne 0xea94
leaq 0x6949(%rip), %r14      # 0x153f9
jmp 0xea28
pushq $0x1
popq %rdx
subq %rbp, %rdx
leaq -0x1(%r14,%rbp), %rcx
testq %rdx, %rdx
je 0xeade
movzbl (%rcx), %esi
cmpl $0x2f, %esi
je 0xeada
cmpl $0x5c, %esi
je 0xeada
decq %rcx
incq %rdx
jmp 0xeac0
movl %esi, %eax
jmp 0xeae1
movq %r14, %rcx
cmpb $0x2f, %al
movq %r14, %r15
sete %dl
cmpb $0x5c, %al
sete %al
orb %dl, %al
movzbl %al, %r13d
addq %rcx, %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 0x8630
movq %r12, %rax
subq %r13, %rax
addq %r14, %rax
testq %rbx, %rbx
movq %r12, %r14
movb $0x0, (%rbp,%rax)
movb $0x1, %al
jne 0xea33
jmp 0xea4d