// File: /workspace/github_c_makefile_star2_O1/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)
cmpl $-0x3, 0x5e394(%rip)    # 0xa3c74
jne 0x45955
cmpb $0x0, 0x570747(%rip)    # 0x5b6030
je 0x45b01
movl $0xfffffffe, 0x5e37b(%rip) # imm = 0xFFFFFFFE
movl $0x0, 0x570831(%rip)    # 0x5b6134
xorl %eax, %eax
leaq 0x570724(%rip), %rcx    # 0x5b6030
movzbl (%rax,%rcx), %edx
cmpl $0x2f, %edx
je 0x45920
cmpl $0x5c, %edx
je 0x45920
testl %edx, %edx
jne 0x45929
jmp 0x4592e
leal 0x1(%rax), %edx
movl %edx, 0x57080b(%rip)    # 0x5b6134
incq %rax
jmp 0x4590c
movslq 0x5707ff(%rip), %r14    # 0x5b6134
leaq 0x5706f4(%rip), %rsi    # 0x5b6030
movq %rbx, %rdi
movq %r14, %rdx
callq 0x60c0
cmpq $0x0, 0x5706d9(%rip)    # 0x5b6028
je 0x45b46
cmpl $-0x2, 0x5e318(%rip)    # 0xa3c74
jne 0x45ab7
movl $0x0, 0x4(%rsp)
leaq 0x5706bf(%rip), %r14    # 0x5b6030
movslq 0x5707bc(%rip), %rdx    # 0x5b6134
movq %rbx, %rdi
movq %r14, %rsi
callq 0x60c0
movq 0x57069e(%rip), %rdi    # 0x5b6028
callq 0x6810
movq %rax, 0x5707a2(%rip)    # 0x5b6138
testq %rax, %rax
je 0x459fd
movslq 0x570792(%rip), %r12    # 0x5b6134
movq 0x57067f(%rip), %rdi    # 0x5b6028
callq 0x6a80
movq 0x570783(%rip), %rsi    # 0x5b6138
addq $0x13, %rsi
movl %eax, %edi
leaq 0x8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x6410
movl $0x7, %r15d
testl %eax, %eax
jne 0x45aa7
movl 0x20(%rsp), %ebp
btl $0xe, %ebp
jb 0x45a42
testl $0xa000, %ebp           # imm = 0xA000
je 0x45aa7
movq 0x570746(%rip), %rax    # 0x5b6138
cmpb $0x2e, 0x13(%rax)
jne 0x45a55
jmp 0x45aa7
movq 0x570624(%rip), %rdi    # 0x5b6028
callq 0x65e0
movq $0x0, 0x570614(%rip) # 0x5b6028
cmpq $0x0, 0x57018c(%rip)    # 0x5b5ba8
je 0x45a32
movl 0x57059c(%rip), %eax    # 0x5b5fc0
movl %eax, 0x5e24a(%rip)     # 0xa3c74
movl $0x8, %r15d
jmp 0x45aa7
movl $0x1, %r15d
movl $0x0, 0x4(%rsp)
jmp 0x45aa7
movq 0x5706ef(%rip), %rax    # 0x5b6138
cmpb $0x2e, 0x13(%rax)
jne 0x45a55
cmpb $0x0, 0x14(%rax)
je 0x45aa7
movq 0x5706dc(%rip), %r13    # 0x5b6138
addq $0x13, %r13
movslq 0x5706cd(%rip), %rsi    # 0x5b6134
addq %r14, %rsi
movq %r13, %rdi
callq 0x45ba9
testl %eax, %eax
je 0x45aa7
addq %rbx, %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x6430
btl $0xe, %ebp
movl $0x1, 0x4(%rsp)
jae 0x45aa1
movq %r12, %rdi
callq 0x6420
movw $0x2f, (%r12,%rax)
movl $0x1, %r15d
cmpl $0x7, %r15d
je 0x45971
cmpl $0x8, %r15d
jne 0x45afb
movl 0x5e1b7(%rip), %eax     # 0xa3c74
xorl %edx, %edx
testl %eax, %eax
js 0x45b32
movq 0x5700de(%rip), %r15    # 0x5b5ba8
leaq 0x10(%r15), %r12
leaq 0x57055b(%rip), %r14    # 0x5b6030
movl %eax, %r13d
leaq (%r12,%r13), %rdi
movq %r14, %rsi
callq 0x45ba9
testl %eax, %eax
jne 0x45b0a
movl 0x4(%r15,%r13), %eax
movl %eax, 0x5e181(%rip)     # 0xa3c74
testl %eax, %eax
jns 0x45ad5
xorl %edx, %edx
jmp 0x45b32
movl 0x4(%rsp), %edx
jmp 0x45b32
xorl %edx, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x45b2c
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 $0x1, %edx
movl %eax, 0x5e142(%rip)     # 0xa3c74
movl %edx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r14d, %r14d
jle 0x45b55
movb $0x0, (%rbx,%r14)
movq %rbx, %rdi
jmp 0x45b5c
leaq 0x2c823(%rip), %rdi     # 0x7237f
callq 0x6610
movq %rax, 0x5704c0(%rip)    # 0x5b6028
xorl %edx, %edx
movl $0x0, %ecx
testq %rax, %rax
jne 0x45b96
cmpq $0x0, 0x57002c(%rip)    # 0x5b5ba8
je 0x45b91
movl 0x57043c(%rip), %eax    # 0x5b5fc0
movl %eax, 0x5e0ea(%rip)     # 0xa3c74
movl $0x3, %ecx
jmp 0x45b96
movl $0x1, %ecx
cmpl $0x3, %ecx
je 0x45955
testl %ecx, %ecx
je 0x45955
jmp 0x45b32