// File: /workspace/github_c_makefile_star2_O1/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
xorl %r15d, %r15d
cmpl $0x0, 0x587d69(%rip)    # 0x5cfe64
js 0x486da
cmpl %ebx, %r15d
jge 0x48709
leaq 0x56e04f(%rip), %r12    # 0x5b6160
leaq 0x5878c8(%rip), %r9     # 0x5cf9e0
movl $0xffffff, %r10d        # imm = 0xFFFFFF
xorl %r11d, %r11d
leaq 0x587d2c(%rip), %rbp    # 0x5cfe54
leaq 0x587d01(%rip), %r8     # 0x5cfe30
movl $0xff, %r13d
movl %ebx, 0x4(%rsp)
movl 0x587d1d(%rip), %ecx    # 0x5cfe5c
addl %r15d, %ecx
cmpl %ebx, %ecx
cmovgel %ebx, %ecx
movl 0x587d17(%rip), %eax    # 0x5cfe64
cmpq $0x5, %rax
ja 0x483da
leaq 0x2e562(%rip), %rdx     # 0x766c0
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
cmpl %ecx, %r15d
jge 0x483da
movslq 0x587ce5(%rip), %rax    # 0x5cfe5c
movslq %r15d, %r15
movslq %ecx, %rcx
movb (%r14,%r15), %dl
movb %dl, (%rax,%r12)
decq %rax
incq %r15
cmpq %r15, %rcx
jne 0x4817d
jmp 0x483d4
cmpl %ecx, %r15d
jge 0x483da
movslq 0x587cb7(%rip), %rax    # 0x5cfe5c
movl 0x587cb5(%rip), %edx    # 0x5cfe60
movslq %r15d, %r15
movslq %ecx, %rcx
leaq 0x587ca0(%rip), %r9     # 0x5cfe58
movslq %edx, %rdx
movzbl (%rdx,%rbp), %esi
movzbl (%rax,%r12), %edi
movzbl (%rdx,%r9), %r8d
movl %edi, %r9d
subl %r8d, %r9d
movl %esi, %r10d
subl %r8d, %r10d
leal (%r9,%r10), %ebx
movl %ebx, %r11d
negl %r11d
cmovsl %ebx, %r11d
movl %r9d, %ebx
negl %ebx
cmovsl %r9d, %ebx
andl %r13d, %ebx
movl %r10d, %r9d
negl %r9d
cmovsl %r10d, %r9d
andl %r13d, %r9d
cmpl %r11d, %r9d
movl %edi, %r10d
cmoval %r8d, %r10d
leaq 0x587c23(%rip), %r8     # 0x5cfe30
cmpl %r11d, %ebx
cmoval %r10d, %esi
cmpl %r9d, %ebx
leaq 0x587c3a(%rip), %r9     # 0x5cfe58
cmoval %r10d, %esi
addb (%r14,%r15), %sil
movb %dil, (%rdx,%r9)
movb %sil, (%rdx,%rbp)
movb %sil, (%rax,%r12)
movl (%r8,%rdx,4), %edx
decq %rax
incq %r15
cmpq %r15, %rcx
jne 0x481b8
jmp 0x483ba
cmpl %ecx, %r15d
jge 0x483da
movslq 0x587c02(%rip), %rax    # 0x5cfe5c
movslq %r15d, %r15
movslq %ecx, %rcx
movb (%r14,%r15), %dl
addb %dl, (%rax,%r12)
decq %rax
incq %r15
cmpq %r15, %rcx
jne 0x48260
jmp 0x483d4
cmpl %ecx, %r15d
jge 0x483da
movslq 0x587bd4(%rip), %rax    # 0x5cfe5c
movl 0x587bd2(%rip), %edx    # 0x5cfe60
movslq %r15d, %r15
movslq %ecx, %rcx
movslq %edx, %rdx
movzbl (%rdx,%rbp), %esi
movzbl (%rax,%r12), %edi
addl %esi, %edi
shrl %edi
addb (%r14,%r15), %dil
movb %dil, (%rax,%r12)
movb %dil, (%rdx,%rbp)
movl (%r8,%rdx,4), %edx
decq %rax
incq %r15
cmpq %r15, %rcx
jne 0x48294
jmp 0x482ff
cmpl %ecx, %r15d
jge 0x483da
movslq 0x587b8b(%rip), %rax    # 0x5cfe5c
movl 0x587b89(%rip), %edx    # 0x5cfe60
movslq %r15d, %r15
movslq %ecx, %rcx
movslq %edx, %rdx
movb (%rdx,%rbp), %sil
addb (%r14,%r15), %sil
movb %sil, (%rdx,%rbp)
movb %sil, (%rax,%r12)
movl (%r8,%rdx,4), %edx
decq %rax
incq %r15
cmpq %r15, %rcx
jne 0x482dd
movl %edx, 0x587b5b(%rip)    # 0x5cfe60
jmp 0x483d4
cmpl %ecx, %r15d
jge 0x483da
movslq 0x587b42(%rip), %rax    # 0x5cfe5c
movl 0x587b40(%rip), %edx    # 0x5cfe60
movslq %r15d, %r15
movslq %ecx, %rcx
leaq 0x587b2b(%rip), %r9     # 0x5cfe58
movslq %edx, %rdx
movzbl (%rdx,%rbp), %esi
movzbl (%rax,%r12), %edi
movzbl (%rdx,%r9), %r8d
movl %edi, %r9d
subl %r8d, %r9d
movl %esi, %r10d
subl %r8d, %r10d
leal (%r9,%r10), %r11d
movl %r11d, %ebx
negl %ebx
cmovsl %r11d, %ebx
movl %r9d, %r11d
negl %r11d
cmovsl %r9d, %r11d
andl %r13d, %r11d
movl %r10d, %r9d
negl %r9d
cmovsl %r10d, %r9d
andl %r13d, %r9d
cmpl %ebx, %r9d
movl %edi, %r10d
cmoval %r8d, %r10d
leaq 0x587aae(%rip), %r8     # 0x5cfe30
cmpl %ebx, %r11d
cmoval %r10d, %esi
cmpl %r9d, %r11d
leaq 0x587ac5(%rip), %r9     # 0x5cfe58
cmoval %r10d, %esi
addb (%r14,%r15), %sil
movb %dil, (%rdx,%r9)
movb %sil, (%rdx,%rbp)
movb %sil, (%rax,%r12)
movl (%r8,%rdx,4), %edx
decq %rax
incq %r15
cmpq %r15, %rcx
jne 0x4832d
movl %edx, 0x587aa0(%rip)    # 0x5cfe60
movl 0x4(%rsp), %ebx
leaq 0x587615(%rip), %r9     # 0x5cf9e0
movl $0xffffff, %r10d        # imm = 0xFFFFFF
xorl %r11d, %r11d
movl %eax, 0x587a82(%rip)    # 0x5cfe5c
cmpl $0x0, 0x587a7b(%rip)    # 0x5cfe5c
jg 0x48709
movl 0x587a57(%rip), %eax    # 0x5cfe44
cmpl 0x587a25(%rip), %eax    # 0x5cfe18
jae 0x48625
movl 0x587a71(%rip), %edx    # 0x5cfe70
movslq %edx, %rcx
movq 0x587a5f(%rip), %rax    # 0x5cfe68
movzbl 0x5879d0(%rip), %esi    # 0x5cfde0
cmpl $0x2, %esi
je 0x484b4
cmpl $0x4, %esi
je 0x48470
cmpl $0x6, %esi
jne 0x48509
cmpl 0x587a47(%rip), %edx    # 0x5cfe74
jle 0x48610
movb (%rcx,%r12), %dl
movb %dl, (%rax)
movb 0x1(%rcx,%r12), %dl
movb %dl, 0x1(%rax)
movb 0x2(%rcx,%r12), %dl
movb %dl, 0x2(%rax)
movb -0x1(%rcx,%r12), %dl
movb %dl, 0x3(%rax)
movslq 0x5879f0(%rip), %rdx    # 0x5cfe48
addq %rdx, %rax
addq $-0x4, %rcx
movslq 0x587a0e(%rip), %rdx    # 0x5cfe74
cmpq %rdx, %rcx
jg 0x48433
jmp 0x48610
cmpl 0x5879fe(%rip), %edx    # 0x5cfe74
jle 0x48610
movzbl (%rcx,%r12), %edx
movl (%r9,%rdx,4), %edx
andl %r10d, %edx
movzbl -0x1(%rcx,%r12), %esi
shll $0x18, %esi
orl %edx, %esi
movl %esi, (%rax)
movslq 0x5879ac(%rip), %rdx    # 0x5cfe48
addq %rdx, %rax
addq $-0x2, %rcx
movslq 0x5879ca(%rip), %rdx    # 0x5cfe74
cmpq %rdx, %rcx
jg 0x4847c
jmp 0x48610
movslq 0x5879b9(%rip), %rsi    # 0x5cfe74
movslq 0x587986(%rip), %rdi    # 0x5cfe48
cmpl $0x0, 0x58791b(%rip)    # 0x5cfde4
je 0x485f1
cmpl %esi, %edx
jle 0x48610
movl (%rcx,%r12), %edx
movl %edx, %r8d
orl $0xff000000, %r8d       # imm = 0xFF000000
andl $0xffffff, %edx         # imm = 0xFFFFFF
cmpl 0x5878f2(%rip), %r8d    # 0x5cfde4
cmovnel %r8d, %edx
movl %edx, (%rax)
addq %rdi, %rax
addq $-0x3, %rcx
cmpq %rsi, %rcx
jg 0x484d7
jmp 0x48610
movzbl 0x5878d1(%rip), %esi    # 0x5cfde1
decl %esi
cmpl $0x7, %esi
ja 0x48610
leaq 0x2e1b6(%rip), %rdi     # 0x766d8
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
movslq 0x587942(%rip), %rsi    # 0x5cfe74
cmpl %esi, %edx
jle 0x48610
movslq 0x587907(%rip), %rdx    # 0x5cfe48
movzbl (%rcx,%r12), %edi
movl (%r9,%rdi,4), %edi
movl %edi, (%rax)
addq %rdx, %rax
decq %rcx
cmpq %rsi, %rcx
jg 0x48541
jmp 0x48610
movl %edx, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rcx,%r12), %esi
movl %edx, %ecx
andb $0x4, %cl
shrl %cl, %esi
movl (%r9,%rsi,4), %ecx
movl %ecx, (%rax)
movslq 0x5878cb(%rip), %rcx    # 0x5cfe48
addq %rcx, %rax
addl $-0x4, %edx
cmpl 0x5878eb(%rip), %edx    # 0x5cfe74
jg 0x4855c
jmp 0x48610
movl %edx, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rcx,%r12), %esi
movl %edx, %ecx
andb $0x7, %cl
shrl %cl, %esi
movl (%r9,%rsi,4), %ecx
movl %ecx, (%rax)
movslq 0x587897(%rip), %rcx    # 0x5cfe48
addq %rcx, %rax
decl %edx
cmpl 0x5878b8(%rip), %edx    # 0x5cfe74
jg 0x48590
jmp 0x48610
movl %edx, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rcx,%r12), %esi
movl %edx, %ecx
andb $0x6, %cl
shrl %cl, %esi
movl (%r9,%rsi,4), %ecx
movl %ecx, (%rax)
movslq 0x587867(%rip), %rcx    # 0x5cfe48
addq %rcx, %rax
addl $-0x2, %edx
cmpl 0x587887(%rip), %edx    # 0x5cfe74
jg 0x485c0
jmp 0x48610
cmpl %esi, %edx
jle 0x48610
movl (%rcx,%r12), %edx
movl $0xff000000, %r8d       # imm = 0xFF000000
orl %r8d, %edx
movl %edx, (%rax)
addq %rdi, %rax
addq $-0x3, %rcx
cmpq %rsi, %rcx
jg 0x485f5
movslq 0x587839(%rip), %rax    # 0x5cfe50
addq %rax, 0x58784a(%rip)    # 0x5cfe68
leaq 0x58780b(%rip), %r8     # 0x5cfe30
movl %r11d, 0x587828(%rip)   # 0x5cfe54
movl %r11d, 0x587825(%rip)   # 0x5cfe58
movl 0x587807(%rip), %eax    # 0x5cfe40
movl 0x587805(%rip), %ecx    # 0x5cfe44
addl 0x587807(%rip), %ecx    # 0x5cfe4c
movl %eax, 0x587811(%rip)    # 0x5cfe5c
movl %ecx, 0x5877f3(%rip)    # 0x5cfe44
movl 0x5877a1(%rip), %eax    # 0x5cfdf8
testl %eax, %eax
je 0x4868f
movl 0x587793(%rip), %edx    # 0x5cfdf4
addl 0x5877b9(%rip), %edx    # 0x5cfe20
cmpl %edx, %ecx
jl 0x4868f
decl %eax
movl %eax, 0x587785(%rip)    # 0x5cfdf8
callq 0x47e0e
leaq 0x5877b1(%rip), %r8     # 0x5cfe30
xorl %r11d, %r11d
movl $0xffffff, %r10d        # imm = 0xFFFFFF
leaq 0x587351(%rip), %r9     # 0x5cf9e0
cmpl %ebx, %r15d
jge 0x486bd
movslq %r15d, %rax
incl %r15d
movzbl (%r14,%rax), %ecx
movl %ecx, 0x5877bf(%rip)    # 0x5cfe64
cmpl $0x0, 0x58773c(%rip)    # 0x5cfde8
js 0x486c9
movl $0x1, %eax
shll %cl, %eax
orl %eax, 0x587731(%rip)    # 0x5cfdec
jmp 0x486cf
movl $0xffffffff, 0x58779d(%rip) # imm = 0xFFFFFFFF
jmp 0x486cf
movl %ecx, 0x587719(%rip)    # 0x5cfde8
cmpl %ebx, %r15d
jl 0x48139
jmp 0x48709
testl %ebx, %ebx
jle 0x48709
movzbl (%r14), %ecx
movl %ecx, 0x58777c(%rip)    # 0x5cfe64
cmpl $0x0, 0x5876f9(%rip)    # 0x5cfde8
js 0x48718
movl $0x1, %eax
shll %cl, %eax
movl $0x1, %r15d
orl %eax, 0x5876e8(%rip)    # 0x5cfdec
jmp 0x48101
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, 0x5876ca(%rip)    # 0x5cfde8
movl $0x1, %r15d
jmp 0x48101