// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Rtklib/rtkcmn.cpp
// Function: bamboo::expath(char const*, char**, int)
extern int expath(const char *path, char *paths[], int nmax)
{
    int i,j,n=0;
    char tmp[1024];
#ifdef WIN32
    WIN32_FIND_DATA file;
    HANDLE h;
    char dir[1024]="",*p;
    
    trace(3,"expath  : path=%s nmax=%d\n",path,nmax);
    
    if ((p=strrchr(path,'\\'))) {
        strncpy(dir,path,p-path+1); dir[p-path+1]='\0';
    }
    if ((h=FindFirstFile((LPCTSTR)path,&file))==INVALID_HANDLE_VALUE) {
        strcpy(paths[0],path);
        return 1;
    }
    sprintf(paths[n++],"%s%s",dir,file.cFileName);
    while (FindNextFile(h,&file)&&n<nmax) {
        if (file.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) continue;
        sprintf(paths[n++],"%s%s",dir,file.cFileName);
    }
    FindClose(h);
#else
    struct dirent *d;
    DIR *dp;
    const char *file=path;
    char dir[1024]="",s1[1024],s2[1024],*p,*q,*r;
    
    trace(3,"expath  : path=%s nmax=%d\n",path,nmax);
    char p_path[1024] = {0};
    strcpy(p_path,path);
    if ((p=strrchr(p_path,'/'))||(p=strrchr(p_path,'\\'))) {
        file=p+1; strncpy(dir,p_path,p-p_path+1); dir[p-p_path+1]='\0';
    }
    if (!(dp=opendir(*dir?dir:"."))) return 0;
    while ((d=readdir(dp))) {
        if (*(d->d_name)=='.') continue;
        sprintf(s1,"^%s$",d->d_name);
        sprintf(s2,"^%s$",file);
        for (p=s1;*p;p++) *p=(char)tolower((int)*p);
        for (p=s2;*p;p++) *p=(char)tolower((int)*p);
        
        for (p=s1,q=strtok_r(s2,"*",&r);q;q=strtok_r(NULL,"*",&r)) {
            if ((p=strstr(p,q))) p+=strlen(q); else break;
        }
        if (p&&n<nmax) sprintf(paths[n++],"%s%s",dir,d->d_name);
    }
    closedir(dp);
#endif
    /* sort paths in alphabetical order */
    for (i=0;i<n-1;i++) {
        for (j=i+1;j<n;j++) {
            if (strcmp(paths[i],paths[j])>0) {
                strcpy(tmp,paths[i]);
                strcpy(paths[i],paths[j]);
                strcpy(paths[j],tmp);
            }
        }
    }
    for (i=0;i<n;i++) trace(3,"expath  : file=%s\n",paths[i]);
    
    return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1438, %rsp           # imm = 0x1438
movl %edx, -0x4c(%rbp)
movq %rsi, -0x48(%rbp)
movq %rdi, %r13
leaq -0x460(%rbp), %r14
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
xorl %esi, %esi
callq 0x8390
leaq -0xc60(%rbp), %r15
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x8390
movq %r15, %rdi
movq %r13, %rsi
callq 0x85c0
pushq $0x2f
popq %rsi
movq %r15, %rdi
callq 0x8690
testq %rax, %rax
jne 0x4adad
movq %r13, -0x38(%rbp)
leaq -0xc60(%rbp), %rdi
pushq $0x5c
popq %rsi
callq 0x8690
testq %rax, %rax
je 0x4afc0
movq %rax, %r12
incq %rax
movq %rax, -0x38(%rbp)
subq %r15, %r12
leaq 0x1(%r12), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x8360
movb $0x0, -0x45f(%rbp,%r12)
cmpb $0x0, -0x460(%rbp)
leaq 0x14473(%rip), %rdi     # 0x5f254
cmovneq %r14, %rdi
callq 0x8930
testq %rax, %rax
je 0x4afac
movq %rax, -0x40(%rbp)
leaq -0x1060(%rbp), %r12
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rbx
movq -0x40(%rbp), %r13
movq %r13, %rdi
callq 0x8950
testq %rax, %rax
je 0x4af20
movq %rax, %r14
cmpb $0x2e, 0x13(%rax)
je 0x4ae0d
addq $0x13, %r14
leaq -0x860(%rbp), %rdi
leaq 0x20541(%rip), %r13     # 0x6b37a
movq %r13, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x8110
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x8110
leaq -0x860(%rbp), %r15
movsbl (%r15), %edi
testl %edi, %edi
je 0x4ae72
callq 0x88e0
movb %al, (%r15)
incq %r15
jmp 0x4ae5d
movq %r12, %r15
movsbl (%r15), %edi
testl %edi, %edi
je 0x4ae8a
callq 0x88e0
movb %al, (%r15)
incq %r15
jmp 0x4ae75
movq %r12, %rdi
leaq 0x204eb(%rip), %rsi     # 0x6b37f
leaq -0x58(%rbp), %rdx
callq 0x8b90
movq %rax, %r13
leaq -0x860(%rbp), %r15
testq %r13, %r13
je 0x4aee5
movq %r15, %rdi
movq %r13, %rsi
callq 0x8170
testq %rax, %rax
je 0x4ae09
movq %rax, %r15
movq %r13, %rdi
callq 0x8290
addq %rax, %r15
xorl %edi, %edi
leaq 0x204a8(%rip), %rsi     # 0x6b37f
leaq -0x58(%rbp), %rdx
callq 0x8b90
movq %rax, %r13
jmp 0x4aea7
movl -0x4c(%rbp), %eax
cmpl %eax, -0x2c(%rbp)
jge 0x4ae09
movl -0x2c(%rbp), %ecx
movl %ecx, %eax
incl %ecx
movl %ecx, -0x2c(%rbp)
movq -0x48(%rbp), %rcx
movq (%rcx,%rax,8), %rdi
leaq 0x1ab66(%rip), %rsi     # 0x65a70
leaq -0x460(%rbp), %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x8110
jmp 0x4ae09
movq %r13, %rdi
callq 0x8a10
movl -0x2c(%rbp), %eax
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovgel %eax, %ecx
decl %ecx
movq %rcx, -0x40(%rbp)
pushq $0x1
popq %r14
xorl %r12d, %r12d
cmpq -0x40(%rbp), %r12
je 0x4afae
movq %r14, -0x38(%rbp)
cmpl %r14d, %eax
jle 0x4afa0
movq -0x48(%rbp), %rax
movq (%rax,%r12,8), %r15
movq (%rax,%r14,8), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x8890
testl %eax, %eax
jle 0x4af98
leaq -0x1460(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x85c0
movq %r15, %rdi
movq %r13, %rsi
callq 0x85c0
movq -0x48(%rbp), %rax
movq (%rax,%r14,8), %rdi
movq %rbx, %rsi
callq 0x85c0
incq %r14
movl -0x2c(%rbp), %eax
jmp 0x4af4b
incq %r12
movq -0x38(%rbp), %r14
incq %r14
jmp 0x4af41
xorl %eax, %eax
addq $0x1438, %rsp           # imm = 0x1438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1428d(%rip), %rdi     # 0x5f254
jmp 0x4ade5