// File: /workspace/github_c_makefile_star2_O3/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 0x586d34(%rip), %r14d   # 0x5d0df0
movl 0x586d36(%rip), %edx    # 0x5d0df8
movl 0x586d2c(%rip), %esi    # 0x5d0df4
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 0x4a0f9
cmpl $0x2, %edx
jl 0x4a10b
cmpl %esi, %r15d
jge 0x4a0fe
jmp 0x4a10b
cmpl $0x2, %edx
jl 0x4a10b
decl %edx
movl %edx, 0x586cf2(%rip)    # 0x5d0df8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x4a0c8
movl $0x33221100, %edi       # imm = 0x33221100
movl %eax, %ecx
shrl %cl, %edi
andl $0xf, %edi
movl $0x1, %r12d
movl %edi, %ecx
shll %cl, %r12d
movl $0x33322110, %edx       # imm = 0x33322110
movl %eax, %ecx
shrl %cl, %edx
movl $0x1, %eax
movl %r12d, 0x586d0d(%rip)   # 0x5d0e48
andb $0xf, %dl
movl $0x1, %r13d
movl %edx, %ecx
shll %cl, %r13d
movl %ebp, %ecx
notl %ecx
addl %ecx, %r14d
addl %r12d, %r14d
movl %edi, %ecx
sarl %cl, %r14d
movl %r13d, 0x586ced(%rip)   # 0x5d0e4c
movl 0x586cab(%rip), %esi    # 0x5d0e10
movl %esi, 0x8(%rsp)
movl %edx, %ecx
shll %cl, %esi
movl %esi, 0x586cdd(%rip)    # 0x5d0e50
movzbl 0x586c66(%rip), %edx    # 0x5d0de0
leal (,%rdx,4), %ecx
movl $0x4021301, %ebx        # imm = 0x4021301
shrl %cl, %ebx
andl $0x7, %ebx
imull %r14d, %ebx
movl %ebx, 0x586cab(%rip)    # 0x5d0e40
movzbl 0x586c45(%rip), %esi    # 0x5d0de1
cmpl %eax, %esi
movl %edi, 0xc(%rsp)
movq %rdx, 0x10(%rsp)
movl %esi, 0x4(%rsp)
je 0x4a1ca
cmpl $0x4, %esi
je 0x4a1c3
cmpl $0x2, %esi
jne 0x4a1de
movl $0x2, %ecx
movl $0x3, %eax
jmp 0x4a1d4
movl $0x1, %ecx
jmp 0x4a1d4
movl $0x3, %ecx
movl $0x7, %eax
addl %eax, %ebx
sarl %cl, %ebx
movl %ebx, 0x586c62(%rip)    # 0x5d0e40
leal 0x1(%rbx), %eax
movslq %eax, %rdx
leaq 0x56cf75(%rip), %rdi    # 0x5b7160
xorl %esi, %esi
callq 0x62f0
xorl %eax, %eax
movl %eax, 0x586c5a(%rip)    # 0x5d0e54
movl %eax, 0x586c58(%rip)    # 0x5d0e58
xorl %edi, %edi
movl %ebx, 0x586c54(%rip)    # 0x5d0e5c
addl 0x586c11(%rip), %r15d   # 0x5d0e20
movl %r15d, 0x586c2e(%rip)   # 0x5d0e44
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addl 0x586bfb(%rip), %ebp    # 0x5d0e1c
leal -0x1(%r12), %ecx
testl %ebp, %ebp
cmovnsl %eax, %ecx
movl %edi, 0x586c2f(%rip)    # 0x5d0e60
andl %ebp, %ecx
decl %r13d
testl %r15d, %r15d
cmovnsl %eax, %r13d
andl %r15d, %r13d
imull 0x8(%rsp), %r13d
leal (%r13,%rcx,4), %ecx
movslq %ecx, %rdx
addq 0x586bb3(%rip), %rdx    # 0x5d0e08
xorl %eax, %ebp
addl %r12d, %ebp
movl %ebp, %esi
movl 0xc(%rsp), %ecx
sarl %cl, %esi
testl %esi, %esi
cmovlel %edi, %esi
addl 0x586ba7(%rip), %ebp    # 0x5d0e14
sarl %cl, %ebp
movl %eax, 0x586bef(%rip)    # 0x5d0e64
cmpl %r14d, %ebp
cmovgel %r14d, %ebp
movq %rdx, 0x586be5(%rip)    # 0x5d0e68
movl %r14d, %edx
subl %esi, %edx
movl %edx, 0x586be2(%rip)    # 0x5d0e70
movl %r14d, %eax
subl %ebp, %eax
movl %eax, 0x586bdb(%rip)    # 0x5d0e74
movq 0x10(%rsp), %rsi
cmpl $0x2, %esi
je 0x4a2cf
cmpl $0x6, %esi
je 0x4a2b9
cmpl $0x4, %esi
jne 0x4a303
addl %edx, %edx
movl %edx, 0x586bbb(%rip)    # 0x5d0e70
addl %eax, %eax
jmp 0x4a2e1
leal -0x2(,%rdx,4), %edx
movl %edx, 0x586baa(%rip)    # 0x5d0e70
leal -0x2(,%rax,4), %eax
jmp 0x4a2e1
leal (%rdx,%rdx,2), %edx
addl $-0x2, %edx
movl %edx, 0x586b95(%rip)    # 0x5d0e70
leal (%rax,%rax,2), %eax
addl $-0x2, %eax
movl %eax, 0x586b8d(%rip)    # 0x5d0e74
movl $0x4, %eax
shll %cl, %eax
movl %eax, 0x586b54(%rip)    # 0x5d0e48
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x4(%rsp), %esi
cmpl $0x4, %esi
je 0x4a354
cmpl $0x2, %esi
je 0x4a331
cmpl $0x1, %esi
jne 0x4a2e7
negl %r14d
andl $0x7, %r14d
addl %r14d, %edx
addl $0x7, %edx
movl %edx, 0x586b47(%rip)    # 0x5d0e70
addl %r14d, %eax
addl $0x7, %eax
jmp 0x4a2e1
negl %r14d
andl $0x3, %r14d
addl %r14d, %edx
leal 0x6(,%rdx,2), %edx
movl %edx, 0x586b28(%rip)    # 0x5d0e70
addl %r14d, %eax
leal 0x6(,%rax,2), %eax
jmp 0x4a2e1
andl $0x1, %r14d
addl %r14d, %edx
leal 0x4(,%rdx,4), %edx
movl %edx, 0x586b08(%rip)    # 0x5d0e70
addl %r14d, %eax
leal 0x4(,%rax,4), %eax
jmp 0x4a2e1