// File: /workspace/github_c_makefile_star2_O2/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
movl %edi, %r15d
movslq %esi, %rcx
leaq 0x396003(%rip), %rax    # 0x3d07c0
movq %rcx, 0x20(%rsp)
movswq (%rax,%rcx,2), %rbx
leaq 0x40c6a2(%rip), %rax    # 0x446e70
movswq (%rax,%rbx,2), %rax
imulq $0x28, %rax, %rax
leaq 0x202282(%rip), %rcx    # 0x23ca60
addq %rcx, %rax
movl 0x23a2b4(%rip), %r9d    # 0x274a9c
movslq 0x31c2d9(%rip), %rcx    # 0x356ac8
cmpq $0x10000, %rcx          # imm = 0x10000
je 0x3a818
movl 0x23a296(%rip), %edx    # 0x274a94
sarl %edx
movl %r9d, %esi
subl %edx, %esi
movslq %esi, %rsi
imulq %rcx, %rsi
shrq $0x10, %rsi
addl %edx, %esi
movl %esi, 0x23a284(%rip)    # 0x274a9c
movslq 0x38d51d(%rip), %rcx    # 0x3c7d3c
movl %ecx, 0x3d300b(%rip)    # 0x40d830
movb 0x20(%rax), %dl
testb %dl, %dl
je 0x3a840
addb $0x10, %dl
movzbl %dl, %edx
imulq %rcx, %rdx
shrq $0x4, %rdx
movl %edx, 0x3d2ff0(%rip)    # 0x40d830
xorl %edx, %edx
testb %r15b, %r15b
setne %dl
leaq 0x392341(%rip), %rcx    # 0x3ccb90
leaq 0x41041a(%rip), %rsi    # 0x44ac70
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rsp)
leaq 0x40e60a(%rip), %rcx    # 0x448e70
leaq 0x394123(%rip), %rsi    # 0x3ce990
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, 0x3ce773(%rip)    # 0x409004
movw %cx, 0x3ce778(%rip)     # 0x409010
movl %edi, 0x3d2f8e(%rip)    # 0x40d82c
movl %esi, 0x41223c(%rip)    # 0x44cae0
movzbl 0x17(%rax,%rdx,8), %ebp
movl %ebp, 0x412235(%rip)    # 0x44cae4
leaq 0x35722a(%rip), %rax    # 0x391ae0
cmpq $0x0, (%rax,%r8,8)
jne 0x3a8c4
andl $0x0, 0x3ce740(%rip)    # 0x409004
cmpw $0x2400, %cx            # imm = 0x2400
jb 0x3a8d5
andw $0x0, 0x3ce73d(%rip)    # 0x409010
xorl %ecx, %ecx
movzwl %cx, %r14d
leaq 0x1f9180(%rip), %rax    # 0x233a60
testb $-0x40, (%rax,%r14,4)
movl %r9d, 0x18(%rsp)
je 0x3a905
movswl %r14w, %edi
xorl %esi, %esi
callq 0x2163b
addl %r14d, %eax
movw %ax, 0x3ce70f(%rip)     # 0x409010
movswq %ax, %r14
leaq 0x3d2f44(%rip), %rax    # 0x40d850
movzbl (%r14,%rax), %edx
movl %edx, %eax
shrl $0x4, %eax
leaq 0x62e93(%rip), %rdi     # 0x9d7b0
leaq 0x3bfebc(%rip), %rcx    # 0x3fa7e0
movswl (%rcx,%r14,2), %esi
xorl %ecx, %ecx
cmpl %esi, (%rdi,%rax,4)
setne %cl
addl %eax, %ecx
pushq $0x20
popq %rax
subl %ecx, %eax
sarl %esi
addl 0x31c184(%rip), %esi    # 0x356ac4
negl %ecx
shll %cl, %esi
movw %ax, 0x41219d(%rip)     # 0x44cae8
shll $0x18, %ebp
addb $-0x13, %al
pushq $0x8
popq %rdi
movl %eax, %ecx
shll %cl, %edi
addl %esi, %ebp
movl %ebp, 0x41218d(%rip)    # 0x44caec
movl %edi, 0x41218b(%rip)    # 0x44caf0
andl $0xf, %edx
movswl 0x31c151(%rip), %eax    # 0x356ac0
addl %edx, %eax
pushq $0xb
popq %r13
subl %eax, %r13d
pushq $-0x1
popq %rax
leaq 0x1770ce(%rip), %rbp    # 0x1b1a50
leaq 0x564997(%rip), %r14    # 0x59f320
movl %eax, %r12d
movl %r15d, 0x1c(%rsp)
movl %r12d, %eax
testw %bx, %bx
js 0x3ad0d
movzwl %bx, %edx
leaq 0x1f70a9(%rip), %rcx    # 0x231a50
movq %rdx, 0x10(%rsp)
movswq (%rcx,%rdx,2), %rdx
shlq $0x5, %rdx
movswq 0xc(%rdx,%rbp), %rcx
testq %rcx, %rcx
js 0x3aadb
addq %rbp, %rdx
xorl %esi, %esi
testb %r15b, %r15b
setne %dil
testb $0x20, 0xe(%rdx)
jne 0x3aadb
imulq $0x28, %rcx, %rcx
leaq 0x20207b(%rip), %rdx    # 0x23ca60
addq %rdx, %rcx
movb %dil, %sil
movzwl 0xc(%rcx,%rsi,2), %ecx
andl $0x1, %ecx
je 0x3aadb
testl %r12d, %r12d
js 0x3acf8
movswq 0x3ce606(%rip), %r15    # 0x409010
leaq 0x3d2e3f(%rip), %rcx    # 0x40d850
movzbl (%r15,%rcx), %ebx
andl $0xf, %ebx
movl (%r14,%rax,4), %edi
movl %edi, %edx
movl %ebx, %ecx
sarl %cl, %edx
movslq %edx, %rcx
leaq 0x31be93(%rip), %rdx    # 0x3568c0
movzwl (%rdx,%rcx,2), %edx
addw %r15w, %dx
movw %dx, 0x3ce5d4(%rip)     # 0x409010
leaq 0x22a02d(%rip), %rcx    # 0x264a70
movq 0x10(%rsp), %rsi
movslq (%rcx,%rsi,4), %rsi
xorl -0x4(%r14,%rsi,4), %edi
movl %ebx, %ecx
sarl %cl, %edi
testl %edi, %edi
je 0x3acc7
leaq (%r14,%rax,4), %rbp
movl %r12d, %edi
cmpl %r12d, %esi
jle 0x3acb3
movl (%rbp), %eax
movl %ebx, %ecx
sarl %cl, %eax
cltq
leaq 0x31be43(%rip), %rcx    # 0x3568c0
movswl (%rcx,%rax,2), %r14d
addl %r15d, %r14d
movswl %dx, %eax
cmpl %eax, %r14d
je 0x3aacb
leal -0x1(%r12), %esi
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
leaq 0x56847e(%rip), %r8     # 0x5a2f20
leaq 0x564877(%rip), %r9     # 0x59f320
callq 0x3b1ef
movw %r14w, 0x3ce55a(%rip)   # 0x409010
leaq 0x229fb3(%rip), %rax    # 0x264a70
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %esi
movl %r14d, %edx
movl %r12d, %edi
addq $0x4, %rbp
incl %r12d
leaq 0x564847(%rip), %r14    # 0x59f320
jmp 0x3aa64
cmpl $-0x1, %r12d
jne 0x3aaf1
leaq 0x229f88(%rip), %rax    # 0x264a70
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %r12d
movb 0x31bfcb(%rip), %al     # 0x356ac2
testb %al, %al
je 0x3ac21
movq 0x10(%rsp), %rcx
leal (,%rcx,4), %ecx
leaq 0x229f5e(%rip), %rdx    # 0x264a70
movl (%rcx,%rdx), %edx
leaq 0x22df64(%rip), %rsi    # 0x268a80
movl (%rcx,%rsi), %esi
movzwl 0x38d20a(%rip), %edi    # 0x3c7d30
movslq %edx, %r8
movslq %esi, %r9
leaq (%r8,%r8), %r10
leaq (,%r8,4), %r11
xorl %ebx, %ebx
leaq (%r8,%rbx), %rcx
cmpq %r9, %rcx
jg 0x3ab6d
leaq (%r10,%rbx,2), %rcx
leaq 0x4185b2(%rip), %rbp    # 0x453100
movzwl (%rbp,%rcx), %ebp
addl %edi, %ebp
andl $0x7ff, %ebp            # imm = 0x7FF
movl %r13d, %ecx
shrl %cl, %ebp
leaq (%r11,%rbx,4), %rcx
movl %ebp, (%r14,%rcx)
incq %rbx
jmp 0x3ab3a
leaq 0x176edc(%rip), %rbp    # 0x1b1a50
movslq %edx, %rcx
cmpb $0x2, %al
leaq 0x38d1d0(%rip), %r11    # 0x3c7d50
leaq 0x568399(%rip), %rbx    # 0x5a2f20
jne 0x3abf9
movslq 0x38d1a4(%rip), %rax    # 0x3c7d34
movslq 0x38e1b9(%rip), %rdx    # 0x3c8d50
imulq %rax, %rdx
shrq $0x10, %rdx
movslq %edx, %rax
movslq %esi, %rdx
leaq (%rcx,%rcx), %rsi
leaq (,%rcx,4), %rdi
xorl %r8d, %r8d
leaq (%rcx,%r8), %r9
cmpq %rdx, %r9
jg 0x3acf8
leaq (%rsi,%r8,2), %r9
leaq 0x418534(%rip), %r10    # 0x453100
movzwl (%r10,%r9), %r9d
addl $0x200, %r9d            # imm = 0x200
andl $0x7ff, %r9d            # imm = 0x7FF
movswq (%r11,%r9,2), %r9
imulq %rax, %r9
shrq $0xe, %r9
leaq (%rdi,%r8,4), %r10
movl %r9d, (%rbx,%r10)
incq %r8
jmp 0x3abb4
leaq (%rbx,%rcx,4), %rdi
subl %ecx, %esi
incl %esi
movslq 0x38d12c(%rip), %rax    # 0x3c7d34
movslq 0x38e141(%rip), %rdx    # 0x3c8d50
imulq %rax, %rdx
shrq $0x10, %rdx
callq 0x444af
jmp 0x3acf8
movslq 0x3f4974(%rip), %rcx    # 0x42f59c
movslq 0x38e121(%rip), %rdi    # 0x3c8d50
imulq %rcx, %rdi
movq 0x10(%rsp), %rcx
leal (,%rcx,4), %ecx
leaq 0x229e2a(%rip), %rdx    # 0x264a70
movl (%rcx,%rdx), %edx
leaq 0x22de30(%rip), %rsi    # 0x268a80
movl (%rcx,%rsi), %esi
movslq 0x3d720a(%rip), %rcx    # 0x411e64
shrq $0x10, %rdi
movslq %edi, %rdi
movzwl 0x38d0c7(%rip), %r8d    # 0x3c7d30
movslq %edx, %r9
movslq %esi, %r10
movq %r9, %r11
subq %rcx, %r11
imulq %rdi, %r11
leaq (%r14,%r9,4), %rbx
cmpq %r10, %r9
jg 0x3ab74
movq %r11, %r14
shrq $0x17, %r14
addl %r8d, %r14d
andl $0x7ff, %r14d           # imm = 0x7FF
movl %r13d, %ecx
shrl %cl, %r14d
movl %r14d, (%rbx)
leaq 0x564679(%rip), %r14    # 0x59f320
incq %r9
addq %rdi, %r11
addq $0x4, %rbx
jmp 0x3ac7d
cmpl %r12d, %edi
leaq 0x176d93(%rip), %rbp    # 0x1b1a50
jge 0x3ace5
decl %r12d
movl %r12d, %esi
jmp 0x3accd
decq %rsi
movl %r12d, %edi
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
leaq 0x568243(%rip), %r8     # 0x5a2f20
movq %r14, %r9
callq 0x3b1ef
movw %r15w, 0x3ce323(%rip)   # 0x409010
pushq $-0x1
popq %rax
movl %eax, %r12d
movl 0x1c(%rsp), %r15d
leaq 0x39dad1(%rip), %rax    # 0x3d87d0
movq 0x10(%rsp), %rcx
movzwl (%rax,%rcx,2), %ebx
jmp 0x3a991
testl %r12d, %r12d
js 0x3ae41
movq %r14, %r8
movswq 0x3ce2ef(%rip), %r14    # 0x409010
leaq 0x3d2b28(%rip), %rcx    # 0x40d850
movzbl (%r14,%rcx), %ebp
andl $0xf, %ebp
movl (%r8,%rax,4), %edi
movl %edi, %edx
movl %ebp, %ecx
sarl %cl, %edx
movslq %edx, %rcx
leaq 0x31bb7c(%rip), %rdx    # 0x3568c0
movzwl (%rdx,%rcx,2), %edx
addw %r14w, %dx
movw %dx, 0x3ce2bd(%rip)     # 0x409010
leaq 0x397a66(%rip), %rsi    # 0x3d27c0
movq 0x20(%rsp), %rcx
movswq (%rsi,%rcx,2), %rcx
leaq 0x22dd15(%rip), %rsi    # 0x268a80
movslq (%rsi,%rcx,4), %rsi
xorl (%r8,%rsi,4), %edi
movl %ebp, %ecx
sarl %cl, %edi
testl %edi, %edi
je 0x3ae1a
leaq (%r8,%rax,4), %r13
leaq 0x568196(%rip), %rbx    # 0x5a2f20
movl %r12d, %edi
cmpl %r12d, %esi
jl 0x3ae02
movl (%r13), %eax
movl %ebp, %ecx
sarl %cl, %eax
cltq
leaq 0x31bb1d(%rip), %rcx    # 0x3568c0
movswl (%rcx,%rax,2), %r15d
addl %r14d, %r15d
movswl %dx, %eax
cmpl %eax, %r15d
je 0x3adf9
leal -0x1(%r12), %esi
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
movq %rbx, %r8
leaq 0x564555(%rip), %r9     # 0x59f320
callq 0x3b1ef
movw %r15w, 0x3ce238(%rip)   # 0x409010
movq 0x20(%rsp), %rax
leaq 0x3979dc(%rip), %rcx    # 0x3d27c0
movswq (%rcx,%rax,2), %rax
leaq 0x22dc90(%rip), %rcx    # 0x268a80
movl (%rcx,%rax,4), %esi
movl %r15d, %edx
movl %r12d, %edi
addq $0x4, %r13
incl %r12d
jmp 0x3ad8d
cmpl %r12d, %edi
jg 0x3ae39
leaq 0x568112(%rip), %r8     # 0x5a2f20
leaq 0x56450b(%rip), %r9     # 0x59f320
movl %r12d, %esi
jmp 0x3ae2b
leaq 0x5680ff(%rip), %r8     # 0x5a2f20
leaq 0x5644f8(%rip), %r9     # 0x59f320
movl %r12d, %edi
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
callq 0x3b1ef
movw %r14w, 0x3ce1cf(%rip)   # 0x409010
movl 0x18(%rsp), %eax
movl %eax, 0x239c51(%rip)    # 0x274a9c
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq