// File: /workspace/github_cpp_makefile_star2_O3/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, %ebx
movq %rsi, -0x48(%rbp)
movq %rdi, %r13
leaq -0xc60(%rbp), %r14
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
xorl %esi, %esi
callq 0x8390
leaq -0x1060(%rbp), %r15
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x8390
movq %r15, %rdi
movq %r13, %rsi
callq 0x85c0
movq %r15, %rdi
movl $0x2f, %esi
callq 0x86a0
testq %rax, %rax
jne 0x534e6
leaq -0x1060(%rbp), %rdi
movl $0x5c, %esi
callq 0x86a0
testq %rax, %rax
je 0x53740
movq %rax, %r12
incq %rax
movq %rax, -0x30(%rbp)
subq %r15, %r12
leaq 0x1(%r12), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x8350
movb $0x0, -0xc5f(%rbp,%r12)
cmpb $0x0, -0xc60(%rbp)
leaq 0x15d3a(%rip), %rdi     # 0x69254
cmovneq %r14, %rdi
callq 0x8930
testq %rax, %rax
je 0x5372c
movq %rax, %r13
movq $0x0, -0x38(%rbp)
movq %r13, %rdi
callq 0x8950
testq %rax, %rax
je 0x53674
movq %rax, %r12
cmpb $0x2e, 0x13(%rax)
je 0x53537
movl %ebx, -0x40(%rbp)
addq $0x13, %r12
leaq -0x860(%rbp), %rdi
leaq 0x21dfe(%rip), %rbx     # 0x75364
movq %rbx, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8120
leaq -0x460(%rbp), %rdi
movq %rbx, %rsi
movq -0x30(%rbp), %rdx
xorl %eax, %eax
callq 0x8120
movb -0x860(%rbp), %al
leaq -0x85f(%rbp), %rbx
testb %al, %al
je 0x535ab
movsbl %al, %edi
callq 0x88e0
movb %al, -0x1(%rbx)
movb (%rbx), %al
incq %rbx
jmp 0x53595
movb -0x460(%rbp), %al
leaq -0x45f(%rbp), %rbx
testb %al, %al
je 0x535ce
movsbl %al, %edi
callq 0x88e0
movb %al, -0x1(%rbx)
movb (%rbx), %al
incq %rbx
jmp 0x535b8
leaq -0x460(%rbp), %rdi
leaq 0x21d8d(%rip), %rsi     # 0x75369
leaq -0x60(%rbp), %rdx
callq 0x8b90
testq %rax, %rax
movl -0x40(%rbp), %ebx
je 0x53633
movq %rax, %r15
leaq -0x860(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x8160
testq %rax, %rax
je 0x53537
movq %rax, %r14
movq %r15, %rdi
callq 0x8290
addq %rax, %r14
xorl %edi, %edi
leaq 0x21d47(%rip), %rsi     # 0x75369
leaq -0x60(%rbp), %rdx
callq 0x8b90
movq %rax, %r15
testq %rax, %rax
jne 0x535f7
cmpl %ebx, -0x38(%rbp)
jge 0x53537
movq -0x38(%rbp), %rax
movq %rax, %rbx
incq %rbx
movl %eax, %eax
movq -0x48(%rbp), %rcx
movq (%rcx,%rax,8), %rdi
leaq 0x1c41d(%rip), %rsi     # 0x6fa74
leaq -0xc60(%rbp), %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x8120
movq %rbx, -0x38(%rbp)
movl -0x40(%rbp), %ebx
jmp 0x53537
movq %r13, %rdi
callq 0x8a10
movq -0x38(%rbp), %rax
cmpl $0x2, %eax
jb 0x5372e
leal -0x1(%rax), %ecx
movq %rcx, -0x50(%rbp)
xorl %ecx, %ecx
movq %rax, %r14
movq -0x48(%rbp), %rax
movq %rax, -0x30(%rbp)
movq %rcx, %rbx
leaq 0x1(%rcx), %rax
movq %rax, -0x58(%rbp)
movl $0x1, %r13d
movq %rcx, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq (%rax,%rbx,8), %r15
movq -0x30(%rbp), %rax
movq (%rax,%r13,8), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x8880
testl %eax, %eax
jle 0x53708
movq %r14, %rbx
leaq -0x1460(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x85c0
movq %r15, %rdi
movq %r12, %rsi
callq 0x85c0
movq -0x30(%rbp), %rax
movq (%rax,%r13,8), %rdi
movq %r14, %rsi
movq %rbx, %r14
movq -0x40(%rbp), %rbx
callq 0x85c0
incq %r13
cmpq %r13, %r14
jne 0x536b2
addq $0x8, -0x30(%rbp)
decq %r14
movq -0x58(%rbp), %rcx
cmpq -0x50(%rbp), %rcx
jne 0x5369d
movq -0x38(%rbp), %rax
jmp 0x5372e
xorl %eax, %eax
addq $0x1438, %rsp           # imm = 0x1438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, -0x30(%rbp)
leaq 0x15b09(%rip), %rdi     # 0x69254
jmp 0x5351e