// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]oatk/misc.c
// Function: parse_pathname
void parse_pathname(char *path, char **_dirname, char **_basename)
{
    if (_dirname) *_dirname = 0;
    if (_basename) *_basename = 0;
    if (path == 0) return;
    int len, i, n_token;
    len = strlen(path);
    if (len == 0) return;
    if (path[len-1] == '/') {
        if (_dirname) *_dirname = strdup(path);
        return;
    }
    char *dirname, *basename, *token;
    dirname = strdup(path);
    token = strtok(dirname, "/");
    n_token = 0;
    do {
        ++n_token;
        basename = token;
        token = strtok(NULL, "/");
    } while (token);
    // necessary for duplicate '/'
    for (i = 0; i < len; ++i)
        if (dirname[i] == '/')
            dirname[i] = 0;
    len = basename - dirname - 1;
    for (i = 0; i < len; ++i)
        if (!dirname[i])
            dirname[i] = '/';
    if (dirname != basename) {
        if (len) {
            // here need to strdup basename
            if (_dirname) *_dirname = dirname;
            if (_basename) *_basename = strdup(basename);
        } else {
            // basename with point to dirname
            if (_dirname) *_dirname = strdup("/");
            if (_basename) *_basename = basename;
        }
    } else {
        if ((strlen(basename)==1 && basename[0] == '.') ||
                (strlen(basename)==2 && 
                 basename[0] == '.' && basename[1] == '.')) {
            if (_dirname) *_dirname = dirname;
        } else {
            if (_dirname) *_dirname = strdup(".");
            if (_basename) *_basename = basename;
        }
    }
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
testq %rsi, %rsi
je 0x4fbc
andq $0x0, (%r14)
testq %rbx, %rbx
je 0x4fc5
andq $0x0, (%rbx)
testq %r15, %r15
je 0x5106
movq %r15, %rdi
callq 0x2130
movq %rax, %r13
testl %r13d, %r13d
je 0x5106
movl %r13d, %eax
decl %eax
cltq
cmpb $0x2f, (%r15,%rax)
jne 0x5009
testq %r14, %r14
je 0x5106
movq %r15, %rdi
callq 0x23b0
movq %rax, (%r14)
jmp 0x5106
movq %r15, %rdi
callq 0x23b0
movq %rax, %r12
leaq 0x1772(%rip), %rbp      # 0x678d
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2330
movq %rax, %r15
xorl %edi, %edi
movq %rbp, %rsi
callq 0x2330
testq %rax, %rax
jne 0x5026
xorl %eax, %eax
testl %r13d, %r13d
movl $0x0, %ecx
cmovgl %r13d, %ecx
cmpq %rax, %rcx
je 0x505c
cmpb $0x2f, (%r12,%rax)
jne 0x5057
movb $0x0, (%r12,%rax)
incq %rax
jmp 0x5046
movl %r12d, %eax
notl %eax
addl %r15d, %eax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
cmpq %rcx, %rdx
je 0x5086
cmpb $0x0, (%r12,%rcx)
jne 0x5081
movb $0x2f, (%r12,%rcx)
incq %rcx
jmp 0x5070
cmpq %r15, %r12
je 0x50a9
testl %eax, %eax
je 0x50c5
testq %r14, %r14
je 0x5097
movq %r12, (%r14)
testq %rbx, %rbx
je 0x5106
movq %r15, %rdi
callq 0x23b0
movq %rax, (%rbx)
jmp 0x5106
movq %r15, %rdi
callq 0x2130
cmpq $0x2, %rax
je 0x50d3
cmpq $0x1, %rax
jne 0x50ea
cmpb $0x2e, (%r15)
je 0x50e0
jmp 0x50ea
testq %r14, %r14
je 0x50fe
leaq 0x16bc(%rip), %rdi      # 0x678d
jmp 0x50f6
cmpb $0x2e, (%r15)
jne 0x50ea
cmpb $0x2e, 0x1(%r15)
jne 0x50ea
testq %r14, %r14
je 0x5106
movq %r12, (%r14)
jmp 0x5106
testq %r14, %r14
je 0x50fe
leaq 0x170f(%rip), %rdi      # 0x6805
callq 0x23b0
movq %rax, (%r14)
testq %rbx, %rbx
je 0x5106
movq %r15, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)