// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: parascan
static void parascan(int dax1, int dax2, int sectnum, unsigned char dastat, int bunch)
{
	sectortype *sec;
	int j, k, l, m, n, x, z, wallnum, nextsectnum, globalhorizbak;
	short *topptr, *botptr;

	(void)dax1; (void)dax2;

	sectnum = thesector[bunchfirst[bunch]]; sec = &sector[sectnum];

	globalhorizbak = globalhoriz;
	if (parallaxyscale != 65536)
		globalhoriz = mulscale16(globalhoriz-(ydimen>>1),parallaxyscale) + (ydimen>>1);
	globvis = globalpisibility;
	//globalorientation = 0L;
	if (sec->visibility != 0) globvis = mulscale4(globvis,(int)((unsigned char)(sec->visibility+16)));

	if (dastat == 0)
	{
		globalpal = sec->ceilingpal;
		globalpicnum = sec->ceilingpicnum;
		globalshade = (int)sec->ceilingshade;
		globalxpanning = (int)sec->ceilingxpanning;
		globalypanning = (int)sec->ceilingypanning;
		topptr = umost;
		botptr = uplc;
	}
	else
	{
		globalpal = sec->floorpal;
		globalpicnum = sec->floorpicnum;
		globalshade = (int)sec->floorshade;
		globalxpanning = (int)sec->floorxpanning;
		globalypanning = (int)sec->floorypanning;
		topptr = dplc;
		botptr = dmost;
	}

	if (palookup[globalpal] == 0) globalpal = 0;
	if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
	if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,(short)sectnum);
	globalshiftval = (picsiz[globalpicnum]>>4);
	if (pow2long[globalshiftval] != tilesizy[globalpicnum]) globalshiftval++;
	globalshiftval = 32-globalshiftval;
	globalzd = (((tilesizy[globalpicnum]>>1)+parallaxyoffs)<<globalshiftval)+(globalypanning<<24);
	globalyscale = (8<<(globalshiftval-19));
	//if (globalorientation&256) globalyscale = -globalyscale, globalzd = -globalzd;

	k = 11 - (picsiz[globalpicnum]&15) - pskybits;
	x = -1;

	for(z=bunchfirst[bunch];z>=0;z=p2[z])
	{
		wallnum = thewall[z]; nextsectnum = wall[wallnum].nextsector;

		if (dastat == 0) j = sector[nextsectnum].ceilingstat;
						else j = sector[nextsectnum].floorstat;

		if ((nextsectnum < 0) || (wall[wallnum].cstat&32) || ((j&1) == 0))
		{
			if (x == -1) x = xb1[z];

			if (parallaxtype == 0)
			{
				n = mulscale16(xdimenrecip,viewingrange);
				for(j=xb1[z];j<=xb2[z];j++)
					lplc[j] = (((mulscale23(j-halfxdimen,n)+globalang)&2047)>>k);
			}
			else
			{
				for(j=xb1[z];j<=xb2[z];j++)
					lplc[j] = ((((int)radarang2[j]+globalang)&2047)>>k);
			}
			if (parallaxtype == 2)
			{
				n = mulscale16(xdimscale,viewingrange);
				for(j=xb1[z];j<=xb2[z];j++)
					swplc[j] = mulscale14(sintable[((int)radarang2[j]+512)&2047],n);
			}
			else
				clearbuf(&swplc[xb1[z]],xb2[z]-xb1[z]+1,mulscale16(xdimscale,viewingrange));
		}
		else if (x >= 0)
		{
			l = globalpicnum; m = (picsiz[globalpicnum]&15);
			globalpicnum = l+pskyoff[lplc[x]>>m];

			if (((lplc[x]^lplc[xb1[z]-1])>>m) == 0)
				wallscan(x,xb1[z]-1,topptr,botptr,swplc,lplc);
			else
			{
				j = x;
				while (x < xb1[z])
				{
					n = l+pskyoff[lplc[x]>>m];
					if (n != globalpicnum)
					{
						wallscan(j,x-1,topptr,botptr,swplc,lplc);
						j = x;
						globalpicnum = n;
					}
					x++;
				}
				if (j < x)
					wallscan(j,x-1,topptr,botptr,swplc,lplc);
			}

			globalpicnum = l;
			x = -1;
		}
	}

	if (x >= 0)
	{
		l = globalpicnum; m = (picsiz[globalpicnum]&15);
		globalpicnum = l+pskyoff[lplc[x]>>m];

		if (((lplc[x]^lplc[xb2[bunchlast[bunch]]])>>m) == 0)
			wallscan(x,xb2[bunchlast[bunch]],topptr,botptr,swplc,lplc);
		else
		{
			j = x;
			while (x <= xb2[bunchlast[bunch]])
			{
				n = l+pskyoff[lplc[x]>>m];
				if (n != globalpicnum)
				{
					wallscan(j,x-1,topptr,botptr,swplc,lplc);
					j = x;
					globalpicnum = n;
				}
				x++;
			}
			if (j <= x)
				wallscan(j,x,topptr,botptr,swplc,lplc);
		}
		globalpicnum = l;
	}
	globalhoriz = globalhorizbak;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movslq %esi, %rcx
