// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/kplib.c
// Function: kcelrend
static int kcelrend (const char *buf, int fleng,
	intptr_t daframeplace, int dabytesperline, int daxres, int dayres,
	int daglobxoffs, int daglobyoffs)
{
	int i, x, y, x0, x1, y0, y1, xsiz, ysiz;
	const unsigned char *cptr;

	(void)fleng; (void)daglobxoffs;

	if (((unsigned char)buf[0] != 0x19) || ((unsigned char)buf[1] != 0x91) ||
		 ((unsigned char)buf[10] != 8) || ((unsigned char)buf[11] != 0)) return(-1);

	coltype = 3; bitdepth = 8; paleng = 256; //For PNGOUT

	xsiz = (int)SSWAPIB(*(unsigned short *)&buf[2]); if (xsiz <= 0) return(-1);
	ysiz = (int)SSWAPIB(*(unsigned short *)&buf[4]); if (ysiz <= 0) return(-1);

	cptr = (unsigned char *)&buf[32];
	for(i=0;i<256;i++)
	{
		palcol[i] = (((int)cptr[0])<<18) +
						(((int)cptr[1])<<10) +
						(((int)cptr[2])<< 2) + LSWAPIB(0xff000000);
		cptr += 3;
	}

	x0 = daglobyoffs; x1 = xsiz+daglobyoffs;
	y0 = daglobyoffs; y1 = ysiz+daglobyoffs;
	for(y=y0;y<y1;y++)
		for(x=x0;x<x1;x++)
		{
			if (((unsigned int)x < (unsigned int)daxres) && ((unsigned int)y < (unsigned int)dayres))
				*(int *)(y*dabytesperline+x*4+daframeplace) = palcol[cptr[0]];
			cptr++;
		}
	return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x19, %eax
jne 0x66105
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x91, %eax
jne 0x66105
movq -0x10(%rbp), %rax
movzbl 0xa(%rax), %eax
cmpl $0x8, %eax
jne 0x66105
movq -0x10(%rbp), %rax
movzbl 0xb(%rax), %eax
cmpl $0x0, %eax
je 0x66111
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6626d
movb $0x3, 0x55cc68(%rip)    # 0x5c2d80
movb $0x8, 0x55cc62(%rip)    # 0x5c2d81
movl $0x100, 0x542a27(%rip)  # imm = 0x100
movq -0x10(%rbp), %rax
movzwl 0x2(%rax), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jg 0x66146
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6626d
movq -0x10(%rbp), %rax
movzwl 0x4(%rax), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jg 0x66163
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6626d
movq -0x10(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x100, -0x30(%rbp)     # imm = 0x100
jge 0x661ce
movq -0x58(%rbp), %rax
movzbl (%rax), %edx
shll $0x12, %edx
movq -0x58(%rbp), %rax
movzbl 0x1(%rax), %eax
shll $0xa, %eax
addl %eax, %edx
movq -0x58(%rbp), %rax
movzbl 0x2(%rax), %eax
shll $0x2, %eax
addl %eax, %edx
addl $0xff000000, %edx       # imm = 0xFF000000
movslq -0x30(%rbp), %rcx
leaq 0x55c7cc(%rip), %rax    # 0x5c2980
movl %edx, (%rax,%rcx,4)
movq -0x58(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x58(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x66176
movl 0x18(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x4c(%rbp), %eax
addl 0x18(%rbp), %eax
movl %eax, -0x40(%rbp)
movl 0x18(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x50(%rbp), %eax
addl 0x18(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x66266
movl -0x3c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x66259
movl -0x34(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x66242
movl -0x38(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x66242
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0x55c758(%rip), %rax    # 0x5c2980
movl (%rax,%rcx,4), %ecx
movl -0x38(%rbp), %eax
imull -0x24(%rbp), %eax
movl -0x34(%rbp), %edx
shll $0x2, %edx
addl %edx, %eax
cltq
addq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x66200
jmp 0x6625b
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x661f2
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)