// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movl 0x558d7a(%rip), %eax    # 0x5c2d98
shll $0x2, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %ecx
movl $0x4020100, %eax        # imm = 0x4020100
sarl %cl, %eax
andl $0xf, %eax
movl %eax, 0x558db1(%rip)    # 0x5c2de8
movl -0x4(%rbp), %ecx
movl $0x402010, %eax         # imm = 0x402010
sarl %cl, %eax
andl $0xf, %eax
movl %eax, 0x558da2(%rip)    # 0x5c2dec
movl 0x558d98(%rip), %eax    # 0x5c2de8
cmpl 0x558d3a(%rip), %eax    # 0x5c2d90
jge 0x6a066
movl 0x558d8e(%rip), %eax    # 0x5c2dec
cmpl 0x558d30(%rip), %eax    # 0x5c2d94
jl 0x6a085
cmpl $0x2, 0x558d2b(%rip)    # 0x5c2d98
jl 0x6a085
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl 0x558d1c(%rip), %eax    # 0x5c2d98
addl $-0x1, %eax
movl %eax, 0x558d13(%rip)    # 0x5c2d98
jmp 0x6a087
cmpl $0x0, -0x4(%rbp)
jl 0x6a018
movb -0x4(%rbp), %cl
movl $0x33221100, %eax       # imm = 0x33221100
shrl %cl, %eax
andl $0xf, %eax
movl %eax, -0x8(%rbp)
movb -0x8(%rbp), %cl
movl $0x1, %eax
movl %eax, %edx
shll %cl, %edx
movl %edx, %ecx
movl %ecx, 0x558d3f(%rip)    # 0x5c2df0
movb -0x4(%rbp), %cl
movl $0x33322110, %edx       # imm = 0x33322110
shrl %cl, %edx
movl %edx, %ecx
andl $0xf, %ecx
movl %ecx, -0xc(%rbp)
movb -0xc(%rbp), %cl
shll %cl, %eax
movl %eax, 0x558d26(%rip)    # 0x5c2df4
movl 0x558cbc(%rip), %ecx    # 0x5c2d90
movl 0x558d16(%rip), %eax    # 0x5c2df0
addl %eax, %ecx
movl 0x558d06(%rip), %eax    # 0x5c2de8
notl %eax
addl %ecx, %eax
movb -0x8(%rbp), %cl
sarl %cl, %eax
movl %eax, 0x558d07(%rip)    # 0x5c2df8
movl 0x558cb9(%rip), %eax    # 0x5c2db0
movb -0xc(%rbp), %cl
shll %cl, %eax
movl %eax, 0x558cfa(%rip)    # 0x5c2dfc
movb 0x558c78(%rip), %cl     # 0x5c2d80
shlb $0x2, %cl
movl $0x4021301, %eax        # imm = 0x4021301
shrl %cl, %eax
andl $0x7, %eax
movl 0x558cdd(%rip), %ecx    # 0x5c2df8
imull %ecx, %eax
movl %eax, 0x558cbc(%rip)    # 0x5c2de0
movsbl 0x558c56(%rip), %eax    # 0x5c2d81
movl %eax, -0x10(%rbp)
subl $0x1, %eax
je 0x6a149
jmp 0x6a135
movl -0x10(%rbp), %eax
subl $0x2, %eax
je 0x6a15d
jmp 0x6a13f
movl -0x10(%rbp), %eax
subl $0x4, %eax
je 0x6a171
jmp 0x6a182
movl 0x558c91(%rip), %eax    # 0x5c2de0
addl $0x7, %eax
sarl $0x3, %eax
movl %eax, 0x558c85(%rip)    # 0x5c2de0
jmp 0x6a182
movl 0x558c7d(%rip), %eax    # 0x5c2de0
addl $0x3, %eax
sarl $0x2, %eax
movl %eax, 0x558c71(%rip)    # 0x5c2de0
jmp 0x6a182
movl 0x558c69(%rip), %eax    # 0x5c2de0
addl $0x1, %eax
sarl %eax
movl %eax, 0x558c5e(%rip)    # 0x5c2de0
movl 0x558c58(%rip), %eax    # 0x5c2de0
addl $0x1, %eax
movslq %eax, %rdx
shlq $0x0, %rdx
leaq 0x53ef67(%rip), %rdi    # 0x5a9100
xorl %esi, %esi
callq 0x62d0
movl $0x0, 0x558c56(%rip)    # 0x5c2e00
movl $0x0, 0x558c50(%rip)    # 0x5c2e04
movl 0x558c26(%rip), %eax    # 0x5c2de0
movl %eax, 0x558c48(%rip)    # 0x5c2e08
movl 0x558bfa(%rip), %eax    # 0x5c2dc0
addl 0x558c20(%rip), %eax    # 0x5c2dec
movl %eax, 0x558c12(%rip)    # 0x5c2de4
movl $0x0, 0x558c30(%rip)    # 0x5c2e0c
movl $0xffffffff, 0x558c2a(%rip) # imm = 0xFFFFFFFF
movl 0x558bd0(%rip), %eax    # 0x5c2dbc
addl 0x558bf6(%rip), %eax    # 0x5c2de8
movl %eax, -0x4(%rbp)
cmpl $0x0, -0x4(%rbp)
setge %al
andb $0x1, %al
movzbl %al, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl 0x558be5(%rip), %ecx    # 0x5c2df0
subl $0x1, %ecx
orl %ecx, %eax
andl -0x4(%rbp), %eax
movl %eax, -0x4(%rbp)
cmpl $0x0, 0x558bc7(%rip)    # 0x5c2de4
setge %al
andb $0x1, %al
movzbl %al, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl 0x558bc5(%rip), %ecx    # 0x5c2df4
subl $0x1, %ecx
orl %ecx, %eax
andl 0x558baa(%rip), %eax    # 0x5c2de4
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
imull 0x558b69(%rip), %eax    # 0x5c2db0
movl -0x4(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
cltq
addq 0x558b50(%rip), %rax    # 0x5c2da8
movq %rax, 0x558bb9(%rip)    # 0x5c2e18
xorl %eax, %eax
subl 0x558b55(%rip), %eax    # 0x5c2dbc
subl 0x558b7b(%rip), %eax    # 0x5c2de8
movl -0x8(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
addl %ecx, %eax
subl $0x1, %eax
movl -0x8(%rbp), %ecx
sarl %cl, %eax
cmpl $0x0, %eax
jle 0x6a2b1
xorl %eax, %eax
subl 0x558b2c(%rip), %eax    # 0x5c2dbc
subl 0x558b52(%rip), %eax    # 0x5c2de8
movl -0x8(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
addl %ecx, %eax
subl $0x1, %eax
movl -0x8(%rbp), %ecx
sarl %cl, %eax
movl %eax, -0x14(%rbp)
jmp 0x6a2b8
xorl %eax, %eax
movl %eax, -0x14(%rbp)
jmp 0x6a2b8
movl -0x14(%rbp), %eax
movl %eax, 0x558b5f(%rip)    # 0x5c2e20
movl 0x558aed(%rip), %eax    # 0x5c2db4
subl 0x558aef(%rip), %eax    # 0x5c2dbc
subl 0x558b15(%rip), %eax    # 0x5c2de8
movl -0x8(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
addl %ecx, %eax
subl $0x1, %eax
movl -0x8(%rbp), %ecx
sarl %cl, %eax
cmpl 0x558b09(%rip), %eax    # 0x5c2df8
jge 0x6a31e
movl 0x558abd(%rip), %eax    # 0x5c2db4
subl 0x558abf(%rip), %eax    # 0x5c2dbc
subl 0x558ae5(%rip), %eax    # 0x5c2de8
movl -0x8(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
addl %ecx, %eax
subl $0x1, %eax
movl -0x8(%rbp), %ecx
sarl %cl, %eax
movl %eax, -0x18(%rbp)
jmp 0x6a327
movl 0x558ad4(%rip), %eax    # 0x5c2df8
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl %eax, 0x558af4(%rip)    # 0x5c2e24
movl 0x558ac2(%rip), %eax    # 0x5c2df8
subl 0x558ae4(%rip), %eax    # 0x5c2e20
movl %eax, 0x558ade(%rip)    # 0x5c2e20
movl 0x558ab0(%rip), %eax    # 0x5c2df8
subl 0x558ad6(%rip), %eax    # 0x5c2e24
movl %eax, 0x558ad0(%rip)    # 0x5c2e24
movsbl 0x558a25(%rip), %eax    # 0x5c2d80
cmpl $0x4, %eax
jne 0x6a381
movl 0x558aba(%rip), %eax    # 0x5c2e20
shll %eax
movl %eax, 0x558ab2(%rip)    # 0x5c2e20
movl 0x558ab0(%rip), %eax    # 0x5c2e24
shll %eax
movl %eax, 0x558aa8(%rip)    # 0x5c2e24
jmp 0x6a4c7
movsbl 0x5589f8(%rip), %eax    # 0x5c2d80
cmpl $0x2, %eax
jne 0x6a3b2
imull $0x3, 0x558a8c(%rip), %eax # 0x5c2e20
subl $0x2, %eax
movl %eax, 0x558a83(%rip)    # 0x5c2e20
imull $0x3, 0x558a80(%rip), %eax # 0x5c2e24
subl $0x2, %eax
movl %eax, 0x558a77(%rip)    # 0x5c2e24
jmp 0x6a4c5
movsbl 0x5589c7(%rip), %eax    # 0x5c2d80
cmpl $0x6, %eax
jne 0x6a3e7
movl 0x558a5c(%rip), %eax    # 0x5c2e20
shll $0x2, %eax
subl $0x2, %eax
movl %eax, 0x558a50(%rip)    # 0x5c2e20
movl 0x558a4e(%rip), %eax    # 0x5c2e24
shll $0x2, %eax
subl $0x2, %eax
movl %eax, 0x558a42(%rip)    # 0x5c2e24
jmp 0x6a4c3
movsbl 0x558993(%rip), %eax    # 0x5c2d81
movl %eax, -0x1c(%rbp)
subl $0x1, %eax
je 0x6a40f
jmp 0x6a3f8
movl -0x1c(%rbp), %eax
subl $0x2, %eax
je 0x6a445
jmp 0x6a402
movl -0x1c(%rbp), %eax
subl $0x4, %eax
je 0x6a483
jmp 0x6a4c1
xorl %eax, %eax
subl 0x5589e1(%rip), %eax    # 0x5c2df8
andl $0x7, %eax
addl $0x7, %eax
addl 0x5589fd(%rip), %eax    # 0x5c2e20
movl %eax, 0x5589f7(%rip)    # 0x5c2e20
xorl %eax, %eax
subl 0x5589c7(%rip), %eax    # 0x5c2df8
andl $0x7, %eax
addl $0x7, %eax
addl 0x5589e7(%rip), %eax    # 0x5c2e24
movl %eax, 0x5589e1(%rip)    # 0x5c2e24
jmp 0x6a4c1
movl 0x5589d5(%rip), %eax    # 0x5c2e20
xorl %ecx, %ecx
subl 0x5589a5(%rip), %ecx    # 0x5c2df8
andl $0x3, %ecx
addl %ecx, %eax
addl $0x3, %eax
shll %eax
movl %eax, 0x5589bd(%rip)    # 0x5c2e20
movl 0x5589bb(%rip), %eax    # 0x5c2e24
xorl %ecx, %ecx
subl 0x558987(%rip), %ecx    # 0x5c2df8
andl $0x3, %ecx
addl %ecx, %eax
addl $0x3, %eax
shll %eax
movl %eax, 0x5589a3(%rip)    # 0x5c2e24
jmp 0x6a4c1
movl 0x558997(%rip), %eax    # 0x5c2e20
xorl %ecx, %ecx
subl 0x558967(%rip), %ecx    # 0x5c2df8
andl $0x1, %ecx
addl %ecx, %eax
addl $0x1, %eax
shll $0x2, %eax
movl %eax, 0x55897e(%rip)    # 0x5c2e20
movl 0x55897c(%rip), %eax    # 0x5c2e24
xorl %ecx, %ecx
subl 0x558948(%rip), %ecx    # 0x5c2df8
andl $0x1, %ecx
addl %ecx, %eax
addl $0x1, %eax
shll $0x2, %eax
movl %eax, 0x558963(%rip)    # 0x5c2e24
jmp 0x6a4c3
jmp 0x6a4c5
jmp 0x6a4c7
movl 0x558923(%rip), %eax    # 0x5c2df0
shll $0x2, %eax
movl %eax, 0x55891a(%rip)    # 0x5c2df0
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nop