// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/kplib.c
// Function: kzfindfile
int kzfindfile (char *filnam)
{
	int i;

	filnam[0] = 0;
	if (srchstat == -3)
	{
		if (!wildst[0]) { srchstat = -1; return(0); }
		do
		{
			srchstat = -2;

				//Extract directory from wildcard string for pre-pending
			wildstpathleng = 0;
			for(i=0;wildst[i];i++)
				if ((wildst[i] == '/') || (wildst[i] == '\\'))
					wildstpathleng = i+1;

			memcpy(filnam,wildst,wildstpathleng);

#if defined(__DOS__)
			if (_dos_findfirst(wildst,_A_SUBDIR,&findata))
				{ if (!kzhashbuf) return(0); srchstat = kzlastfnam; continue; }
			i = wildstpathleng;
			if (findata.attrib&16)
				if ((findata.name[0] == '.') && (!findata.name[1])) continue;
			strcpy(&filnam[i],findata.name);
			if (findata.attrib&16) strcat(&filnam[i],"\\");
#elif defined(_WIN32)
			hfind = FindFirstFile(wildst,&findata);
			if (hfind == INVALID_HANDLE_VALUE)
				{ if (!kzhashbuf) return(0); srchstat = kzlastfnam; continue; }
			if (findata.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN) continue;
			i = wildstpathleng;
			if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
				if ((findata.cFileName[0] == '.') && (!findata.cFileName[1])) continue;
			strcpy(&filnam[i],findata.cFileName);
			if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) strcat(&filnam[i],"\\");
#else
			if (!hfind)
			{
				char *s = ".";
				if (wildstpathleng > 0) {
					filnam[wildstpathleng] = 0;
					s = filnam;
				}
				hfind = opendir(s);
				if (!hfind) { if (!kzhashbuf) return 0; srchstat = kzlastfnam; continue; }
			}
			break;   // process srchstat == -2
#endif
			return(1);
		} while (0);
	}
	if (srchstat == -2)
		while (1)
		{
			memcpy(filnam,wildst,wildstpathleng);
#if defined(__DOS__)
			if (_dos_findnext(&findata))
				{ if (!kzhashbuf) return(0); srchstat = kzlastfnam; break; }
			i = wildstpathleng;
			if (findata.attrib&16)
				if ((findata.name[0] == '.') && (!findata.name[1])) continue;
			strcpy(&filnam[i],findata.name);
			if (findata.attrib&16) strcat(&filnam[i],"\\");
#elif defined(_WIN32)
			if (!FindNextFile(hfind,&findata))
				{ FindClose(hfind); hfind = INVALID_HANDLE_VALUE; if (!kzhashbuf) return(0); srchstat = kzlastfnam; break; }
			if (findata.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN) continue;
			i = wildstpathleng;
			if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
				if ((findata.cFileName[0] == '.') && (!findata.cFileName[1])) continue;
			strcpy(&filnam[i],findata.cFileName);
			if (findata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) strcat(&filnam[i],"\\");
#else
			struct stat st;
			if ((findata = readdir(hfind)) == NULL)
				{ closedir(hfind); hfind = NULL; if (!kzhashbuf) return 0; srchstat = kzlastfnam; break; }
			i = wildstpathleng;
			if (fstatat(dirfd(hfind), findata->d_name, &st, 0)) continue;
			if (st.st_mode & S_IFDIR)
				{ if (findata->d_name[0] == '.' && !findata->d_name[1]) continue; } //skip .
			else if ((st.st_mode & S_IFREG) || (st.st_mode & S_IFLNK))
				{ if (findata->d_name[0] == '.') continue; } //skip hidden (dot) files
			else continue; //skip devices and fifos and such
			if (!wildmatch(findata->d_name,&wildst[wildstpathleng])) continue;
			strcpy(&filnam[i],findata->d_name);
			if (st.st_mode & S_IFDIR) strcat(&filnam[i],"/");
#endif
			return(1);
		}
	while (srchstat >= 0)
	{
		if (wildmatch(&kzhashbuf[srchstat+16],wildst))
		{
			//strcpy(filnam,&kzhashbuf[srchstat+16]);
			filnam[0] = '|'; strcpy(&filnam[1],&kzhashbuf[srchstat+16]);
			srchstat = *(int *)&kzhashbuf[srchstat+4];
			return(1);
		}
		srchstat = *(int *)&kzhashbuf[srchstat+4];
	}
	return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