leaq 0x3990c4(%rip), %rax    # 0x3d77c0
movq %rcx, 0x20(%rsp)
movswq (%rax,%rcx,2), %rbx
leaq 0x40f763(%rip), %rax    # 0x44de70
movswq (%rax,%rbx,2), %rax
leaq (%rax,%rax,4), %rax
leaq 0x205343(%rip), %rcx    # 0x243a60
leaq (%rcx,%rax,8), %rax
movl 0x23d374(%rip), %r13d   # 0x27ba9c
movslq 0x31f399(%rip), %rcx    # 0x35dac8
cmpq $0x10000, %rcx          # imm = 0x10000
je 0x3e758
movl 0x23d356(%rip), %edx    # 0x27ba94
sarl %edx
movl %r13d, %esi
subl %edx, %esi
movslq %esi, %rsi
imulq %rcx, %rsi
shrq $0x10, %rsi
addl %edx, %esi
movl %esi, 0x23d344(%rip)    # 0x27ba9c
movslq 0x3905dd(%rip), %rcx    # 0x3ced3c
movl %ecx, 0x3d60cb(%rip)    # 0x414830
movb 0x20(%rax), %dl
testb %dl, %dl
je 0x3e780
addb $0x10, %dl
movzbl %dl, %edx
imulq %rcx, %rdx
shrq $0x4, %rdx
movl %edx, 0x3d60b0(%rip)    # 0x414830
xorl %edx, %edx
movl %edi, 0x1c(%rsp)
testb %dil, %dil
setne %dl
leaq 0x3953fd(%rip), %rcx    # 0x3d3b90
leaq 0x4134d6(%rip), %rsi    # 0x451c70
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rsp)
leaq 0x4116c6(%rip), %rcx    # 0x44fe70
leaq 0x3971df(%rip), %rsi    # 0x3d5990
cmoveq %rcx, %rsi
movq %rsi, (%rsp)
movzbl 0x16(%rax,%rdx,8), %esi
movsbl 0x14(%rax,%rdx,8), %edi
movzwl 0x10(%rax,%rdx,8), %ecx
movzbl 0x15(%rax,%rdx,8), %r8d
movl %r8d, 0x3d182f(%rip)    # 0x410004
movw %cx, 0x3d1834(%rip)     # 0x410010
movl %edi, 0x3d604a(%rip)    # 0x41482c
movl %esi, 0x4152f8(%rip)    # 0x453ae0
movzbl 0x17(%rax,%rdx,8), %ebp
movl %ebp, 0x4152f1(%rip)    # 0x453ae4
leaq 0x35a2e6(%rip), %rax    # 0x398ae0
cmpq $0x0, (%rax,%r8,8)
jne 0x3e80b
movl $0x0, 0x3d17f9(%rip)    # 0x410004
movzwl %cx, %eax
cmpl $0x2400, %eax           # imm = 0x2400
jb 0x3e820
movw $0x0, 0x3d17f2(%rip)    # 0x410010
xorl %ecx, %ecx
movzwl %cx, %r14d
leaq 0x1fc235(%rip), %rax    # 0x23aa60
testb $-0x40, (%rax,%r14,4)
je 0x3e84b
movswl %r14w, %edi
xorl %esi, %esi
callq 0x242cd
addl %r14d, %eax
movw %ax, 0x3d17c9(%rip)     # 0x410010
movswq %ax, %r14
leaq 0x3d5ffe(%rip), %rax    # 0x414850
movzbl (%r14,%rax), %edx
movl %edx, %eax
shrl $0x4, %eax
leaq 0x65f4d(%rip), %rdi     # 0xa47b0
leaq 0x3c2f76(%rip), %rcx    # 0x4017e0
movswl (%rcx,%r14,2), %esi
xorl %ecx, %ecx
cmpl %esi, (%rdi,%rax,4)
setne %cl
addl %eax, %ecx
movl $0x20, %eax
subl %ecx, %eax
sarl %esi
addl 0x31f23c(%rip), %esi    # 0x35dac4
negl %ecx
shll %cl, %esi
movw %ax, 0x415255(%rip)     # 0x453ae8
shll $0x18, %ebp
addb $-0x13, %al
movl $0x8, %edi
movl %eax, %ecx
shll %cl, %edi
addl %esi, %ebp
movl %ebp, 0x415243(%rip)    # 0x453aec
movl %edi, 0x415241(%rip)    # 0x453af0
testw %bx, %bx
js 0x3ee97
movl %r13d, 0x18(%rsp)
andl $0xf, %edx
movswl 0x31f1f9(%rip), %eax    # 0x35dac0
addl %edx, %eax
movl $0xb, %r13d
subl %eax, %r13d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0x17a171(%rip), %r15    # 0x1b8a50
leaq 0x567a3a(%rip), %r14    # 0x5a6320
movdqa 0x357f2(%rip), %xmm4    # 0x740e0
movdqa 0x357fa(%rip), %xmm5    # 0x740f0
pcmpeqd %xmm6, %xmm6
movl 0x1c(%rsp), %ebp
movzwl %bx, %r8d
leaq 0x1fa147(%rip), %rax    # 0x238a50
movswq (%rax,%r8,2), %rcx
shlq $0x5, %rcx
movswq 0xc(%rcx,%r15), %rax
testq %rax, %rax
movq %r8, 0x10(%rsp)
js 0x3ea6c
addq %r15, %rcx
xorl %edx, %edx
testb %bpl, %bpl
setne %sil
testb $0x20, 0xe(%rcx)
jne 0x3ea6c
leaq (%rax,%rax,4), %rax
leaq 0x205119(%rip), %rcx    # 0x243a60
leaq (%rcx,%rax,8), %rax
movb %sil, %dl
movzwl 0xc(%rax,%rdx,2), %eax
andl $0x1, %eax
je 0x3ea6c
testl %r12d, %r12d
js 0x3ed35
movswq 0x3d16a3(%rip), %r15    # 0x410010
leaq 0x3d5edc(%rip), %rax    # 0x414850
movzbl (%r15,%rax), %ebx
andl $0xf, %ebx
movl %r12d, %edx
movl (%r14,%rdx,4), %edi
movl %edi, %eax
movl %ebx, %ecx
sarl %cl, %eax
cltq
leaq 0x31ef2e(%rip), %rcx    # 0x35d8c0
movzwl (%rcx,%rax,2), %eax
addw %r15w, %ax
movw %ax, 0x3d166f(%rip)     # 0x410010
leaq 0x22d0c8(%rip), %rcx    # 0x26ba70
movslq (%rcx,%r8,4), %rsi
xorl -0x4(%r14,%rsi,4), %edi
movl %ebx, %ecx
sarl %cl, %edi
testl %edi, %edi
je 0x3ece9
cmpl %esi, %r12d
jge 0x3ed20
leaq (%r14,%rdx,4), %rbp
movl %r12d, %edi
movl (%rbp), %edx
movl %ebx, %ecx
sarl %cl, %edx
movslq %edx, %rcx
leaq 0x31eee2(%rip), %rdx    # 0x35d8c0
movswl (%rdx,%rcx,2), %r14d
addl %r15d, %r14d
movswl %ax, %ecx
cmpl %ecx, %r14d
je 0x3ea41
leal -0x1(%r12), %esi
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
leaq 0x56b51d(%rip), %r8     # 0x5a9f20
leaq 0x567916(%rip), %r9     # 0x5a6320
callq 0x3f2ef
movq 0x10(%rsp), %r8
pcmpeqd %xmm6, %xmm6
movdqa 0x356d0(%rip), %xmm5    # 0x740f0
movdqa 0x356b8(%rip), %xmm4    # 0x740e0
movw %r14w, 0x3d15e0(%rip)   # 0x410010
leaq 0x22d039(%rip), %rax    # 0x26ba70
movl (%rax,%r8,4), %esi
movl %r14d, %eax
movl %r12d, %edi
addq $0x4, %rbp
incl %r12d
cmpl %r12d, %esi
jg 0x3e9cd
cmpl %r12d, %edi
movl 0x1c(%rsp), %ebp
leaq 0x5678c5(%rip), %r14    # 0x5a6320
jge 0x3ed20
decl %r12d
movl %r12d, %esi
jmp 0x3ecef
cmpl $-0x1, %r12d
jne 0x3ea7d
leaq 0x22cff7(%rip), %rax    # 0x26ba70
movl (%rax,%r8,4), %r12d
movb 0x31f03f(%rip), %dl     # 0x35dac2
leal (,%r8,4), %ecx
leaq 0x22cfde(%rip), %rax    # 0x26ba70
movslq (%rcx,%rax), %rax
leaq 0x230fe3(%rip), %rsi    # 0x26fa80
movl (%rcx,%rsi), %esi
testb %dl, %dl
je 0x3eafc
cmpl %eax, %esi
jl 0x3ec1d
movzwl 0x39027d(%rip), %edi    # 0x3ced30
leaq (%rax,%rax), %r8
leaq (,%rax,4), %r9
movl %esi, %r10d
subl %eax, %r10d
incl %r10d
xorl %r11d, %r11d
leaq (%r8,%r11,2), %rcx
leaq 0x41b62a(%rip), %rbx    # 0x45a100
movzwl (%rbx,%rcx), %ebx
addl %edi, %ebx
andl $0x7ff, %ebx            # imm = 0x7FF
movl %r13d, %ecx
shrl %cl, %ebx
leaq (%r9,%r11,4), %rcx
movl %ebx, (%r14,%rcx)
incq %r11
cmpl %r11d, %r10d
jne 0x3eacb
jmp 0x3ec1d
cmpl %eax, %esi
jl 0x3eca4
movslq 0x3f7a91(%rip), %rcx    # 0x43659c
movslq 0x39123e(%rip), %rdi    # 0x3cfd50
imulq %rcx, %rdi
movslq 0x3da347(%rip), %rcx    # 0x418e64
shrq $0x10, %rdi
movslq %edi, %r14
movzwl 0x390205(%rip), %edi    # 0x3ced30
movl %esi, %r9d
subl %eax, %r9d
leaq 0x2(%r9), %r8
andq $-0x2, %r8
movq %r9, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movq %rax, %r9
subq %rcx, %r9
imulq %r14, %r9
leaq (%r14,%r14), %r10
leaq 0x5677c8(%rip), %r11    # 0x5a6320
leaq (%r11,%rax,4), %r11
addq $0x4, %r11
negq %rcx
leaq (%rax,%rcx), %rbx
incq %rbx
imulq %r14, %rbx
leaq 0x5677ab(%rip), %r14    # 0x5a6320
pxor %xmm5, %xmm0
xorl %r15d, %r15d
movq %r15, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
por %xmm4, %xmm1
pxor %xmm5, %xmm1
movdqa %xmm1, %xmm2
pcmpgtd %xmm0, %xmm2
pcmpeqd %xmm0, %xmm1
pshufd $0xf5, %xmm1, %xmm3     # xmm3 = xmm1[1,1,3,3]
pand %xmm2, %xmm3
pshufd $0xf5, %xmm2, %xmm1     # xmm1 = xmm2[1,1,3,3]
por %xmm3, %xmm1
movd %xmm1, %ecx
notl %ecx
testb $0x1, %cl
je 0x3ebda
movq %r9, %r14
shrq $0x17, %r14
addl %edi, %r14d
andl $0x7ff, %r14d           # imm = 0x7FF
movl %r13d, %ecx
shrl %cl, %r14d
movl %r14d, -0x4(%r11,%r15,4)
leaq 0x567746(%rip), %r14    # 0x5a6320
pxor %xmm6, %xmm1
pextrw $0x4, %xmm1, %ecx
testb $0x1, %cl
je 0x3ec0a
movq %rbx, %r14
shrq $0x17, %r14
addl %edi, %r14d
andl $0x7ff, %r14d           # imm = 0x7FF
movl %r13d, %ecx
shrl %cl, %r14d
movl %r14d, (%r11,%r15,4)
leaq 0x567716(%rip), %r14    # 0x5a6320
addq $0x2, %r15
addq %r10, %r9
addq %r10, %rbx
cmpq %r15, %r8
jne 0x3eb7c
cmpb $0x2, %dl
leaq 0x179e29(%rip), %r15    # 0x1b8a50
jne 0x3eca4
cmpl %eax, %esi
jl 0x3ece2
movl %eax, %edi
movslq 0x3900fa(%rip), %rcx    # 0x3ced34
movslq 0x39110f(%rip), %rdx    # 0x3cfd50
imulq %rcx, %rdx
shrq $0x10, %rdx
movslq %edx, %rcx
leaq (%rax,%rax), %rdx
shlq $0x2, %rax
subl %edi, %esi
incl %esi
xorl %edi, %edi
leaq 0x56b2bf(%rip), %r10    # 0x5a9f20
leaq 0x41b498(%rip), %r11    # 0x45a100
leaq 0x3900e1(%rip), %rbx    # 0x3ced50
leaq (%rdx,%rdi,2), %r8
movzwl (%r11,%r8), %r8d
addl $0x200, %r8d            # imm = 0x200
andl $0x7ff, %r8d            # imm = 0x7FF
movswq (%rbx,%r8,2), %r8
imulq %rcx, %r8
shrq $0xe, %r8
leaq (%rax,%rdi,4), %r9
movl %r8d, (%r10,%r9)
incq %rdi
cmpl %edi, %esi
jne 0x3ec6f
jmp 0x3ece2
leaq 0x56b275(%rip), %rcx    # 0x5a9f20
leaq (%rcx,%rax,4), %rdi
subl %eax, %esi
incl %esi
movslq 0x39007a(%rip), %rax    # 0x3ced34
movslq 0x39108f(%rip), %rdx    # 0x3cfd50
imulq %rax, %rdx
shrq $0x10, %rdx
callq 0x4d2d8
pcmpeqd %xmm6, %xmm6
movdqa 0x35416(%rip), %xmm5    # 0x740f0
movdqa 0x353fe(%rip), %xmm4    # 0x740e0
movq 0x10(%rsp), %r8
jmp 0x3ed35
decq %rsi
movl %r12d, %edi
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
leaq 0x56b221(%rip), %r8     # 0x5a9f20
movq %r14, %r9
callq 0x3f2ef
movq 0x10(%rsp), %r8
pcmpeqd %xmm6, %xmm6
movdqa 0x353d8(%rip), %xmm5    # 0x740f0
movdqa 0x353c0(%rip), %xmm4    # 0x740e0
movw %r15w, 0x3d12e8(%rip)   # 0x410010
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0x179d1b(%rip), %r15    # 0x1b8a50
leaq 0x3a0a94(%rip), %rax    # 0x3df7d0
movzwl (%rax,%r8,2), %ebx
testw %bx, %bx
jns 0x3e8fe
testl %r12d, %r12d
movl 0x18(%rsp), %r13d
js 0x3ee97
movq %r14, %r9
movswq 0x3d12ad(%rip), %r14    # 0x410010
leaq 0x3d5ae6(%rip), %rax    # 0x414850
movzbl (%r14,%rax), %ebp
andl $0xf, %ebp
movl %r12d, %edi
movl (%r9,%rdi,4), %r8d
movl %r8d, %eax
movl %ebp, %ecx
sarl %cl, %eax
cltq
leaq 0x31eb37(%rip), %rcx    # 0x35d8c0
movzwl (%rcx,%rax,2), %eax
addw %r14w, %ax
movw %ax, 0x3d1278(%rip)     # 0x410010
leaq 0x39aa21(%rip), %r15    # 0x3d97c0
movq 0x20(%rsp), %rcx
movswq (%r15,%rcx,2), %rdx
leaq 0x230cd0(%rip), %rcx    # 0x26fa80
movslq (%rcx,%rdx,4), %rsi
xorl (%r9,%rsi,4), %r8d
movl %ebp, %ecx
sarl %cl, %r8d
testl %r8d, %r8d
je 0x3edd2
cmpl %esi, %r12d
jle 0x3ede8
movl %r12d, %edi
movl %r12d, %esi
jmp 0x3ee73
leaq 0x56b147(%rip), %r8     # 0x5a9f20
leaq 0x567540(%rip), %r9     # 0x5a6320
movl %r12d, %edi
jmp 0x3ee81
leaq 0x567531(%rip), %rcx    # 0x5a6320
leaq (%rcx,%rdi,4), %r13
movl %r12d, %edi
movl (%r13), %esi
movl %ebp, %ecx
sarl %cl, %esi
movslq %esi, %rcx
leaq 0x31eab8(%rip), %rsi    # 0x35d8c0
movswl (%rsi,%rcx,2), %ebx
addl %r14d, %ebx
movswl %ax, %ecx
cmpl %ecx, %ebx
je 0x3ee4d
leal -0x1(%r12), %esi
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
leaq 0x56b0f5(%rip), %r8     # 0x5a9f20
leaq 0x5674ee(%rip), %r9     # 0x5a6320
callq 0x3f2ef
movw %bx, 0x3d11d2(%rip)     # 0x410010
movq 0x20(%rsp), %rax
movzwl (%r15,%rax,2), %edx
movl %ebx, %eax
movl %r12d, %edi
movswq %dx, %rcx
leal 0x1(%r12), %esi
addq $0x4, %r13
leaq 0x230c1f(%rip), %r8     # 0x26fa80
cmpl %r12d, (%r8,%rcx,4)
movl %esi, %r12d
jg 0x3edf6
cmpl %esi, %edi
movl 0x18(%rsp), %r13d
jg 0x3ee8f
leaq 0x56b0a6(%rip), %r8     # 0x5a9f20
leaq 0x56749f(%rip), %r9     # 0x5a6320
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
callq 0x3f2ef
movw %r14w, 0x3d1179(%rip)   # 0x410010
movl %r13d, 0x23cbfe(%rip)   # 0x27ba9c
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq