// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/kplib.c
// Function: putbuf
static void putbuf (const unsigned char *buf, int leng)
{
	int i, x;
	intptr_t p;

	if (filt < 0)
	{
		if (leng <= 0) return;
		filt = buf[0];
		if (filter1st < 0) filter1st = filt; else filterest |= (1<<filt);
		if (filt == gotcmov) filt = 5;
		i = 1;
	} else i = 0;

	while (i < leng)
	{
		x = i+xplc; if (x > leng) x = leng;
		switch (filt)
		{
			case 0:
				while (i < x) { olinbuf[xplc] = buf[i]; xplc--; i++; }
				break;
			case 1:
				while (i < x)
				{
					olinbuf[xplc] = (opixbuf1[xm] += buf[i]);
					xm = xmn[xm]; xplc--; i++;
				}
				break;
			case 2:
				while (i < x) { olinbuf[xplc] += buf[i]; xplc--; i++; }
				break;
			case 3:
				while (i < x)
				{
					opixbuf1[xm] = olinbuf[xplc] = ((opixbuf1[xm]+olinbuf[xplc])>>1)+buf[i];
					xm = xmn[xm]; xplc--; i++;
				}
				break;
			case 4:
				while (i < x)
				{
					opixbuf1[xm] = (unsigned char)(Paeth(opixbuf1[xm],olinbuf[xplc],opixbuf0[xm])+buf[i]);
					opixbuf0[xm] = olinbuf[xplc];
					olinbuf[xplc] = opixbuf1[xm];
					xm = xmn[xm]; xplc--; i++;
				}
				break;
			case 5: //Special hack for Paeth686 (Doesn't have to be case 5)
				while (i < x)
				{
					opixbuf1[xm] = (unsigned char)(Paeth686(opixbuf1[xm],olinbuf[xplc],opixbuf0[xm])+buf[i]);
					opixbuf0[xm] = olinbuf[xplc];
					olinbuf[xplc] = opixbuf1[xm];
					xm = xmn[xm]; xplc--; i++;
				}
				break;
		}

		if (xplc > 0) return;

			//Draw line!
		if ((unsigned int)yplc < (unsigned int)yres)
		{
			x = xr0; p = nfplace;
			switch (coltype)
			{
				case 2:
					rgbhlineasm(x,xr1,p,ixstp);
					break;
				case 4:
					for(;x>xr1;p+=ixstp,x-=2)
					{
#if (PROCESSALPHAHERE == 1)
							//Enable this code to process alpha right here!
						if (olinbuf[x-1] == 255) { *(int *)p = palcol[olinbuf[x]]; continue; }
						if (!olinbuf[x-1]) { *(int *)p = bakcol; continue; }
							//I do >>8, but theoretically should be: /255
						*(unsigned char *)(p) = *(unsigned char *)(p+1) = *(unsigned char *)(p+2) = *(unsigned char *)(p+3) =
							(((((int)olinbuf[x])-bakr)*(int)olinbuf[x-1])>>8) + bakr;
#else
						*(int *)p = (palcol[olinbuf[x]]&LSWAPIB(0xffffff))|LSWAPIL((int)olinbuf[x-1]);
#endif
					}
					break;
				case 6:
					for(;x>xr1;p+=ixstp,x-=4)
					{
#if (PROCESSALPHAHERE == 1)
							//Enable this code to process alpha right here!
						if (olinbuf[x-1] == 255) { *(int *)p = *(int *)&olinbuf[x]; continue; }
						if (!olinbuf[x-1]) { *(int *)p = bakcol; continue; }
							//I do >>8, but theoretically should be: /255
						*(unsigned char *)(p  ) = (((((int)olinbuf[x  ])-bakr)*(int)olinbuf[x-1])>>8) + bakr;
						*(unsigned char *)(p+1) = (((((int)olinbuf[x+1])-bakg)*(int)olinbuf[x-1])>>8) + bakg;
						*(unsigned char *)(p+2) = (((((int)olinbuf[x+2])-bakb)*(int)olinbuf[x-1])>>8) + bakb;
#else
						*(unsigned char *)(p  ) = olinbuf[x  ]; //R
						*(unsigned char *)(p+1) = olinbuf[x+1]; //G
						*(unsigned char *)(p+2) = olinbuf[x+2]; //B
						*(unsigned char *)(p+3) = olinbuf[x-1]; //A
#endif
					}
					break;
				default:
					switch(bitdepth)
					{
						case 1: for(;x>xr1;p+=ixstp,x-- ) *(int *)p = palcol[olinbuf[x>>3]>>(x&7)]; break;
						case 2: for(;x>xr1;p+=ixstp,x-=2) *(int *)p = palcol[olinbuf[x>>3]>>(x&6)]; break;
						case 4: for(;x>xr1;p+=ixstp,x-=4) *(int *)p = palcol[olinbuf[x>>3]>>(x&4)]; break;
						case 8: pal8hlineasm(x,xr1,p,ixstp); break; //for(;x>xr1;p+=ixstp,x--) *(int *)p = palcol[olinbuf[x]]; break;
					}
					break;
			}
			nfplace += nbpl;
		}

		*(int *)&opixbuf0[0] = *(int *)&opixbuf1[0] = 0;
		xplc = xsizbpl; yplc += iystp;
		if ((intlac) && (yplc >= globyoffs+ysiz)) { intlac--; initpass(); }
		if (i < leng)
		{
			filt = buf[i++];
			if (filter1st < 0) filter1st = filt; else filterest |= (1<<filt);
			if (filt == gotcmov) filt = 5;
		} else filt = -1;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movl 0x586ad7(%rip), %ecx    # 0x5d0e64
xorl %edx, %edx
testl %ecx, %ecx
js 0x4a955
cmpl %ebx, %edx
jge 0x4a983
movl 0x586ab7(%rip), %eax    # 0x5d0e5c
leaq 0x56cdb4(%rip), %r15    # 0x5b7160
movl $0xff000000, %r12d      # imm = 0xFF000000
leaq 0x586627(%rip), %r9     # 0x5d09e0
movl $0xffffff, %r10d        # imm = 0xFFFFFF
leaq 0x586a8e(%rip), %r13    # 0x5d0e54
leaq 0x586a63(%rip), %r11    # 0x5d0e30
movl %ebx, 0x4(%rsp)
leal (%rax,%rdx), %ebp
cmpl %ebx, %ebp
cmovgel %ebx, %ebp
cmpl $0x5, %ecx
ja 0x4a661
movl %ecx, %ecx
leaq 0x2d5c1(%rip), %rsi     # 0x779ac
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
cmpl %ebp, %edx
jge 0x4a661
movslq %edx, %rcx
movslq %ebp, %rdx
cltq
movb (%r14,%rcx), %sil
movb %sil, (%rax,%r15)
decq %rax
incq %rcx
cmpq %rcx, %rdx
jne 0x4a404
jmp 0x4a659
cmpl %ebp, %edx
jge 0x4a661
movl 0x586a36(%rip), %ecx    # 0x5d0e60
movslq %edx, %rdx
cltq
movl %ebp, (%rsp)
movslq %ebp, %rsi
movslq %ecx, %rcx
movzbl (%rcx,%r13), %edi
movzbl (%rax,%r15), %r8d
leaq 0x586a0f(%rip), %r13    # 0x5d0e58
movzbl (%rcx,%r13), %r9d
movl %r8d, %r10d
subl %r9d, %r10d
movl %edi, %r11d
subl %r9d, %r11d
leal (%r10,%r11), %ebx
movl %ebx, %r12d
negl %r12d
cmovsl %ebx, %r12d
movl %r10d, %ebx
negl %ebx
cmovsl %r10d, %ebx
movl $0xff, %ebp
andl %ebp, %ebx
movl %r11d, %r10d
negl %r10d
cmovsl %r11d, %r10d
andl %ebp, %r10d
cmpl %r12d, %r10d
movl %r8d, %r11d
cmoval %r9d, %r11d
cmpl %r12d, %ebx
cmoval %r11d, %edi
cmpl %r10d, %ebx
cmoval %r11d, %edi
leaq 0x58698c(%rip), %r11    # 0x5d0e30
addb (%r14,%rdx), %dil
movb %r8b, (%rcx,%r13)
leaq 0x5869a1(%rip), %r13    # 0x5d0e54
movb %dil, (%rcx,%r13)
movb %dil, (%rax,%r15)
movl (%r11,%rcx,4), %ecx
decq %rax
incq %rdx
cmpq %rdx, %rsi
jne 0x4a435
jmp 0x4a639
cmpl %ebp, %edx
jge 0x4a661
movslq %edx, %rcx
cltq
movslq %ebp, %rdx
movb (%r14,%rcx), %sil
addb %sil, (%rax,%r15)
decq %rax
incq %rcx
cmpq %rcx, %rdx
jne 0x4a4e3
jmp 0x4a659
cmpl %ebp, %edx
jge 0x4a661
movl 0x586957(%rip), %ecx    # 0x5d0e60
movslq %edx, %rdx
cltq
movl %ebp, (%rsp)
movslq %ebp, %rsi
movslq %ecx, %rcx
movzbl (%rcx,%r13), %edi
movzbl (%rax,%r15), %r8d
addl %edi, %r8d
shrl %r8d
addb (%r14,%rdx), %r8b
movb %r8b, (%rax,%r15)
movb %r8b, (%rcx,%r13)
movl (%r11,%rcx,4), %ecx
decq %rax
incq %rdx
cmpq %rdx, %rsi
jne 0x4a514
jmp 0x4a639
cmpl %ebp, %edx
jge 0x4a661
movl 0x58690b(%rip), %ecx    # 0x5d0e60
movslq %edx, %rdx
cltq
movl %ebp, (%rsp)
movslq %ebp, %rsi
movslq %ecx, %rcx
movb (%rcx,%r13), %dil
addb (%r14,%rdx), %dil
movb %dil, (%rcx,%r13)
movb %dil, (%rax,%r15)
movl (%r11,%rcx,4), %ecx
decq %rax
incq %rdx
cmpq %rdx, %rsi
jne 0x4a560
jmp 0x4a639
cmpl %ebp, %edx
jge 0x4a661
movl 0x5868cb(%rip), %ecx    # 0x5d0e60
movslq %edx, %rdx
cltq
movl %ebp, (%rsp)
movslq %ebp, %rsi
movslq %ecx, %rcx
movzbl (%rcx,%r13), %edi
movzbl (%rax,%r15), %r8d
leaq 0x5868a4(%rip), %r13    # 0x5d0e58
movzbl (%rcx,%r13), %r9d
movl %r8d, %r10d
subl %r9d, %r10d
movl %edi, %r11d
subl %r9d, %r11d
leal (%r10,%r11), %ebx
movl %ebx, %r12d
negl %r12d
cmovsl %ebx, %r12d
movl %r10d, %ebx
negl %ebx
cmovsl %r10d, %ebx
movl $0xff, %ebp
andl %ebp, %ebx
movl %r11d, %r10d
negl %r10d
cmovsl %r11d, %r10d
andl %ebp, %r10d
cmpl %r12d, %r10d
movl %r8d, %r11d
cmoval %r9d, %r11d
cmpl %r12d, %ebx
cmoval %r11d, %edi
cmpl %r10d, %ebx
cmoval %r11d, %edi
leaq 0x586821(%rip), %r11    # 0x5d0e30
addb (%r14,%rdx), %dil
movb %r8b, (%rcx,%r13)
leaq 0x586836(%rip), %r13    # 0x5d0e54
movb %dil, (%rcx,%r13)
movb %dil, (%rax,%r15)
movl (%r11,%rcx,4), %ecx
decq %rax
incq %rdx
cmpq %rdx, %rsi
jne 0x4a5a0
movl %ecx, 0x586821(%rip)    # 0x5d0e60
movl 0x4(%rsp), %ebx
movl $0xff000000, %r12d      # imm = 0xFF000000
leaq 0x586390(%rip), %r9     # 0x5d09e0
movl $0xffffff, %r10d        # imm = 0xFFFFFF
movl (%rsp), %ebp
movl %eax, 0x5867fd(%rip)    # 0x5d0e5c
jmp 0x4a663
movl %edx, %ebp
testl %eax, %eax
jg 0x4a983
movl 0x5867d3(%rip), %ecx    # 0x5d0e44
cmpl 0x5867a1(%rip), %ecx    # 0x5d0e18
jae 0x4a89f
movl 0x5867ed(%rip), %edx    # 0x5d0e70
movslq %edx, %rcx
movq 0x5867db(%rip), %rax    # 0x5d0e68
movzbl 0x58674c(%rip), %esi    # 0x5d0de0
cmpl $0x2, %esi
je 0x4a738
cmpl $0x4, %esi
je 0x4a6f4
cmpl $0x6, %esi
jne 0x4a78d
cmpl 0x5867c3(%rip), %edx    # 0x5d0e74
jle 0x4a88b
movb (%rcx,%r15), %dl
movb %dl, (%rax)
movb 0x1(%rcx,%r15), %dl
movb %dl, 0x1(%rax)
movb 0x2(%rcx,%r15), %dl
movb %dl, 0x2(%rax)
movb -0x1(%rcx,%r15), %dl
movb %dl, 0x3(%rax)
movslq 0x58676c(%rip), %rdx    # 0x5d0e48
addq %rdx, %rax
addq $-0x4, %rcx
movslq 0x58678a(%rip), %rdx    # 0x5d0e74
cmpq %rdx, %rcx
jg 0x4a6b7
jmp 0x4a88b
cmpl 0x58677a(%rip), %edx    # 0x5d0e74
jle 0x4a88b
movzbl (%rcx,%r15), %edx
movl (%r9,%rdx,4), %edx
andl %r10d, %edx
movzbl -0x1(%rcx,%r15), %esi
shll $0x18, %esi
orl %edx, %esi
movl %esi, (%rax)
movslq 0x586728(%rip), %rdx    # 0x5d0e48
addq %rdx, %rax
addq $-0x2, %rcx
movslq 0x586746(%rip), %rdx    # 0x5d0e74
cmpq %rdx, %rcx
jg 0x4a700
jmp 0x4a88b
movslq 0x586735(%rip), %rsi    # 0x5d0e74
movslq 0x586702(%rip), %rdi    # 0x5d0e48
cmpl $0x0, 0x586697(%rip)    # 0x5d0de4
je 0x4a872
cmpl %esi, %edx
jle 0x4a88b
movl (%rcx,%r15), %edx
movl %edx, %r8d
orl $0xff000000, %r8d       # imm = 0xFF000000
andl $0xffffff, %edx         # imm = 0xFFFFFF
cmpl 0x58666e(%rip), %r8d    # 0x5d0de4
cmovnel %r8d, %edx
movl %edx, (%rax)
addq %rdi, %rax
addq $-0x3, %rcx
cmpq %rsi, %rcx
jg 0x4a75b
jmp 0x4a88b
movzbl 0x58664d(%rip), %esi    # 0x5d0de1
decl %esi
cmpl $0x7, %esi
ja 0x4a88b
leaq 0x2d21e(%rip), %rdi     # 0x779c4
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
movslq 0x5866be(%rip), %rsi    # 0x5d0e74
cmpl %esi, %edx
jle 0x4a88b
movslq 0x586683(%rip), %rdx    # 0x5d0e48
movzbl (%rcx,%r15), %edi
movl (%r9,%rdi,4), %edi
movl %edi, (%rax)
addq %rdx, %rax
decq %rcx
cmpq %rsi, %rcx
jg 0x4a7c5
jmp 0x4a88b
movl %edx, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rcx,%r15), %esi
movl %edx, %ecx
andb $0x4, %cl
shrl %cl, %esi
movl (%r9,%rsi,4), %ecx
movl %ecx, (%rax)
movslq 0x586647(%rip), %rcx    # 0x5d0e48
addq %rcx, %rax
addl $-0x4, %edx
cmpl 0x586667(%rip), %edx    # 0x5d0e74
jg 0x4a7e0
jmp 0x4a88b
movl %edx, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rcx,%r15), %esi
movl %edx, %ecx
andb $0x7, %cl
shrl %cl, %esi
movl (%r9,%rsi,4), %ecx
movl %ecx, (%rax)
movslq 0x586616(%rip), %rcx    # 0x5d0e48
addq %rcx, %rax
decl %edx
cmpl 0x586637(%rip), %edx    # 0x5d0e74
jg 0x4a811
jmp 0x4a88b
movl %edx, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rcx,%r15), %esi
movl %edx, %ecx
andb $0x6, %cl
shrl %cl, %esi
movl (%r9,%rsi,4), %ecx
movl %ecx, (%rax)
movslq 0x5865e6(%rip), %rcx    # 0x5d0e48
addq %rcx, %rax
addl $-0x2, %edx
cmpl 0x586606(%rip), %edx    # 0x5d0e74
jg 0x4a841
jmp 0x4a88b
cmpl %esi, %edx
jle 0x4a88b
movl (%rcx,%r15), %edx
orl %r12d, %edx
movl %edx, (%rax)
addq %rdi, %rax
addq $-0x3, %rcx
cmpq %rsi, %rcx
jg 0x4a876
movslq 0x5865be(%rip), %rax    # 0x5d0e50
addq %rax, 0x5865cf(%rip)    # 0x5d0e68
movl 0x5865a5(%rip), %ecx    # 0x5d0e44
xorl %eax, %eax
movl %eax, 0x5865ad(%rip)    # 0x5d0e54
movl %eax, 0x5865ab(%rip)    # 0x5d0e58
movl 0x58658d(%rip), %eax    # 0x5d0e40
addl 0x586593(%rip), %ecx    # 0x5d0e4c
movl %eax, 0x58659d(%rip)    # 0x5d0e5c
movl %ecx, 0x58657f(%rip)    # 0x5d0e44
movl 0x58652d(%rip), %edx    # 0x5d0df8
testl %edx, %edx
je 0x4a906
movl 0x58651f(%rip), %esi    # 0x5d0df4
addl 0x586545(%rip), %esi    # 0x5d0e20
cmpl %esi, %ecx
jl 0x4a906
decl %edx
movl %edx, 0x586511(%rip)    # 0x5d0df8
callq 0x4a0a7
leaq 0x58653d(%rip), %r11    # 0x5d0e30
movl $0xffffff, %r10d        # imm = 0xFFFFFF
leaq 0x5860e0(%rip), %r9     # 0x5d09e0
movl 0x586556(%rip), %eax    # 0x5d0e5c
cmpl %ebx, %ebp
jge 0x4a932
movslq %ebp, %rcx
incl %ebp
movzbl (%r14,%rcx), %ecx
movl %ecx, 0x58654a(%rip)    # 0x5d0e64
cmpl $0x0, 0x5864c7(%rip)    # 0x5d0de8
js 0x4a943
movl $0x1, %edx
shll %cl, %edx
orl %edx, 0x5864bc(%rip)    # 0x5d0dec
jmp 0x4a949
movl $0xffffffff, 0x586528(%rip) # imm = 0xFFFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x4a949
movl %ecx, 0x58649f(%rip)    # 0x5d0de8
movl %ebp, %edx
cmpl %ebx, %ebp
jl 0x4a3d1
jmp 0x4a983
testl %ebx, %ebx
jle 0x4a983
movzbl (%r14), %ecx
movl %ecx, 0x586501(%rip)    # 0x5d0e64
cmpl $0x0, 0x58647e(%rip)    # 0x5d0de8
js 0x4a992
movl $0x1, %eax
shll %cl, %eax
movl $0x1, %edx
orl %eax, 0x58646e(%rip)    # 0x5d0dec
jmp 0x4a397
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, 0x586450(%rip)    # 0x5d0de8
movl $0x1, %edx
jmp 0x4a397