movb $0x0, (%rdi)
movl 0x5d11f(%rip), %eax     # 0xa4c74
cmpl $-0x3, %eax
jne 0x47c25
movb 0x56f4cc(%rip), %dl     # 0x5b7030
testb %dl, %dl
je 0x47bdc
movl $0xfffffffe, 0x5d102(%rip) # imm = 0xFFFFFFFE
movl $0x0, 0x56f5b8(%rip)    # 0x5b7134
xorl %r14d, %r14d
leaq 0x56f4aa(%rip), %rax    # 0x5b7030
xorl %ecx, %ecx
cmpb $0x2f, %dl
je 0x47b9e
movzbl %dl, %edx
cmpl $0x5c, %edx
je 0x47b9e
testl %edx, %edx
je 0x47baf
incq %rcx
jmp 0x47baa
incq %rcx
movl %ecx, 0x56f58d(%rip)    # 0x5b7134
movl %ecx, %r14d
movb (%rcx,%rax), %dl
jmp 0x47b88
movslq %r14d, %rdx
leaq 0x56f477(%rip), %rsi    # 0x5b7030
movq %rbx, %rdi
callq 0x60c0
cmpq $0x0, 0x56f45f(%rip)    # 0x5b7028
jne 0x47c2e
testl %r14d, %r14d
jle 0x47beb
movl %r14d, %eax
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
jmp 0x47bf2
movl $0xffffffff, 0x5d08e(%rip) # imm = 0xFFFFFFFF
jmp 0x47d85
leaq 0x2b7d9(%rip), %rdi     # 0x733cb
callq 0x6610
movq %rax, 0x56f42a(%rip)    # 0x5b7028
testq %rax, %rax
je 0x47c0b
movl 0x5d06b(%rip), %eax     # 0xa4c74
jmp 0x47c25
cmpq $0x0, 0x56ef95(%rip)    # 0x5b6ba8
je 0x47d85
movl 0x56f3a1(%rip), %eax    # 0x5b6fc0
movl %eax, 0x5d04f(%rip)     # 0xa4c74
cmpl $-0x2, %eax
jne 0x47d49
movslq 0x56f4ff(%rip), %rdx    # 0x5b7134
leaq 0x56f3f4(%rip), %r14    # 0x5b7030
movq %rbx, %rdi
movq %r14, %rsi
callq 0x60c0
movq 0x56f3da(%rip), %rdi    # 0x5b7028
callq 0x6810
movq %rax, 0x56f4de(%rip)    # 0x5b7138
testq %rax, %rax
je 0x47d1c
leaq 0x8(%rsp), %r15
movslq 0x56f4c5(%rip), %r13    # 0x5b7134
movq 0x56f3b2(%rip), %rdi    # 0x5b7028
callq 0x6a80
movq 0x56f4b6(%rip), %rsi    # 0x5b7138
addq $0x13, %rsi
movl %eax, %edi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x6410
testl %eax, %eax
jne 0x47cee
movl 0x20(%rsp), %ebp
btl $0xe, %ebp
jb 0x47cb9
testl $0xa000, %ebp           # imm = 0xA000
je 0x47cee
movq 0x56f489(%rip), %r12    # 0x5b7138
cmpb $0x2e, 0x13(%r12)
jne 0x47cd0
jmp 0x47cee
movq 0x56f478(%rip), %r12    # 0x5b7138
cmpb $0x2e, 0x13(%r12)
jne 0x47cd0
cmpb $0x0, 0x14(%r12)
je 0x47cee
addq $0x13, %r12
movslq 0x56f459(%rip), %rsi    # 0x5b7134
addq %r14, %rsi
movq %r12, %rdi
callq 0x47dee
testl %eax, %eax
jne 0x47dc5
movslq 0x56f43f(%rip), %rdx    # 0x5b7134
movq %rbx, %rdi
movq %r14, %rsi
callq 0x60c0
movq 0x56f321(%rip), %rdi    # 0x5b7028
callq 0x6810
movq %rax, 0x56f425(%rip)    # 0x5b7138
testq %rax, %rax
jne 0x47c68
movq 0x56f305(%rip), %rdi    # 0x5b7028
callq 0x65e0
movq $0x0, 0x56f2f5(%rip) # 0x5b7028
cmpq $0x0, 0x56ee6d(%rip)    # 0x5b6ba8
je 0x47d85
movl 0x56f27d(%rip), %eax    # 0x5b6fc0
movl %eax, 0x5cf2b(%rip)     # 0xa4c74
xorl %ebp, %ebp
testl %eax, %eax
js 0x47db1
movq 0x56ee52(%rip), %r15    # 0x5b6ba8
leaq 0x10(%r15), %r12
leaq 0x56f2cf(%rip), %r14    # 0x5b7030
movl %eax, %r13d
leaq (%r12,%r13), %rdi
movq %r14, %rsi
callq 0x47dee
testl %eax, %eax
jne 0x47d89
movl 0x4(%r15,%r13), %eax
movl %eax, 0x5cef5(%rip)     # 0xa4c74
testl %eax, %eax
jns 0x47d61
jmp 0x47db1
xorl %ebp, %ebp
jmp 0x47db1
movb $0x7c, (%rbx)
incq %rbx
leaq (%r15,%r13), %r14
addq $0x10, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6430
movl -0xc(%r14), %eax
movl %eax, 0x5cec8(%rip)     # 0xa4c74
movl $0x1, %ebp
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %r13, %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6430
btl $0xe, %ebp
movl $0x1, %ebp
jae 0x47db1
movq %rbx, %rdi
callq 0x6420
movw $0x2f, (%rbx,%rax)
jmp 0x47db1