// File: /workspace/github_c_makefile_star2_O2/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 0x588507(%rip), %r14d   # 0x5c9df0
movl 0x588509(%rip), %edx    # 0x5c9df8
movl 0x5884ff(%rip), %esi    # 0x5c9df4
pushq $-0x1
popq %rdi
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 0x41929
cmpl $0x2, %edx
jl 0x41938
cmpl %esi, %r15d
jge 0x4192e
jmp 0x41938
cmpl $0x2, %edx
jl 0x41938
decl %edx
movl %edx, 0x5884c2(%rip)    # 0x5c9df8
movl %edi, %eax
testl %eax, %eax
js 0x418f8
movl $0x33221100, %edi       # imm = 0x33221100
movl %eax, %ecx
shrl %cl, %edi
andl $0xf, %edi
pushq $0x1
popq %rsi
movl %esi, %r13d
movl %edi, %ecx
shll %cl, %r13d
movl $0x33322110, %edx       # imm = 0x33322110
movl %eax, %ecx
shrl %cl, %edx
movl %r13d, 0x5884e5(%rip)   # 0x5c9e48
andb $0xf, %dl
movl %esi, %r12d
movl %edx, %ecx
shll %cl, %r12d
movl %ebp, %eax
notl %eax
addl %eax, %r14d
addl %r13d, %r14d
movl %edi, 0xc(%rsp)
movl %edi, %ecx
sarl %cl, %r14d
movl %r12d, 0x5884c4(%rip)   # 0x5c9e4c
movl 0x588482(%rip), %eax    # 0x5c9e10
movl %eax, 0x8(%rsp)
movl %edx, %ecx
shll %cl, %eax
movl %eax, 0x5884b4(%rip)    # 0x5c9e50
movzbl 0x58843d(%rip), %eax    # 0x5c9de0
leal (,%rax,4), %ecx
movl $0x4021301, %ebx        # imm = 0x4021301
shrl %cl, %ebx
andl $0x7, %ebx
imull %r14d, %ebx
movl %ebx, 0x588482(%rip)    # 0x5c9e40
movzbl 0x58841c(%rip), %edx    # 0x5c9de1
cmpl %esi, %edx
movq %rax, 0x10(%rsp)
movl %edx, 0x4(%rsp)
je 0x419e7
cmpl $0x4, %edx
je 0x419e3
cmpl $0x2, %edx
jne 0x419f7
pushq $0x2
popq %rcx
pushq $0x3
jmp 0x419ec
movl %esi, %ecx
jmp 0x419ed
pushq $0x3
popq %rcx
pushq $0x7
popq %rsi
addl %esi, %ebx
sarl %cl, %ebx
movl %ebx, 0x588449(%rip)    # 0x5c9e40
leal 0x1(%rbx), %eax
movslq %eax, %rdx
leaq 0x56e75c(%rip), %rdi    # 0x5b0160
xorl %esi, %esi
callq 0x62f0
andl $0x0, 0x588442(%rip)    # 0x5c9e54
andl $0x0, 0x58843f(%rip)    # 0x5c9e58
addl 0x588400(%rip), %r15d   # 0x5c9e20
andl $0x0, 0x588439(%rip)    # 0x5c9e60
orl $-0x1, 0x588436(%rip)   # 0x5c9e64
addl 0x5883e8(%rip), %ebp    # 0x5c9e1c
leal -0x1(%r13), %eax
testl %ebp, %ebp
pushq $-0x1
popq %rcx
cmovnsl %ecx, %eax
movl %ebx, 0x588416(%rip)    # 0x5c9e5c
andl %ebp, %eax
decl %r12d
testl %r15d, %r15d
cmovnsl %ecx, %r12d
andl %r15d, %r12d
imull 0x8(%rsp), %r12d
leal (%r12,%rax,4), %eax
cltq
addq 0x5883a0(%rip), %rax    # 0x5c9e08
xorl %ecx, %ebp
addl %r13d, %ebp
movl %ebp, %edx
movl 0xc(%rsp), %ecx
sarl %cl, %edx
testl %edx, %edx
movl $0x0, %esi
cmovlel %esi, %edx
addl 0x58838f(%rip), %ebp    # 0x5c9e14
sarl %cl, %ebp
movl %r15d, 0x5883b6(%rip)   # 0x5c9e44
cmpl %r14d, %ebp
cmovgel %r14d, %ebp
movq %rax, 0x5883cc(%rip)    # 0x5c9e68
movl %r14d, %esi
subl %edx, %esi
movl %esi, 0x5883c9(%rip)    # 0x5c9e70
movl %r14d, %eax
subl %ebp, %eax
movl %eax, 0x5883c2(%rip)    # 0x5c9e74
movq 0x10(%rsp), %rdx
cmpl $0x2, %edx
je 0x41ae8
cmpl $0x6, %edx
je 0x41ad2
cmpl $0x4, %edx
jne 0x41b1a
addl %esi, %esi
movl %esi, 0x5883a2(%rip)    # 0x5c9e70
addl %eax, %eax
jmp 0x41afa
leal -0x2(,%rsi,4), %edx
movl %edx, 0x588391(%rip)    # 0x5c9e70
leal -0x2(,%rax,4), %eax
jmp 0x41afa
leal (%rsi,%rsi,2), %edx
addl $-0x2, %edx
movl %edx, 0x58837c(%rip)    # 0x5c9e70
leal (%rax,%rax,2), %eax
addl $-0x2, %eax
movl %eax, 0x588374(%rip)    # 0x5c9e74
pushq $0x4
popq %rax
shll %cl, %eax
movl %eax, 0x58833d(%rip)    # 0x5c9e48
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x4(%rsp), %edx
cmpl $0x4, %edx
je 0x41b6c
cmpl $0x2, %edx
je 0x41b49
cmpl $0x1, %edx
jne 0x41b00
negl %r14d
andl $0x7, %r14d
leal (%rsi,%r14), %edx
addl $0x7, %edx
movl %edx, 0x58832f(%rip)    # 0x5c9e70
addl %r14d, %eax
addl $0x7, %eax
jmp 0x41afa
negl %r14d
andl $0x3, %r14d
addl %r14d, %esi
leal 0x6(,%rsi,2), %edx
movl %edx, 0x588310(%rip)    # 0x5c9e70
addl %r14d, %eax
leal 0x6(,%rax,2), %eax
jmp 0x41afa
andl $0x1, %r14d
addl %r14d, %esi
leal 0x4(,%rsi,4), %edx
movl %edx, 0x5882f0(%rip)    # 0x5c9e70
addl %r14d, %eax
leal 0x4(,%rax,4), %eax
jmp 0x41afa