// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0xb0243(%rip), %rax     # 0xe0510
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x1c1002(%rip), %rax    # 0x1f12e0
movzbl (%rax,%rcx), %eax
movl %eax, -0x20(%rbp)
cmpl $0x7fffffff, -0x14(%rbp) # imm = 0x7FFFFFFF
jbe 0x30305
callq 0x69c0
movl $0x16, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x30541
cmpl $0xff, -0x20(%rbp)
jne 0x30327
movl -0x1c(%rbp), %edi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %eax
movl %eax, %edx
callq 0x6750
movl %eax, -0x4(%rbp)
jmp 0x30541
cmpl $0xfe, -0x20(%rbp)
jne 0x303ae
movl 0xb02da(%rip), %eax     # 0xe0610
cmpl -0x8(%rbp), %eax
je 0x3039a
callq 0x69df0
cmpl $0x0, %eax
jl 0x30362
callq 0x69df0
movl %eax, %edx
movslq 0xb02bd(%rip), %rcx     # 0xe0610
leaq 0x1c0fc6(%rip), %rax    # 0x1f1320
movl %edx, (%rax,%rcx,4)
callq 0x69ea0
movl -0x8(%rbp), %eax
movl %eax, 0xb02a5(%rip)     # 0xe0610
movslq -0x8(%rbp), %rax
leaq 0x1c10aa(%rip), %rdi    # 0x1f1420
imulq $0x104, %rax, %rax      # imm = 0x104
addq %rax, %rdi
callq 0x30210
movslq -0x8(%rbp), %rcx
leaq 0x1c0f90(%rip), %rax    # 0x1f1320
movl (%rax,%rcx,4), %edi
xorl %esi, %esi
callq 0x69d40
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x68de0
movl %eax, -0x4(%rbp)
jmp 0x30541
jmp 0x303b0
movslq -0x20(%rbp), %rcx
leaq 0xb0145(%rip), %rax     # 0xe0500
cmpl $-0x1, (%rax,%rcx,4)
je 0x3053a
movslq -0x20(%rbp), %rcx
leaq 0x1c0ef0(%rip), %rax    # 0x1f12c0
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movslq -0x8(%rbp), %rdx
leaq 0x1c0f3a(%rip), %rcx    # 0x1f1320
addl (%rcx,%rdx,4), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movslq -0x20(%rbp), %rdx
leaq 0x1c0e86(%rip), %rcx    # 0x1f1280
cmpl (%rcx,%rdx,4), %eax
je 0x30441
movslq -0x20(%rbp), %rcx
leaq 0xb00f6(%rip), %rax     # 0xe0500
movl (%rax,%rcx,4), %edi
movl -0x18(%rbp), %eax
movslq -0x20(%rbp), %rdx
leaq 0x1c0e75(%rip), %rcx    # 0x1f1290
movl (%rcx,%rdx,4), %ecx
addl $0x1, %ecx
shll $0x4, %ecx
addl %ecx, %eax
movslq %eax, %rsi
xorl %edx, %edx
callq 0x62a0
movl -0x18(%rbp), %edx
movslq -0x20(%rbp), %rcx
leaq 0x1c0e42(%rip), %rax    # 0x1f1280
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
movslq -0x20(%rbp), %rdx
leaq 0x1c0e71(%rip), %rcx    # 0x1f12c0
movq (%rcx,%rdx,8), %rcx
movl -0x1c(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
movslq -0x20(%rbp), %rsi
leaq 0x1c0e56(%rip), %rdx    # 0x1f12c0
movq (%rdx,%rsi,8), %rdx
movslq -0x1c(%rbp), %rsi
subl (%rdx,%rsi,4), %ecx
movslq -0x8(%rbp), %rsi
leaq 0x1c0ea0(%rip), %rdx    # 0x1f1320
subl (%rdx,%rsi,4), %ecx
cmpl %ecx, %eax
jae 0x3048f
movl -0x14(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x304d1
movslq -0x20(%rbp), %rcx
leaq 0x1c0e26(%rip), %rax    # 0x1f12c0
movq (%rax,%rcx,8), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movslq -0x20(%rbp), %rdx
leaq 0x1c0e0b(%rip), %rcx    # 0x1f12c0
movq (%rcx,%rdx,8), %rcx
movslq -0x1c(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movslq -0x8(%rbp), %rdx
leaq 0x1c0e55(%rip), %rcx    # 0x1f1320
subl (%rcx,%rdx,4), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x14(%rbp)
movslq -0x20(%rbp), %rcx
leaq 0xb001e(%rip), %rax     # 0xe0500
movl (%rax,%rcx,4), %edi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %eax
movl %eax, %edx
callq 0x6750
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jle 0x30532
movl -0x18(%rbp), %edx
movslq -0x8(%rbp), %rcx
leaq 0x1c0e16(%rip), %rax    # 0x1f1320
addl (%rax,%rcx,4), %edx
leaq 0x1c0e0c(%rip), %rax    # 0x1f1320
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %edx
movslq -0x20(%rbp), %rcx
leaq 0x1c0d5b(%rip), %rax    # 0x1f1280
addl (%rax,%rcx,4), %edx
leaq 0x1c0d51(%rip), %rax    # 0x1f1280
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x30541
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)