// File: /workspace/github_c_makefile_star2_O1/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 0x20218
movl %edx, %ebp
movq %rsi, %rbx
movl %edi, %r14d
movslq %edi, %r15
leaq 0x19359d(%rip), %rax    # 0x1b3780
movzbl (%r15,%rax), %r12d
cmpq $0xfe, %r12
je 0x20237
leaq 0x82e58(%rip), %rax     # 0xa3050
movslq (%rax,%r15,4), %r14
cmpl $0xff, %r12d
jne 0x202af
movl %ebp, %edx
movl %r14d, %edi
movq %rbx, %rsi
callq 0x6800
jmp 0x20228
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, 0x82f12(%rip)    # 0xa3150
je 0x20297
callq 0x47c82
testl %eax, %eax
js 0x20264
callq 0x47c82
movslq 0x82efb(%rip), %rcx     # 0xa3150
leaq 0x193564(%rip), %rdx    # 0x1b37c0
movl %eax, (%rdx,%rcx,4)
callq 0x47ce0
movl %r14d, 0x82ee5(%rip)    # 0xa3150
movq %r15, %rax
shlq $0x8, %rax
leaq (%rax,%r15,4), %rax
leaq 0x193643(%rip), %rdi    # 0x1b38c0
addq %rax, %rdi
callq 0x20173
leaq 0x193534(%rip), %rax    # 0x1b37c0
movl (%rax,%r15,4), %edi
xorl %esi, %esi
callq 0x47c41
movq %rbx, %rdi
movl %ebp, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x45c69
leaq 0x82d8a(%rip), %rsi     # 0xa3040
movl (%rsi,%r12,4), %edi
cmpl $-0x1, %edi
je 0x20377
leaq 0x193496(%rip), %rdx    # 0x1b3760
movq (%rdx,%r12,8), %rax
leaq 0x1934eb(%rip), %rcx    # 0x1b37c0
movl (%rcx,%r15,4), %r13d
addl (%rax,%r14,4), %r13d
leaq 0x19343c(%rip), %rax    # 0x1b3720
cmpl (%rax,%r12,4), %r13d
je 0x20330
leaq 0x19343f(%rip), %rax    # 0x1b3730
leal (,%r12,4), %ecx
movq %rcx, (%rsp)
movl (%rcx,%rax), %eax
shll $0x4, %eax
addl %r13d, %eax
addl $0x10, %eax
movslq %eax, %rsi
xorl %edx, %edx
callq 0x62b0
leaq 0x193446(%rip), %rdx    # 0x1b3760
leaq 0x82d1f(%rip), %rsi     # 0xa3040
leaq 0x1933f8(%rip), %rax    # 0x1b3720
movq (%rsp), %rcx
movl %r13d, (%rcx,%rax)
movq (%rdx,%r12,8), %rax
movl (%rax,%r14,4), %ecx
movl 0x4(%rax,%r14,4), %edx
leaq 0x19347c(%rip), %r14    # 0x1b37c0
addl (%r14,%r15,4), %ecx
subl %ecx, %edx
cmpl %ebp, %edx
cmovael %ebp, %edx
movl (%rsi,%r12,4), %edi
movq %rbx, %rsi
callq 0x6800
testl %eax, %eax
jle 0x20228
addl %eax, (%r14,%r15,4)
leaq 0x1933b2(%rip), %rcx    # 0x1b3720
addl %eax, (%rcx,%r12,4)
jmp 0x20228
xorl %eax, %eax
jmp 0x20228