// File: /workspace/github_c_makefile_star2_O1/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, (%rsp)
movq %rdi, %r14
movl $0x7c, %esi
callq 0x2110
movq %rax, %rbx
testq %rax, %rax
jne 0x8fc6
movq %r14, %rdi
movl $0x2f, %esi
callq 0x2110
movq %rax, %rbx
testq %rbx, %rbx
je 0x8ff7
incq %rbx
movl %r14d, %eax
notl %eax
addl %ebx, %eax
movslq %eax, %r15
leaq 0x10cf11(%rip), %r12    # 0x115ef0
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2070
movb $0x0, (%r15,%r12)
movq %rbx, %r14
jmp 0x901a
movzbl 0xb212(%rip), %eax      # 0x14210
leaq 0x10b43b(%rip), %rcx    # 0x114440
movq (%rcx,%rax,8), %rsi
leaq 0x10cee0(%rip), %rdi    # 0x115ef0
movl $0x104, %edx            # imm = 0x104
callq 0x2070
leaq 0x10cfdf(%rip), %rdi    # 0x116000
movl $0x103, %edx            # imm = 0x103
movq %r14, %rsi
callq 0x2070
cmpl $0x2a2e2a, 0x10cfc8(%rip) # imm = 0x2A2E2A
jne 0x9043
movw $0x2a, 0x10cfbd(%rip)   # 0x116000
movb 0x10cfb7(%rip), %bl     # 0x116000
testb %bl, %bl
je 0x9071
leaq 0x10cfad(%rip), %r14    # 0x116001
callq 0x2030
movq (%rax), %rcx
movsbq %bl, %rdx
movb (%rcx,%rdx,4), %cl
movb %cl, -0x1(%r14)
movb (%r14), %bl
incq %r14
testb %bl, %bl
jne 0x9059
leaq 0x10ce78(%rip), %rdi    # 0x115ef0
callq 0x20d0
testq %rax, %rax
je 0x9141
movq %rax, %r14
movq %rax, %rdi
callq 0x2280
testq %rax, %rax
je 0x9139
movq %rax, %rbx
movq (%rsp), %rax
leaq 0x18(%rax), %r15
leaq 0x10cf54(%rip), %r12    # 0x116000
leaq 0x13(%rbx), %r13
movl $0x103, %edx            # imm = 0x103
movq %r15, %rdi
movq %r13, %rsi
callq 0x2070
movb 0x13(%rbx), %bpl
testb %bpl, %bpl
je 0x90ea
callq 0x2030
addq $0x14, %rbx
movq (%rax), %rcx
movsbq %bpl, %rdx
movb (%rcx,%rdx,4), %cl
movb %cl, -0x1(%rbx)
movb (%rbx), %bpl
incq %rbx
testb %bpl, %bpl
jne 0x90d2
movq %r12, %rdi
movq %r13, %rsi
movl $0x10, %edx
callq 0x2140
testl %eax, %eax
jne 0x9125
leaq 0x10cdeb(%rip), %rdi    # 0x115ef0
movq %r15, %rsi
callq 0x85e1
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x2240
testl %eax, %eax
jne 0x9164
testb $0x40, 0x21(%rsp)
je 0x9192
movq %r14, %rdi
callq 0x2280
movq %rax, %rbx
testq %rax, %rax
jne 0x90ac
movq %r14, %rdi
callq 0x21a0
movq $0x0, 0x10cd94(%rip) # 0x115ee0
xorl %r14d, %r14d
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x21a0
cmpl $0x0, 0x10b1a1(%rip)    # 0x114314
je 0x9141
movq 0xae7c(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x7c41(%rip), %rsi      # 0x10dc7
movq %r15, %rdx
xorl %eax, %eax
callq 0x2210
jmp 0x9141
movq (%rsp), %rcx
movb $0x0, 0x11c(%rcx)
xorl %eax, %eax
cmpb $0x2e, 0x18(%rcx)
sete %al
addl %eax, %eax
movq %rax, (%rcx)
movq $0x0, 0x8(%rcx)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rcx)
jmp 0x914f