// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/cache1d.c
// Function: kopen4load
int kopen4load(const char *filename, char searchfirst)
{
	int i, j, k, fil, newhandle;
	char bad, *gfileptr;

	newhandle = MAXOPENFILES-1;
	while (filehan[newhandle] != -1)
	{
		newhandle--;
		if (newhandle < 0)
		{
			buildprintf("TOO MANY FILES OPEN IN FILE GROUPING SYSTEM!");
			exit(0);
		}
	}

	if (searchfirst == 0)
		if ((fil = openfrompath(filename,BO_BINARY|BO_RDONLY,S_IREAD)) >= 0)
		{
			filegrp[newhandle] = 255;
			filehan[newhandle] = fil;
			filepos[newhandle] = 0;
			return(newhandle);
		}

	for (; toupperlookup[(int)(unsigned char)*filename] == '/'; filename++);
	
#ifdef WITHKPLIB
	if ((kzcurhand != newhandle) && (kztell() >= 0))
	{
		if (kzcurhand >= 0) filepos[kzcurhand] = kztell();
		kzclose();
	}
	if (searchfirst != 1 && (i = kzipopen(filename)) != 0) {
		kzcurhand = newhandle;
		filegrp[newhandle] = 254;
		filehan[newhandle] = i;
		filepos[newhandle] = 0;
		strcpy(filenamsav[newhandle],filename);
		return newhandle;
	}
#endif

	for(k=numgroupfiles-1;k>=0;k--)
	{
		if (searchfirst == 1) k = 0;
		if (groupfil[k] >= 0)
		{
			for(i=gnumfiles[k]-1;i>=0;i--)
			{
				gfileptr = (char *)&gfilelist[k][i<<4];

				bad = 0;
				for(j=0;j<13;j++)
				{
					if (!filename[j]) break;
					if (toupperlookup[(int)(unsigned char)filename[j]] != toupperlookup[(int)(unsigned char)gfileptr[j]])
						{ bad = 1; break; }
				}
				if (bad) continue;
				if (j<13 && gfileptr[j]) continue;   // JBF: because e1l1.map might exist before e1l1
				if (j==13 && filename[j]) continue;   // JBF: long file name

				filegrp[newhandle] = k;
				filehan[newhandle] = i;
				filepos[newhandle] = 0;
				return(newhandle);
			}
		}
	}
	return(-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movl $0x3f, -0x28(%rbp)
movslq -0x28(%rbp), %rcx
leaq 0xb060c(%rip), %rax     # 0xe0510
cmpl $-0x1, (%rax,%rcx,4)
je 0x2ff30
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jge 0x2ff2e
leaq 0x82113(%rip), %rdi     # 0xb2033
movb $0x0, %al
callq 0x37c90
xorl %edi, %edi
callq 0x6630
jmp 0x2fef9
movsbl -0x11(%rbp), %eax
cmpl $0x0, %eax
jne 0x2ff90
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x2f4a0
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
jl 0x2ff8e
movslq -0x28(%rbp), %rcx
leaq 0x1c1384(%rip), %rax    # 0x1f12e0
movb $-0x1, (%rax,%rcx)
movl -0x24(%rbp), %edx
movslq -0x28(%rbp), %rcx
leaq 0xb05a2(%rip), %rax     # 0xe0510
movl %edx, (%rax,%rcx,4)
movslq -0x28(%rbp), %rcx
leaq 0x1c13a4(%rip), %rax    # 0x1f1320
movl $0x0, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x301f8
jmp 0x2ff90
jmp 0x2ff92
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movslq %eax, %rcx
leaq 0xb045d(%rip), %rax     # 0xe0400
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x2ffbc
jmp 0x2ffae
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x2ff92
movl 0xb064e(%rip), %eax     # 0xe0610
cmpl -0x28(%rbp), %eax
je 0x2fff7
callq 0x69df0
cmpl $0x0, %eax
jl 0x2fff7
cmpl $0x0, 0xb0638(%rip)     # 0xe0610
jl 0x2fff2
callq 0x69df0
movl %eax, %edx
movslq 0xb0628(%rip), %rcx     # 0xe0610
leaq 0x1c1331(%rip), %rax    # 0x1f1320
movl %edx, (%rax,%rcx,4)
callq 0x69ea0
movsbl -0x11(%rbp), %eax
cmpl $0x1, %eax
je 0x30075
movq -0x10(%rbp), %rdi
callq 0x30210
movl %eax, -0x18(%rbp)
cmpl $0x0, %eax
je 0x30075
movl -0x28(%rbp), %eax
movl %eax, 0xb05f6(%rip)     # 0xe0610
movslq -0x28(%rbp), %rcx
leaq 0x1c12bb(%rip), %rax    # 0x1f12e0
movb $-0x2, (%rax,%rcx)
movl -0x18(%rbp), %edx
movslq -0x28(%rbp), %rcx
leaq 0xb04d9(%rip), %rax     # 0xe0510
movl %edx, (%rax,%rcx,4)
movslq -0x28(%rbp), %rcx
leaq 0x1c12db(%rip), %rax    # 0x1f1320
movl $0x0, (%rax,%rcx,4)
movslq -0x28(%rbp), %rax
leaq 0x1c13c9(%rip), %rdi    # 0x1f1420
imulq $0x104, %rax, %rax      # imm = 0x104
addq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x63e0
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x301f8
movl 0x1c11fd(%rip), %eax    # 0x1f1278
subl $0x1, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jl 0x301f1
movsbl -0x11(%rbp), %eax
cmpl $0x1, %eax
jne 0x3009b
movl $0x0, -0x20(%rbp)
movslq -0x20(%rbp), %rcx
leaq 0xb045a(%rip), %rax     # 0xe0500
cmpl $0x0, (%rax,%rcx,4)
jl 0x301e1
movslq -0x20(%rbp), %rcx
leaq 0x1c11d5(%rip), %rax    # 0x1f1290
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jl 0x301df
movslq -0x20(%rbp), %rcx
leaq 0x1c11c7(%rip), %rax    # 0x1f12a0
movq (%rax,%rcx,8), %rax
movl -0x18(%rbp), %ecx
shll $0x4, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movb $0x0, -0x29(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xd, -0x1c(%rbp)
jge 0x30159
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x3010e
jmp 0x30159
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movslq %eax, %rcx
leaq 0xb02dc(%rip), %rax     # 0xe0400
movsbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
movslq %ecx, %rdx
leaq 0xb02c2(%rip), %rcx     # 0xe0400
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x3014c
movb $0x1, -0x29(%rbp)
jmp 0x30159
jmp 0x3014e
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x300f8
cmpb $0x0, -0x29(%rbp)
je 0x30161
jmp 0x301d1
cmpl $0xd, -0x1c(%rbp)
jge 0x3017a
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x3017a
jmp 0x301d1
cmpl $0xd, -0x1c(%rbp)
jne 0x30193
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x30193
jmp 0x301d1
movl -0x20(%rbp), %eax
movb %al, %dl
movslq -0x28(%rbp), %rcx
leaq 0x1c113d(%rip), %rax    # 0x1f12e0
movb %dl, (%rax,%rcx)
movl -0x18(%rbp), %edx
movslq -0x28(%rbp), %rcx
leaq 0xb035c(%rip), %rax     # 0xe0510
movl %edx, (%rax,%rcx,4)
movslq -0x28(%rbp), %rcx
leaq 0x1c115e(%rip), %rax    # 0x1f1320
movl $0x0, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x301f8
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x300c4
jmp 0x301e1
jmp 0x301e3
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x30081
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)