// File: /workspace/github_c_makefile_star2_O1/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 0x55fa
movq $0x0, (%r14)
testq %rbx, %rbx
je 0x5606
movq $0x0, (%rbx)
testq %r15, %r15
je 0x5749
movq %r15, %rdi
callq 0x2130
movq %rax, %r13
testl %r13d, %r13d
je 0x5749
leal -0x1(%r13), %eax
cltq
cmpb $0x2f, (%r15,%rax)
jne 0x5649
testq %r14, %r14
je 0x5749
movq %r15, %rdi
callq 0x23b0
movq %rax, (%r14)
jmp 0x5749
movq %r15, %rdi
callq 0x23b0
movq %rax, %r12
leaq 0x213a(%rip), %rbp      # 0x7795
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2330
movq %rax, %r15
xorl %edi, %edi
movq %rbp, %rsi
callq 0x2330
testq %rax, %rax
jne 0x5666
testl %r13d, %r13d
jle 0x569a
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %eax, %eax
cmpb $0x2f, (%r12,%rax)
jne 0x5692
movb $0x0, (%r12,%rax)
incq %rax
cmpq %rax, %r13
jne 0x5686
movq %r12, %rax
notq %rax
addq %r15, %rax
testl %eax, %eax
jle 0x56c5
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
cmpb $0x0, (%r12,%rdx)
jne 0x56bd
movb $0x2f, (%r12,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x56b1
cmpq %r15, %r12
je 0x56e8
testl %eax, %eax
je 0x572d
testq %r14, %r14
je 0x56d6
movq %r12, (%r14)
testq %rbx, %rbx
je 0x5749
movq %r15, %rdi
callq 0x23b0
movq %rax, (%rbx)
jmp 0x5749
movq %r15, %rdi
callq 0x2130
cmpq $0x2, %rax
je 0x5708
cmpq $0x1, %rax
jne 0x571f
cmpb $0x2e, (%r15)
je 0x5715
cmpq $0x2, %rax
jne 0x571f
cmpb $0x2e, (%r15)
jne 0x571f
cmpb $0x2e, 0x1(%r15)
jne 0x571f
testq %r14, %r14
je 0x5749
movq %r12, (%r14)
jmp 0x5749
testq %r14, %r14
je 0x5741
leaq 0x20e2(%rip), %rdi      # 0x780d
jmp 0x5739
testq %r14, %r14
je 0x5741
leaq 0x205c(%rip), %rdi      # 0x7795
callq 0x23b0
movq %rax, (%r14)
testq %rbx, %rbx
je 0x5749
movq %r15, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq