// File: /workspace/github_c_makefile_star2_O2/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 0x1de95
movl %edx, %ebp
movq %rsi, %rbx
movl %edi, %r14d
movslq %edi, %r15
leaq 0x18f920(%rip), %rax    # 0x1ad780
movzbl (%r15,%rax), %r12d
cmpq $0xfe, %r12
je 0x1deb2
leaq 0x7f1db(%rip), %rax     # 0x9d050
movslq (%rax,%r15,4), %r14
cmpl $0xff, %r12d
jne 0x1df26
movl %ebp, %edx
movl %r14d, %edi
movq %rbx, %rsi
callq 0x6800
jmp 0x1dea3
callq 0x6a90
movl $0x16, (%rax)
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r14d, 0x7f297(%rip)    # 0x9d150
je 0x1df0e
callq 0x41773
testl %eax, %eax
js 0x1dedf
callq 0x41773
movslq 0x7f280(%rip), %rcx     # 0x9d150
leaq 0x18f8e9(%rip), %rdx    # 0x1ad7c0
movl %eax, (%rdx,%rcx,4)
callq 0x417cf
movl %r14d, 0x7f26a(%rip)    # 0x9d150
imulq $0x104, %r15, %rax      # imm = 0x104
leaq 0x18f9cc(%rip), %rdi    # 0x1ad8c0
addq %rax, %rdi
callq 0x1de05
leaq 0x18f8bd(%rip), %rax    # 0x1ad7c0
movl (%rax,%r15,4), %edi
xorl %esi, %esi
callq 0x4172f
movq %rbx, %rdi
movl %ebp, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40c51
leaq 0x7f113(%rip), %rax     # 0x9d040
movl (%rax,%r12,4), %edi
cmpl $-0x1, %edi
je 0x1dff6
leaq 0x18f81f(%rip), %rax    # 0x1ad760
movq (%rax,%r12,8), %rax
leaq 0x18f874(%rip), %rcx    # 0x1ad7c0
movl (%rcx,%r15,4), %r13d
addl (%rax,%r14,4), %r13d
leaq 0x18f7c5(%rip), %rcx    # 0x1ad720
cmpl (%rcx,%r12,4), %r13d
je 0x1dfbe
leaq 0x18f7c8(%rip), %rax    # 0x1ad730
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 0x18f78a(%rip), %rax    # 0x1ad720
movl %r13d, (%rcx,%rax)
leaq 0x18f7bf(%rip), %rax    # 0x1ad760
movq (%rax,%r12,8), %rax
movl (%rax,%r14,4), %r13d
leaq 0x7f090(%rip), %rdx     # 0x9d040
movl (%rcx,%rdx), %edi
leaq 0x18f806(%rip), %rcx    # 0x1ad7c0
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 0x1dea3
leaq 0x18f7de(%rip), %rcx    # 0x1ad7c0
addl %eax, (%rcx,%r15,4)
leaq 0x18f733(%rip), %rcx    # 0x1ad720
addl %eax, (%rcx,%r12,4)
jmp 0x1dea3
xorl %eax, %eax
jmp 0x1dea3