// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/src/kplib.c
// Function: initpass
static int initpass (void) //Interlaced images have 7 "passes", non-interlaced have 1
{
	int i, j, k;

	do
	{
		i = (intlac<<2);
		ixoff = ((0x04020100>>i)&15);
		iyoff = ((0x00402010>>i)&15);
		if (((ixoff >= xsiz) || (iyoff >= ysiz)) && (intlac >= 2)) { i = -1; intlac--; }
	} while (i < 0);
	j = ((0x33221100>>i)&15); ixstp = (1<<j);
	k = ((0x33322110>>i)&15); iystp = (1<<k);

		//xsiz=12      0123456789ab
		//j=3,ixoff=0  0       1       ((12+(1<<3)-1 - 0)>>3) = 2
		//j=3,ixoff=4      2           ((12+(1<<3)-1 - 4)>>3) = 1
		//j=2,ixoff=2    3   4   5     ((12+(1<<2)-1 - 2)>>2) = 3
		//j=1,ixoff=1   6 7 8 9 a b    ((12+(1<<1)-1 - 1)>>1) = 6
	ixsiz = ((xsiz+ixstp-1-ixoff)>>j); //It's confusing! See the above example.
	nbpl = (bytesperline<<k);

		//Initialize this to make filters fast:
	xsizbpl = ((0x04021301>>(coltype<<2))&15)*ixsiz;
	switch (bitdepth)
	{
		case 1: xsizbpl = ((xsizbpl+7)>>3); break;
		case 2: xsizbpl = ((xsizbpl+3)>>2); break;
		case 4: xsizbpl = ((xsizbpl+1)>>1); break;
	}

	memset(olinbuf,0,(xsizbpl+1)*sizeof(olinbuf[0]));
	*(int *)&opixbuf0[0] = *(int *)&opixbuf1[0] = 0;
	xplc = xsizbpl; yplc = globyoffs+iyoff; xm = 0; filt = -1;

	i = globxoffs+ixoff; i = (((-(i>=0))|(ixstp-1))&i);
	k = (((-(yplc>=0))|(iystp-1))&yplc);
	nfplace = k*bytesperline + (i<<2) + frameplace;

		//Precalculate x-clipping to screen borders (speeds up putbuf)
		//Equation: (0 <= xr <= ixsiz) && (0 <= xr*ixstp+globxoffs+ixoff <= xres)
	xr0 = max((-globxoffs-ixoff+(1<<j)-1)>>j,0);
	xr1 = min((xres-globxoffs-ixoff+(1<<j)-1)>>j,ixsiz);
	xr0 = ixsiz-xr0;
	xr1 = ixsiz-xr1;

		  if (coltype == 4) { xr0 = xr0*2;   xr1 = xr1*2;   }
	else if (coltype == 2) { xr0 = xr0*3-2; xr1 = xr1*3-2; }
	else if (coltype == 6) { xr0 = xr0*4-2; xr1 = xr1*4-2; }
	else
	{
		switch(bitdepth)
		{
			case 1: xr0 += ((-ixsiz)&7)+7;
					  xr1 += ((-ixsiz)&7)+7; break;
			case 2: xr0 = ((xr0+((-ixsiz)&3)+3)<<1);
					  xr1 = ((xr1+((-ixsiz)&3)+3)<<1); break;
			case 4: xr0 = ((xr0+((-ixsiz)&1)+1)<<2);
					  xr1 = ((xr1+((-ixsiz)&1)+1)<<2); break;
		}
	}
	ixstp <<= 2;
	return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x587fcd(%rip), %r14d   # 0x5cfdf0
movl 0x587fcf(%rip), %edx    # 0x5cfdf8
movl 0x587fc5(%rip), %esi    # 0x5cfdf4
leal (,%rdx,4), %eax
movl $0x4020100, %ebp        # imm = 0x4020100
movl %eax, %ecx
shrl %cl, %ebp
movl $0x402010, %r15d        # imm = 0x402010
shrl %cl, %r15d
andl $0x7, %ebp
andl $0x7, %r15d
cmpl %r14d, %ebp
jge 0x47e60
cmpl $0x2, %edx
jl 0x47e72
cmpl %esi, %r15d
jge 0x47e65
jmp 0x47e72
cmpl $0x2, %edx
jl 0x47e72
decl %edx
movl %edx, 0x587f8b(%rip)    # 0x5cfdf8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x47e2f
movl $0x33221100, %ebx       # imm = 0x33221100
movl %eax, %ecx
shrl %cl, %ebx
andl $0xf, %ebx
movl $0x1, %edi
movl %ebx, %ecx
shll %cl, %edi
movl $0x33322110, %edx       # imm = 0x33322110
movl %eax, %ecx
shrl %cl, %edx
movl $0x1, %esi
movl %edi, 0x587fa9(%rip)    # 0x5cfe48
andb $0xf, %dl
movl $0x1, %r13d
movl %edx, %ecx
shll %cl, %r13d
movl %ebp, %eax
notl %eax
addl %eax, %r14d
movq %rdi, 0x10(%rsp)
addl %edi, %r14d
movl %ebx, %ecx
sarl %cl, %r14d
movl %r13d, 0x587f84(%rip)   # 0x5cfe4c
movl 0x587f42(%rip), %eax    # 0x5cfe10
movl %eax, 0x4(%rsp)
movl %edx, %ecx
shll %cl, %eax
movl %eax, 0x587f74(%rip)    # 0x5cfe50
movzbl 0x587efd(%rip), %edx    # 0x5cfde0
leal (,%rdx,4), %ecx
movl $0x4021301, %eax        # imm = 0x4021301
shrl %cl, %eax
andl $0x7, %eax
imull %r14d, %eax
movl %eax, 0x587f42(%rip)    # 0x5cfe40
movzbl 0x587edc(%rip), %edi    # 0x5cfde1
cmpl %esi, %edi
movq %rdx, 0x8(%rsp)
je 0x47f30
cmpl $0x4, %edi
je 0x47f24
cmpl $0x2, %edi
jne 0x47f44
movl $0x2, %ecx
movl $0x3, %edx
jmp 0x47f3a
movl $0x1, %edx
movl $0x1, %ecx
jmp 0x47f3a
movl $0x3, %ecx
movl $0x7, %edx
addl %edx, %eax
sarl %cl, %eax
movl %eax, 0x587efc(%rip)    # 0x5cfe40
movl %edi, (%rsp)
movslq 0x587ef2(%rip), %r12    # 0x5cfe40
movq %r12, %rdx
incq %rdx
leaq 0x56e205(%rip), %rdi    # 0x5b6160
xorl %esi, %esi
callq 0x62f0
xorl %eax, %eax
movl %eax, 0x587eea(%rip)    # 0x5cfe54
movl %eax, 0x587ee8(%rip)    # 0x5cfe58
xorl %edi, %edi
movl %r12d, 0x587ee3(%rip)   # 0x5cfe5c
addl 0x587ea0(%rip), %r15d   # 0x5cfe20
movl %r15d, 0x587ebd(%rip)   # 0x5cfe44
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addl 0x587e8a(%rip), %ebp    # 0x5cfe1c
movq 0x10(%rsp), %rsi
leal -0x1(%rsi), %ecx
testl %ebp, %ebp
cmovnsl %eax, %ecx
movl %edi, 0x587ebb(%rip)    # 0x5cfe60
andl %ebp, %ecx
decl %r13d
testl %r15d, %r15d
cmovnsl %eax, %r13d
andl %r15d, %r13d
imull 0x4(%rsp), %r13d
leal (%r13,%rcx,4), %ecx
movslq %ecx, %rdx
addq 0x587e3f(%rip), %rdx    # 0x5cfe08
xorl %eax, %ebp
addl %esi, %ebp
movl %ebp, %esi
movl %ebx, %ecx
sarl %cl, %esi
testl %esi, %esi
cmovlel %edi, %esi
addl 0x587e36(%rip), %ebp    # 0x5cfe14
sarl %cl, %ebp
movl %eax, 0x587e7e(%rip)    # 0x5cfe64
cmpl %r14d, %ebp
cmovgel %r14d, %ebp
movq %rdx, 0x587e74(%rip)    # 0x5cfe68
movl %r14d, %ecx
subl %esi, %ecx
movl %ecx, 0x587e71(%rip)    # 0x5cfe70
movl %r14d, %eax
subl %ebp, %eax
movl %eax, 0x587e6a(%rip)    # 0x5cfe74
movq 0x8(%rsp), %rdx
cmpl $0x2, %edx
je 0x48040
cmpl $0x6, %edx
je 0x4802a
cmpl $0x4, %edx
jne 0x4806e
addl %ecx, %ecx
movl %ecx, 0x587e4a(%rip)    # 0x5cfe70
addl %eax, %eax
jmp 0x48052
leal -0x2(,%rcx,4), %ecx
movl %ecx, 0x587e39(%rip)    # 0x5cfe70
leal -0x2(,%rax,4), %eax
jmp 0x48052
leal (%rcx,%rcx,2), %ecx
addl $-0x2, %ecx
movl %ecx, 0x587e24(%rip)    # 0x5cfe70
leal (%rax,%rax,2), %eax
addl $-0x2, %eax
movl %eax, 0x587e1c(%rip)    # 0x5cfe74
shll $0x2, 0x587de9(%rip)    # 0x5cfe48
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%rsp), %edx
cmpl $0x4, %edx
je 0x480be
cmpl $0x2, %edx
je 0x4809b
cmpl $0x1, %edx
jne 0x48058
negl %r14d
andl $0x7, %r14d
addl %r14d, %ecx
addl $0x7, %ecx
movl %ecx, 0x587ddd(%rip)    # 0x5cfe70
addl %r14d, %eax
addl $0x7, %eax
jmp 0x48052
negl %r14d
andl $0x3, %r14d
addl %r14d, %ecx
leal 0x6(,%rcx,2), %ecx
movl %ecx, 0x587dbe(%rip)    # 0x5cfe70
addl %r14d, %eax
leal 0x6(,%rax,2), %eax
jmp 0x48052
andl $0x1, %r14d
addl %r14d, %ecx
leal 0x4(,%rcx,4), %ecx
movl %ecx, 0x587d9e(%rip)    # 0x5cfe70
addl %r14d, %eax
leal 0x4(,%rax,4), %eax
jmp 0x48052