// File: /workspace/github_c_makefile_star2_O3/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 0x576a
movq $0x0, (%r14)
testq %rbx, %rbx
je 0x5776
movq $0x0, (%rbx)
testq %r15, %r15
je 0x58b5
movq %r15, %rdi
callq 0x2130
movq %rax, %r13
testl %r13d, %r13d
je 0x58b5
leal -0x1(%r13), %eax
cltq
cmpb $0x2f, (%r15,%rax)
jne 0x57b9
testq %r14, %r14
je 0x58b5
movq %r15, %rdi
callq 0x23b0
movq %rax, (%r14)
jmp 0x58b5
movq %r15, %rdi
callq 0x23b0
movq %rax, %r12
leaq 0x1fc2(%rip), %rbp      # 0x778d
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2330
movq %rax, %r15
xorl %edi, %edi
movq %rbp, %rsi
callq 0x2330
testq %rax, %rax
jne 0x57d6
testl %r13d, %r13d
jle 0x580a
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %eax, %eax
cmpb $0x2f, (%r12,%rax)
jne 0x5802
movb $0x0, (%r12,%rax)
incq %rax
cmpq %rax, %r13
jne 0x57f6
movq %r12, %rax
notq %rax
addq %r15, %rax
testl %eax, %eax
jle 0x5835
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
cmpb $0x0, (%r12,%rdx)
jne 0x582d
movb $0x2f, (%r12,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x5821
cmpq %r15, %r12
je 0x5858
testl %eax, %eax
je 0x5874
testq %r14, %r14
je 0x5846
movq %r12, (%r14)
testq %rbx, %rbx
je 0x58b5
movq %r15, %rdi
callq 0x23b0
movq %rax, (%rbx)
jmp 0x58b5
movq %r15, %rdi
callq 0x2130
cmpq $0x2, %rax
je 0x5882
cmpq $0x1, %rax
jne 0x5899
cmpb $0x2e, (%r15)
je 0x588f
jmp 0x5899
testq %r14, %r14
je 0x58ad
leaq 0x1f0d(%rip), %rdi      # 0x778d
jmp 0x58a5
cmpb $0x2e, (%r15)
jne 0x5899
cmpb $0x2e, 0x1(%r15)
jne 0x5899
testq %r14, %r14
je 0x58b5
movq %r12, (%r14)
jmp 0x58b5
testq %r14, %r14
je 0x58ad
leaq 0x1f60(%rip), %rdi      # 0x7805
callq 0x23b0
movq %rax, (%r14)
testq %rbx, %rbx
je 0x58b5
movq %r15, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq