// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/kplib.c
// Function: kpgetdim
int kpgetdim (const char *buf, int leng, int *xsiz, int *ysiz)
{
	int *lptr;
	const unsigned char *cptr;
	unsigned char *ubuf = (unsigned char *)buf;

	(*xsiz) = (*ysiz) = 0; if (leng < 16) return(-1);
	if ((ubuf[0] == 0x89) && (ubuf[1] == 0x50)) //.PNG
	{
		lptr = (int *)buf;
		if ((lptr[0] != LSWAPIB(0x474e5089)) || (lptr[1] != LSWAPIB(0x0a1a0a0d))) return(-1);
		lptr = &lptr[2];
		while (((uintptr_t)lptr-(uintptr_t)buf) < (uintptr_t)(leng-16))
		{
			if (lptr[1] == LSWAPIB(0x52444849)) //IHDR
				{ (*xsiz) = LSWAPIL(lptr[2]); (*ysiz) = LSWAPIL(lptr[3]); break; }
			lptr = (int *)((intptr_t)lptr + LSWAPIL(lptr[0]) + 12);
		}
	}
	else if ((ubuf[0] == 0xff) && (ubuf[1] == 0xd8)) //.JPG
	{
		cptr = (unsigned char *)&buf[2];
		while (((uintptr_t)cptr-(uintptr_t)buf) < (uintptr_t)(leng-8))
		{
			if (cptr[0] != 255) { cptr = &cptr[1]; continue; }
			if ((unsigned int)(cptr[1]-0xc0) < 3)
			{
				(*ysiz) = SSWAPIL(*(unsigned short *)&cptr[5]);
				(*xsiz) = SSWAPIL(*(unsigned short *)&cptr[7]);
				break;
			}
			cptr = &cptr[SSWAPIL(*(unsigned short *)&cptr[2])+2];
		}
	}
	else if ((ubuf[0] == 'G') && (ubuf[1] == 'I') && (ubuf[2] == 'F') && (ubuf[12] == 0)) //.GIF
	{
		(*xsiz) = (int)SSWAPIB(*(unsigned short *)&buf[6]);
		(*ysiz) = (int)SSWAPIB(*(unsigned short *)&buf[8]);
	}
	else if ((ubuf[0] == 0x19) && (ubuf[1] == 0x91) && (ubuf[10] == 8) && (ubuf[11] == 0)) //old .CEL/.PIC
	{
		(*xsiz) = (int)SSWAPIB(*(unsigned short *)&buf[2]);
		(*ysiz) = (int)SSWAPIB(*(unsigned short *)&buf[4]);
	}
	else if ((ubuf[0] == 'B') && (ubuf[1] == 'M')) //.BMP
	{
		if (*(int *)(&buf[14]) == LSWAPIB(12)) //OS/2 1.x (old format)
		{
			if (*(short *)(&buf[22]) != SSWAPIB(1)) return(-1);
			(*xsiz) = (int)SSWAPIB(*(unsigned short *)&buf[18]);
			(*ysiz) = (int)SSWAPIB(*(unsigned short *)&buf[20]);
		}
		else //All newer formats...
		{
			if (*(short *)(&buf[26]) != SSWAPIB(1)) return(-1);
			(*xsiz) = LSWAPIB(*(int *)&buf[18]);
			(*ysiz) = LSWAPIB(*(int *)&buf[22]);
		}
	}
	else if (*(int *)ubuf == LSWAPIB(0x0801050a)) //.PCX
	{
		(*xsiz) = SSWAPIB(*(short *)&buf[ 8])-SSWAPIB(*(short *)&buf[4])+1;
		(*ysiz) = SSWAPIB(*(short *)&buf[10])-SSWAPIB(*(short *)&buf[6])+1;
	}
	else if ((*(int *)ubuf == LSWAPIB(0x20534444)) && (*(int *)&ubuf[4] == LSWAPIB(124))) //.DDS
	{
		(*xsiz) = LSWAPIB(*(int *)&buf[16]);
		(*ysiz) = LSWAPIB(*(int *)&buf[12]);
	}
	else
	{     //Unreliable .TGA identification - this MUST be final case!
		if ((leng >= 20) && (!(ubuf[1]&0xfe)))
			if ((ubuf[2] < 12) && ((1<<ubuf[2])&0xe0e))
				if ((!(ubuf[16]&7)) && (ubuf[16] != 0) && (ubuf[16] <= 32))
					if (!(buf[17]&0xc0))
					{
						(*xsiz) = (int)SSWAPIB(*(unsigned short *)&buf[12]);
						(*ysiz) = (int)SSWAPIB(*(unsigned short *)&buf[14]);
					}
	}
	return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
cmpl $0x10, -0x14(%rbp)
jge 0x61c85
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x620b3
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x89, %eax
jne 0x61d5e
movq -0x40(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x50, %eax
jne 0x61d5e
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x474e5089, (%rax)     # imm = 0x474E5089
jne 0x61cc9
movq -0x30(%rbp), %rax
cmpl $0xa1a0a0d, 0x4(%rax)   # imm = 0xA1A0A0D
je 0x61cd5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x620b3
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movl -0x14(%rbp), %ecx
subl $0x10, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jae 0x61d59
movq -0x30(%rbp), %rax
cmpl $0x52444849, 0x4(%rax)  # imm = 0x52444849
jne 0x61d31
movq -0x30(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x620c0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl 0xc(%rax), %edi
callq 0x620c0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x61d59
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %edi
callq 0x620c0
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
addq $0xc, %rax
movq %rax, -0x30(%rbp)
jmp 0x61ce1
jmp 0x620ac
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xff, %eax
jne 0x61e3e
movq -0x40(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0xd8, %eax
jne 0x61e3e
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movl -0x14(%rbp), %ecx
subl $0x8, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jae 0x61e39
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xff, %eax
je 0x61dc8
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x61d8f
movq -0x38(%rbp), %rax
movzbl 0x1(%rax), %eax
subl $0xc0, %eax
cmpl $0x3, %eax
jae 0x61e08
movq -0x38(%rbp), %rax
movzwl 0x5(%rax), %edi
callq 0x62100
movzwl %ax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movzwl 0x7(%rax), %edi
callq 0x62100
movzwl %ax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x61e39
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movzwl 0x2(%rax), %edi
callq 0x62100
movw %ax, %cx
movq -0x50(%rbp), %rax
movzwl %cx, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
jmp 0x61d8f
jmp 0x620aa
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x47, %eax
jne 0x61e92
movq -0x40(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x49, %eax
jne 0x61e92
movq -0x40(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x46, %eax
jne 0x61e92
movq -0x40(%rbp), %rax
movzbl 0xc(%rax), %eax
cmpl $0x0, %eax
jne 0x61e92
movq -0x10(%rbp), %rax
movzwl 0x6(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movzwl 0x8(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x620a8
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x19, %eax
jne 0x61ee8
movq -0x40(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x91, %eax
jne 0x61ee8
movq -0x40(%rbp), %rax
movzbl 0xa(%rax), %eax
cmpl $0x8, %eax
jne 0x61ee8
movq -0x40(%rbp), %rax
movzbl 0xb(%rax), %eax
cmpl $0x0, %eax
jne 0x61ee8
movq -0x10(%rbp), %rax
movzwl 0x2(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movzwl 0x4(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x620a6
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x42, %eax
jne 0x61f7e
movq -0x40(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x4d, %eax
jne 0x61f7e
movq -0x10(%rbp), %rax
cmpl $0xc, 0xe(%rax)
jne 0x61f46
movq -0x10(%rbp), %rax
movswl 0x16(%rax), %eax
cmpl $0x1, %eax
je 0x61f28
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x620b3
movq -0x10(%rbp), %rax
movzwl 0x12(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movzwl 0x14(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x61f79
movq -0x10(%rbp), %rax
movswl 0x1a(%rax), %eax
cmpl $0x1, %eax
je 0x61f5f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x620b3
movq -0x10(%rbp), %rax
movl 0x12(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl 0x16(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x620a4
movq -0x40(%rbp), %rax
cmpl $0x801050a, (%rax)      # imm = 0x801050A
jne 0x61fc5
movq -0x10(%rbp), %rax
movswl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
movswl 0x4(%rax), %eax
subl %eax, %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movswl 0xa(%rax), %ecx
movq -0x10(%rbp), %rax
movswl 0x6(%rax), %eax
subl %eax, %ecx
addl $0x1, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x620a2
movq -0x40(%rbp), %rax
cmpl $0x20534444, (%rax)     # imm = 0x20534444
jne 0x61ffa
movq -0x40(%rbp), %rax
cmpl $0x7c, 0x4(%rax)
jne 0x61ffa
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x620a0
cmpl $0x14, -0x14(%rbp)
jl 0x6209e
movq -0x40(%rbp), %rax
movzbl 0x1(%rax), %eax
andl $0xfe, %eax
cmpl $0x0, %eax
jne 0x6209e
movq -0x40(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0xc, %eax
jge 0x6209c
movq -0x40(%rbp), %rax
movzbl 0x2(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
andl $0xe0e, %eax            # imm = 0xE0E
cmpl $0x0, %eax
je 0x6209c
movq -0x40(%rbp), %rax
movzbl 0x10(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
jne 0x6209a
movq -0x40(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x0, %eax
je 0x6209a
movq -0x40(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x20, %eax
jg 0x6209a
movq -0x10(%rbp), %rax
movsbl 0x11(%rax), %eax
andl $0xc0, %eax
cmpl $0x0, %eax
jne 0x62098
movq -0x10(%rbp), %rax
movzwl 0xc(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movzwl 0xe(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x6209a
jmp 0x6209c
jmp 0x6209e
jmp 0x620a0
jmp 0x620a2
jmp 0x620a4
jmp 0x620a6
jmp 0x620a8
jmp 0x620aa
jmp 0x620ac
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)