// File: /workspace/github_c_makefile_star2_O2/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
subq $0x18, %rsp
movl %esi, %ebp
movq %rdi, %r14
movl 0x5882bc(%rip), %ecx    # 0x5c9e64
xorl %r9d, %r9d
testl %ecx, %ecx
js 0x420fa
leaq 0x56e5a6(%rip), %r15    # 0x5b0160
leaq 0x587e1f(%rip), %r13    # 0x5c99e0
movl %ebp, 0x4(%rsp)
movq %r14, 0x8(%rsp)
cmpl %ebp, %r9d
jge 0x42126
movl 0x588283(%rip), %ebx    # 0x5c9e5c
leal (%rbx,%r9), %eax
cmpl %ebp, %eax
cmovgel %ebp, %eax
cmpl $0x5, %ecx
ja 0x41e3d
movslq %ebx, %r13
movl %ecx, %ecx
leaq 0x2ab25(%rip), %rdx     # 0x6c71c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
movslq %eax, %rdi
movq %rdi, 0x10(%rsp)
jmpq *%rcx
movslq %r9d, %r9
leaq 0x56e54e(%rip), %rax    # 0x5b0160
addq %rax, %r13
cmpq %rdi, %r9
jge 0x41e2f
movb (%r14,%r9), %al
movb %al, (%r13)
decl %ebx
movl %ebx, 0x58822e(%rip)    # 0x5c9e5c
incq %r9
decq %r13
jmp 0x41c15
movl 0x588224(%rip), %eax    # 0x5c9e60
movslq %r9d, %r9
leaq 0x56e51a(%rip), %rcx    # 0x5b0160
addq %rcx, %r13
cmpq %rdi, %r9
jge 0x41e26
movslq %eax, %r14
leaq 0x5881f8(%rip), %rax    # 0x5c9e54
movzbl (%r14,%rax), %edi
movzbl (%r13), %ebp
leaq 0x5881eb(%rip), %r12    # 0x5c9e58
movzbl (%r14,%r12), %edx
movl %ebp, %esi
movq %r9, %r15
callq 0x42146
movq 0x10(%rsp), %rdi
movq %r15, %r9
movq 0x8(%rsp), %rcx
addb (%rcx,%r15), %al
leaq 0x5881c0(%rip), %rcx    # 0x5c9e54
movb %al, (%r14,%rcx)
movb %bpl, (%r14,%r12)
movb %al, (%r13)
leaq 0x588189(%rip), %rax    # 0x5c9e30
movl (%rax,%r14,4), %eax
movl %eax, 0x5881af(%rip)    # 0x5c9e60
decl %ebx
movl %ebx, 0x5881a3(%rip)    # 0x5c9e5c
incq %r9
decq %r13
jmp 0x41c49
movslq %r9d, %r9
leaq 0x56e495(%rip), %rax    # 0x5b0160
addq %rax, %r13
cmpq %rdi, %r9
jge 0x41e2f
movb (%r14,%r9), %al
addb %al, (%r13)
decl %ebx
movl %ebx, 0x588175(%rip)    # 0x5c9e5c
incq %r9
decq %r13
jmp 0x41cce
movl 0x58816b(%rip), %eax    # 0x5c9e60
movslq %r9d, %r9
leaq 0x56e461(%rip), %rcx    # 0x5b0160
addq %rcx, %r13
cmpq %rdi, %r9
jge 0x41e2f
cltq
leaq 0x588140(%rip), %rsi    # 0x5c9e54
movzbl (%rax,%rsi), %ecx
movzbl (%r13), %edx
addl %ecx, %edx
shrl %edx
addb (%r14,%r9), %dl
movb %dl, (%r13)
movb %dl, (%rax,%rsi)
leaq 0x5880fd(%rip), %rcx    # 0x5c9e30
movl (%rcx,%rax,4), %eax
movl %eax, 0x588124(%rip)    # 0x5c9e60
decl %ebx
movl %ebx, 0x588118(%rip)    # 0x5c9e5c
incq %r9
decq %r13
jmp 0x41d02
movl 0x58810e(%rip), %eax    # 0x5c9e60
movslq %r9d, %r9
leaq 0x56e404(%rip), %rcx    # 0x5b0160
addq %rcx, %r13
cmpq %rdi, %r9
jge 0x41e2f
cltq
leaq 0x5880e3(%rip), %rdx    # 0x5c9e54
movb (%rax,%rdx), %cl
addb (%r14,%r9), %cl
movb %cl, (%rax,%rdx)
movb %cl, (%r13)
leaq 0x5880aa(%rip), %rcx    # 0x5c9e30
movl (%rcx,%rax,4), %eax
movl %eax, 0x5880d1(%rip)    # 0x5c9e60
decl %ebx
movl %ebx, 0x5880c5(%rip)    # 0x5c9e5c
incq %r9
decq %r13
jmp 0x41d5f
movslq %r9d, %r9
movl 0x5880b8(%rip), %eax    # 0x5c9e60
leaq 0x56e3b1(%rip), %rcx    # 0x5b0160
addq %rcx, %r13
cmpq %rdi, %r9
jge 0x41e26
movslq %eax, %r14
leaq 0x588093(%rip), %rax    # 0x5c9e54
movzbl (%r14,%rax), %edi
movzbl (%r13), %ebp
leaq 0x588086(%rip), %r12    # 0x5c9e58
movzbl (%r14,%r12), %edx
movl %ebp, %esi
movq %r9, %r15
callq 0x42146
movq 0x10(%rsp), %rdi
movq %r15, %r9
movq 0x8(%rsp), %rcx
addb (%rcx,%r15), %al
leaq 0x58805b(%rip), %rcx    # 0x5c9e54
movb %al, (%r14,%rcx)
movb %bpl, (%r14,%r12)
movb %al, (%r13)
leaq 0x588024(%rip), %rax    # 0x5c9e30
movl (%rax,%r14,4), %eax
movl %eax, 0x58804a(%rip)    # 0x5c9e60
decl %ebx
movl %ebx, 0x58803e(%rip)    # 0x5c9e5c
incq %r9
decq %r13
jmp 0x41db2
movl 0x4(%rsp), %ebp
movq 0x8(%rsp), %r14
leaq 0x56e32a(%rip), %r15    # 0x5b0160
leaq 0x587ba3(%rip), %r13    # 0x5c99e0
testl %ebx, %ebx
movl $0xffffff, %edi         # imm = 0xFFFFFF
jg 0x42126
movl 0x587ff4(%rip), %eax    # 0x5c9e44
cmpl 0x587fc2(%rip), %eax    # 0x5c9e18
jae 0x4205e
movl 0x58800e(%rip), %edx    # 0x5c9e70
movslq %edx, %rcx
movq 0x587ffc(%rip), %rax    # 0x5c9e68
movzbl 0x587f6d(%rip), %esi    # 0x5c9de0
cmpl $0x2, %esi
je 0x41f00
cmpl $0x4, %esi
je 0x41eef
cmpl $0x6, %esi
jne 0x41f6a
movslq 0x587fe3(%rip), %rdx    # 0x5c9e74
cmpq %rdx, %rcx
jle 0x4204a
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 0x587f89(%rip), %rdx    # 0x5c9e48
addq %rdx, %rax
addq $-0x4, %rcx
jmp 0x41e8a
movzbl (%rcx,%r15), %edx
movl (%r13,%rdx,4), %edx
andl %edi, %edx
movzbl -0x1(%rcx,%r15), %esi
shll $0x18, %esi
orl %edx, %esi
movl %esi, (%rax)
movslq 0x587f60(%rip), %rdx    # 0x5c9e48
addq %rdx, %rax
addq $-0x2, %rcx
movslq 0x587f7e(%rip), %rdx    # 0x5c9e74
cmpq %rdx, %rcx
jg 0x41ec8
jmp 0x4204a
movslq 0x587f6d(%rip), %rdx    # 0x5c9e74
movslq 0x587f3a(%rip), %rsi    # 0x5c9e48
cmpl $0x0, 0x587ecf(%rip)    # 0x5c9de4
je 0x41f60
cmpq %rdx, %rcx
jle 0x4204a
movl (%rcx,%r15), %edi
movl %edi, %r8d
orl $0xff000000, %r8d       # imm = 0xFF000000
andl $0xffffff, %edi         # imm = 0xFFFFFF
cmpl 0x587ea9(%rip), %r8d    # 0x5c9de4
cmovnel %r8d, %edi
movl %edi, (%rax)
addq %rsi, %rax
addq $-0x3, %rcx
jmp 0x41f17
movl (%rcx,%r15), %edi
movl $0xff000000, %r8d       # imm = 0xFF000000
orl %r8d, %edi
movl %edi, (%rax)
addq %rsi, %rax
addq $-0x3, %rcx
cmpq %rdx, %rcx
jg 0x41f4a
jmp 0x4204a
movzbl 0x587e70(%rip), %esi    # 0x5c9de1
decl %esi
cmpl $0x7, %esi
ja 0x4204a
leaq 0x2a7b1(%rip), %rdi     # 0x6c734
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
movslq 0x587ee1(%rip), %rdx    # 0x5c9e74
movslq 0x587eae(%rip), %rsi    # 0x5c9e48
cmpq %rdx, %rcx
jle 0x4204a
movzbl (%rcx,%r15), %edi
movl (%r13,%rdi,4), %edi
movl %edi, (%rax)
addq %rsi, %rax
decq %rcx
jmp 0x41f9a
movl %edx, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rcx,%r15), %esi
movl %edx, %ecx
andb $0x4, %cl
shrl %cl, %esi
movl (%r13,%rsi,4), %ecx
movl %ecx, (%rax)
movslq 0x587e6f(%rip), %rcx    # 0x5c9e48
addq %rcx, %rax
addl $-0x4, %edx
cmpl 0x587e8f(%rip), %edx    # 0x5c9e74
jg 0x41fb7
jmp 0x4204a
movl %edx, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rcx,%r15), %esi
movl %edx, %ecx
andb $0x7, %cl
shrl %cl, %esi
movl (%r13,%rsi,4), %ecx
movl %ecx, (%rax)
movslq 0x587e3d(%rip), %rcx    # 0x5c9e48
addq %rcx, %rax
decl %edx
cmpl 0x587e5e(%rip), %edx    # 0x5c9e74
jg 0x41fe9
jmp 0x4204a
movl %edx, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rcx,%r15), %esi
movl %edx, %ecx
andb $0x6, %cl
shrl %cl, %esi
movl (%r13,%rsi,4), %ecx
movl %ecx, (%rax)
movslq 0x587e0c(%rip), %rcx    # 0x5c9e48
addq %rcx, %rax
addl $-0x2, %edx
cmpl 0x587e2c(%rip), %edx    # 0x5c9e74
jg 0x4201a
movslq 0x587dff(%rip), %rax    # 0x5c9e50
addq %rax, 0x587e10(%rip)    # 0x5c9e68
movl 0x587de6(%rip), %eax    # 0x5c9e44
andl $0x0, 0x587def(%rip)    # 0x5c9e54
andl $0x0, 0x587dec(%rip)    # 0x5c9e58
movl 0x587dce(%rip), %ecx    # 0x5c9e40
addl 0x587dd4(%rip), %eax    # 0x5c9e4c
movl %ecx, 0x587dde(%rip)    # 0x5c9e5c
movl %eax, 0x587dc0(%rip)    # 0x5c9e44
movl 0x587d6e(%rip), %ecx    # 0x5c9df8
testl %ecx, %ecx
je 0x420b1
movl 0x587d60(%rip), %edx    # 0x5c9df4
addl 0x587d86(%rip), %edx    # 0x5c9e20
cmpl %edx, %eax
jl 0x420b1
decl %ecx
movl %ecx, 0x587d52(%rip)    # 0x5c9df8
movq %r9, %rbx
callq 0x418d4
movq %rbx, %r9
cmpl %ebp, %r9d
jge 0x420e0
movslq %r9d, %rax
incl %r9d
movzbl (%r14,%rax), %ecx
movl %ecx, 0x587d9d(%rip)    # 0x5c9e64
cmpl $0x0, 0x587d1a(%rip)    # 0x5c9de8
js 0x420ef
pushq $0x1
popq %rax
shll %cl, %eax
orl %eax, 0x587d11(%rip)    # 0x5c9dec
jmp 0x41bca
orl $-0x1, 0x587d7d(%rip)   # 0x5c9e64
pushq $-0x1
popq %rcx
jmp 0x41bca
movl %ecx, 0x587cf3(%rip)    # 0x5c9de8
jmp 0x41bca
testl %ebp, %ebp
jle 0x42126
movzbl (%r14), %ecx
movl %ecx, 0x587d5c(%rip)    # 0x5c9e64
cmpl $0x0, 0x587cd9(%rip)    # 0x5c9de8
js 0x42135
pushq $0x1
popq %rdx
movl %edx, %eax
shll %cl, %eax
orl %eax, 0x587cce(%rip)    # 0x5c9dec
movl %edx, %r9d
jmp 0x41bb3
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, 0x587cad(%rip)    # 0x5c9de8
pushq $0x1
popq %rax
movl %eax, %r9d
jmp 0x41bb3