// File: /workspace/github_c_makefile_star2_O2/serge-404[P]CPM32/cpm.c
// Function: FindFirstFile
DIR *FindFirstFile(char* lpFileName,	// pointer to name of file to search for  
    WIN32_FIND_DATA *lpFindFileData) 	// pointer to returned information 
{
    DIR *pDir;
    struct dirent *pDirent;
    struct stat statbuf;
	char *cDir, *cName=lpFileName;
	int szDir;
	cDir=strrchr(lpFileName, '|');
	if (cDir==NULL)
		cDir=strrchr(lpFileName, '/');
	if ((cDir)!=NULL) { 
		cName=cDir+1;
		cDir=lpFileName;
		szDir=cName-cDir-1;
		strncpy(ffDir, cDir, szDir);
		ffDir[szDir]=0;
	}
	else {
		strncpy(ffDir, cpm_drive[ cpm_disk_no], sizeof(ffDir));
	}
	strncpy(ffName, cName, sizeof(ffName)-1);
	if (strncmp(ffName,"*.*",4)==0) {
		*ffName='*';
		ffName[1]=0;
	}
	CharUpperX(ffName);
	pDir = opendir(ffDir);
	if (pDir == NULL) 
        return hFindFile=INVALID_HANDLE_VALUE;
    while ((pDirent = readdir(pDir)) != NULL) {
       	strncpy(lpFindFileData->cFileName, pDirent->d_name, _MAX_PATH-1);
		if (fnmatch(ffName, CharUpperX(pDirent->d_name), FNM_CASEFOLD)==0) {
			if (stat(buildname(ffDir,lpFindFileData->cFileName), &statbuf)!=0) { 
				closedir(pDir);
				DEBUGOUT(stderr, "FindFirst ERROR: failed while stat file `%s`\n",lpFindFileData->cFileName);
	 			return hFindFile=INVALID_HANDLE_VALUE;
			}
			if (!(statbuf.st_mode & S_IFDIR)) {
				lpFindFileData->cAlternateFileName[0]=0;
				lpFindFileData->dwFileAttributes=(*(lpFindFileData->cFileName)=='.' ? FILE_ATTRIBUTE_HIDDEN : 0);	
				lpFindFileData->nFileSizeHigh=0;
				lpFindFileData->nFileSizeLow=(DWORD)statbuf.st_size;
				return pDir;
			}
		}
    }
    closedir(pDir);
    return hFindFile=INVALID_HANDLE_VALUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r13
movq %rdi, %r14
pushq $0x7c
popq %rsi
callq 0x2110
testq %rax, %rax
jne 0x7dd2
pushq $0x2f
popq %rsi
movq %r14, %rdi
callq 0x2110
testq %rax, %rax
je 0x7ef8
movq %rax, %rbx
incq %rbx
movl %r14d, %eax
notl %eax
addl %ebx, %eax
movslq %eax, %r15
leaq 0x10d107(%rip), %r12    # 0x114ef0
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2070
movb $0x0, (%r15,%r12)
movq %rbx, %r14
leaq 0x10d1fa(%rip), %rdi    # 0x115000
movl $0x103, %edx            # imm = 0x103
movq %r14, %rsi
callq 0x2070
cmpl $0x2a2e2a, 0x10d1e3(%rip) # imm = 0x2A2E2A
jne 0x7e28
movw $0x2a, 0x10d1d8(%rip)   # 0x115000
leaq 0x10d1d1(%rip), %rdi    # 0x115000
callq 0x74b0
leaq 0x10d0b5(%rip), %rdi    # 0x114ef0
callq 0x20d0
testq %rax, %rax
je 0x7f31
movq %rax, %r14
movq %r13, (%rsp)
leaq 0x18(%r13), %r15
leaq 0x10d1a5(%rip), %r12    # 0x115000
pushq $0x10
popq %rbp
leaq 0x8(%rsp), %rbx
movq %r14, %rdi
callq 0x2270
testq %rax, %rax
je 0x7eee
movq %rax, %r13
addq $0x13, %r13
movl $0x103, %edx            # imm = 0x103
movq %r15, %rdi
movq %r13, %rsi
callq 0x2070
movq %r13, %rdi
callq 0x74b0
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x2140
testl %eax, %eax
jne 0x7e63
leaq 0x10d049(%rip), %rdi    # 0x114ef0
movq %r15, %rsi
callq 0x75d4
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2230
testl %eax, %eax
jne 0x7f20
testb $0x40, 0x21(%rsp)
jne 0x7e63
movq (%rsp), %rcx
movb $0x0, 0x11c(%rcx)
xorl %eax, %eax
cmpb $0x2e, 0x18(%rcx)
sete %al
addl %eax, %eax
movq %rax, (%rcx)
andq $0x0, 0x8(%rcx)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rcx)
jmp 0x7f3c
movq %r14, %rdi
callq 0x21a0
jmp 0x7f31
movzbl 0xb311(%rip), %eax      # 0x13210
leaq 0x10b53a(%rip), %rcx    # 0x113440
movq (%rcx,%rax,8), %rsi
leaq 0x10cfdf(%rip), %rdi    # 0x114ef0
movl $0x104, %edx            # imm = 0x104
callq 0x2070
jmp 0x7dff
movq %r14, %rdi
callq 0x21a0
cmpl $0x0, 0x10b3e5(%rip)    # 0x113314
jne 0x7f51
andq $0x0, 0x10cfa7(%rip)    # 0x114ee0
xorl %r14d, %r14d
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb0a0(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x7e65(%rip), %rsi      # 0xfdc7
movq %r15, %rdx
xorl %eax, %eax
callq 0x2200
jmp 0x7f31