// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/cache1d.c
// Function: kread
int kread(int handle, void *buffer, unsigned leng)
{
	int i, filenum, groupnum;

	filenum = filehan[handle];
	groupnum = filegrp[handle];
	if (leng > INT_MAX) { errno = EINVAL; return -1; }
	if (groupnum == 255) return((int)read(filenum,buffer,leng));
#ifdef WITHKPLIB
	else if (groupnum == 254)
	{
		if (kzcurhand != handle)
		{
			if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); }
			kzcurhand = handle;
			kzipopen(filenamsav[handle]);
			kzseek(filepos[handle],SEEK_SET);
		}
		return(kzread(buffer,leng));
	}
#endif

	if (groupfil[groupnum] != -1)
	{
		i = gfileoffs[groupnum][filenum]+filepos[handle];
		if (i != groupfilpos[groupnum])
		{
			lseek(groupfil[groupnum],i+((gnumfiles[groupnum]+1)<<4),SEEK_SET);
			groupfilpos[groupnum] = i;
		}
		leng = min(leng,(gfileoffs[groupnum][filenum+1]-gfileoffs[groupnum][filenum])-filepos[handle]);
		i = (int)read(groupfil[groupnum],buffer,leng);
		if (i > 0) {
			filepos[handle] += i;
			groupfilpos[groupnum] += i;
		}
		return(i);
	}

	return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testl %edx, %edx
js 0x206da
movl %edx, %ebp
movq %rsi, %rbx
movl %edi, %r14d
movslq %edi, %r15
leaq 0x1940db(%rip), %rax    # 0x1b4780
movzbl (%r15,%rax), %r12d
cmpq $0xfe, %r12
je 0x206f9
leaq 0x83996(%rip), %rax     # 0xa4050
movslq (%rax,%r15,4), %r14
cmpl $0xff, %r12d
jne 0x20771
movl %ebp, %edx
movl %r14d, %edi
movq %rbx, %rsi
callq 0x6800
jmp 0x206ea
callq 0x6a90
movl $0x16, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r14d, 0x83a50(%rip)    # 0xa4150
je 0x20759
callq 0x49f1b
testl %eax, %eax
js 0x20726
callq 0x49f1b
movslq 0x83a39(%rip), %rcx     # 0xa4150
leaq 0x1940a2(%rip), %rdx    # 0x1b47c0
movl %eax, (%rdx,%rcx,4)
callq 0x49f79
movl %r14d, 0x83a23(%rip)    # 0xa4150
movq %r15, %rax
shlq $0x8, %rax
leaq (%rax,%r15,4), %rax
leaq 0x194181(%rip), %rdi    # 0x1b48c0
addq %rax, %rdi
callq 0x20635
leaq 0x194072(%rip), %rax    # 0x1b47c0
movl (%rax,%r15,4), %edi
xorl %esi, %esi
callq 0x49ed5
movq %rbx, %rdi
movl %ebp, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x47ea9
leaq 0x838c8(%rip), %rax     # 0xa4040
movl (%rax,%r12,4), %edi
cmpl $-0x1, %edi
je 0x20841
leaq 0x193fd4(%rip), %rax    # 0x1b4760
movq (%rax,%r12,8), %rax
leaq 0x194029(%rip), %rcx    # 0x1b47c0
movl (%rcx,%r15,4), %r13d
addl (%rax,%r14,4), %r13d
leaq 0x193f7a(%rip), %rcx    # 0x1b4720
cmpl (%rcx,%r12,4), %r13d
je 0x20809
leaq 0x193f7d(%rip), %rax    # 0x1b4730
leal (,%r12,4), %r9d
movq %r9, (%rsp)
movl (%r9,%rax), %eax
shll $0x4, %eax
addl %r13d, %eax
addl $0x10, %eax
movslq %eax, %rsi
xorl %edx, %edx
callq 0x62b0
movq (%rsp), %rcx
leaq 0x193f3f(%rip), %rax    # 0x1b4720
movl %r13d, (%rcx,%rax)
leaq 0x193f74(%rip), %rax    # 0x1b4760
movq (%rax,%r12,8), %rax
movl (%rax,%r14,4), %r13d
leaq 0x83845(%rip), %rdx     # 0xa4040
movl (%rcx,%rdx), %edi
leaq 0x193fbb(%rip), %rcx    # 0x1b47c0
addl (%rcx,%r15,4), %r13d
movl 0x4(%rax,%r14,4), %edx
subl %r13d, %edx
cmpl %ebp, %edx
cmovael %ebp, %edx
movq %rbx, %rsi
callq 0x6800
testl %eax, %eax
jle 0x206ea
leaq 0x193f93(%rip), %rcx    # 0x1b47c0
addl %eax, (%rcx,%r15,4)
leaq 0x193ee8(%rip), %rcx    # 0x1b4720
addl %eax, (%rcx,%r12,4)
jmp 0x206ea
xorl %eax, %eax
jmp 0x206ea