// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movl %edi, %r13d
movslq %esi, %rax
leaq 0x3994ea(%rip), %r14    # 0x3d67c0
movq %rax, 0x20(%rsp)
movswq (%r14,%rax,2), %rax
leaq 0x40fb89(%rip), %rcx    # 0x44ce70
movswq (%rcx,%rax,2), %rax
leaq (%rax,%rax,4), %rax
leaq 0x205769(%rip), %rcx    # 0x242a60
leaq (%rcx,%rax,8), %rax
movl 0x23d79b(%rip), %edi    # 0x27aa9c
movslq 0x31f7c0(%rip), %rcx    # 0x35cac8
cmpq $0x10000, %rcx          # imm = 0x10000
je 0x3d330
movl 0x23d77d(%rip), %edx    # 0x27aa94
sarl %edx
movl %edi, %esi
subl %edx, %esi
movslq %esi, %rsi
imulq %rcx, %rsi
shrq $0x10, %rsi
addl %edx, %esi
movl %esi, 0x23d76c(%rip)    # 0x27aa9c
movl %edi, 0x34(%rsp)
movslq 0x390a01(%rip), %rcx    # 0x3cdd3c
movl %ecx, 0x3d64ef(%rip)    # 0x413830
movb 0x20(%rax), %dl
testb %dl, %dl
je 0x3d35c
addb $0x10, %dl
movzbl %dl, %edx
imulq %rcx, %rdx
shrq $0x4, %rdx
movl %edx, 0x3d64d4(%rip)    # 0x413830
xorl %ecx, %ecx
testb %r13b, %r13b
setne %cl
leaq 0x395825(%rip), %rdx    # 0x3d2b90
leaq 0x4138fe(%rip), %rsi    # 0x450c70
cmoveq %rdx, %rsi
movq %rsi, 0x10(%rsp)
leaq 0x411aee(%rip), %rdx    # 0x44ee70
leaq 0x397607(%rip), %rsi    # 0x3d4990
cmoveq %rdx, %rsi
movq %rsi, 0x8(%rsp)
movzbl 0x15(%rax,%rcx,8), %edx
movl %edx, 0x3d1c67(%rip)    # 0x40f004
movzwl 0x10(%rax,%rcx,8), %esi
movw %si, 0x3d1c67(%rip)     # 0x40f010
movsbl 0x14(%rax,%rcx,8), %esi
movl %esi, 0x3d6478(%rip)    # 0x41382c
movzbl 0x16(%rax,%rcx,8), %esi
movl %esi, 0x415721(%rip)    # 0x452ae0
movzbl 0x17(%rax,%rcx,8), %ebp
movl %ebp, 0x41571a(%rip)    # 0x452ae4
leaq 0x35a70f(%rip), %rax    # 0x397ae0
cmpq $0x0, (%rax,%rdx,8)
jne 0x3d3e2
movl $0x0, 0x3d1c22(%rip)    # 0x40f004
cmpw $0x2400, 0x3d1c25(%rip) # imm = 0x2400
jb 0x3d3f6
movw $0x0, 0x3d1c1a(%rip)    # 0x40f010
movswq 0x3d1c12(%rip), %rax    # 0x40f010
leaq 0x1fc65b(%rip), %rcx    # 0x239a60
testb $-0x40, (%rcx,%rax,4)
je 0x3d420
movswl %ax, %ebx
movl %ebx, %edi
xorl %esi, %esi
callq 0x23d49
addl %eax, %ebx
movw %bx, 0x3d1bf0(%rip)     # 0x40f010
movswq 0x3d1be8(%rip), %rcx    # 0x40f010
leaq 0x3d6421(%rip), %rax    # 0x413850
movzbl (%rcx,%rax), %edx
movl %edx, %eax
shrl $0x4, %eax
movw %ax, 0x4156a9(%rip)     # 0x452ae8
leaq 0x6636a(%rip), %rdi     # 0xa37b0
leaq 0x3c3393(%rip), %rsi    # 0x4007e0
movswl (%rsi,%rcx,2), %esi
cmpl %esi, (%rdi,%rax,4)
je 0x3d462
movzwl %ax, %eax
incl %eax
movw %ax, 0x415686(%rip)     # 0x452ae8
movzwl 0x41567f(%rip), %ecx    # 0x452ae8
movw $0x20, %ax
subw %cx, %ax
movw %ax, 0x415671(%rip)     # 0x452ae8
movswl %si, %esi
sarl %esi
addl 0x31f642(%rip), %esi    # 0x35cac4
negw %cx
shll %cl, %esi
shll $0x18, %ebp
addl %esi, %ebp
addb $-0x13, %al
movl $0x8, %esi
movl %eax, %ecx
shll %cl, %esi
movl %ebp, 0x41564f(%rip)    # 0x452aec
movl %esi, 0x41564d(%rip)    # 0x452af0
movq 0x20(%rsp), %rax
movzwl (%r14,%rax,2), %eax
testw %ax, %ax
js 0x3d874
andl $0xf, %edx
movswl 0x31f600(%rip), %ecx    # 0x35cac0
addl %edx, %ecx
movl $0xb, %r12d
subl %ecx, %r12d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
leaq 0x22d598(%rip), %r10    # 0x26aa70
leaq 0x567e41(%rip), %r9     # 0x5a5320
leaq 0x3a12ea(%rip), %rbx    # 0x3de7d0
movl %r13d, 0x1c(%rsp)
movzwl %ax, %ebp
leaq 0x1fa55b(%rip), %rax    # 0x237a50
movswq (%rax,%rbp,2), %rcx
shlq $0x5, %rcx
leaq 0x17a54b(%rip), %rax    # 0x1b7a50
movswq 0xc(%rcx,%rax), %rax
testq %rax, %rax
js 0x3d631
leaq 0x17a535(%rip), %rdx    # 0x1b7a50
addq %rdx, %rcx
xorl %edx, %edx
testb %r13b, %r13b
setne %sil
testb $0x20, 0xe(%rcx)
jne 0x3d631
leaq (%rax,%rax,4), %rax
leaq 0x205524(%rip), %rcx    # 0x242a60
leaq (%rcx,%rax,8), %rax
movb %sil, %dl
movzwl 0xc(%rax,%rdx,2), %eax
andl $0x1, %eax
je 0x3d631
testl %r15d, %r15d
js 0x3d865
movswq 0x3d1aae(%rip), %r8     # 0x40f010
leaq 0x3d62e7(%rip), %rax    # 0x413850
movzbl (%r8,%rax), %ebx
andl $0xf, %ebx
movl %r15d, %eax
movl (%r9,%rax,4), %edx
movl %edx, %esi
movl %ebx, %ecx
sarl %cl, %esi
movslq %esi, %rcx
leaq 0x31f338(%rip), %rsi    # 0x35c8c0
movzwl (%rsi,%rcx,2), %ecx
addw %r8w, %cx
movw %cx, 0x3d1a79(%rip)     # 0x40f010
movslq (%r10,%rbp,4), %rsi
xorl -0x4(%r9,%rsi,4), %edx
movl %ebx, %ecx
sarl %cl, %edx
testl %edx, %edx
movq %r8, 0x28(%rsp)
je 0x3d80c
cmpl (%r10,%rbp,4), %r15d
jge 0x3d814
leaq (%r9,%rax,4), %r13
movl %r15d, %edi
movl (%r13), %eax
movl %ebx, %ecx
sarl %cl, %eax
cltq
leaq 0x31f2ed(%rip), %rcx    # 0x35c8c0
movswl (%rcx,%rax,2), %r14d
addl %r8d, %r14d
movswl 0x3d1a2e(%rip), %eax    # 0x40f010
cmpl %eax, %r14d
je 0x3d61f
leal -0x1(%r15), %esi
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rcx
leaq 0x56b924(%rip), %r8     # 0x5a8f20
callq 0x3de63
movq 0x28(%rsp), %r8
leaq 0x567d13(%rip), %r9     # 0x5a5320
leaq 0x22d45c(%rip), %r10    # 0x26aa70
movw %r14w, 0x3d19f4(%rip)   # 0x40f010
movl %r15d, %edi
addq $0x4, %r13
incl %r15d
cmpl %r15d, (%r10,%rbp,4)
jg 0x3d5c2
jmp 0x3d817
cmpl $-0x1, %r15d
jne 0x3d63b
movl (%r10,%rbp,4), %r15d
movb 0x31f481(%rip), %al     # 0x35cac2
leal (,%rbp,4), %ecx
movslq (%rcx,%r10), %rsi
leaq 0x23142d(%rip), %rdx    # 0x26ea80
movl (%rcx,%rdx), %edx
testb %al, %al
je 0x3d6ac
cmpl %edx, %esi
jg 0x3d727
movl %esi, %ecx
movzwl 0x3906c5(%rip), %edi    # 0x3cdd30
leaq (%rsi,%rsi), %r8
shlq $0x2, %rsi
subl %ecx, %edx
incl %edx
xorl %r11d, %r11d
leaq (%r8,%r11,2), %rcx
leaq 0x41ba7b(%rip), %r10    # 0x459100
movzwl (%r10,%rcx), %r10d
addl %edi, %r10d
andl $0x7ff, %r10d           # imm = 0x7FF
movl %r12d, %ecx
shrl %cl, %r10d
leaq (%rsi,%r11,4), %rcx
movl %r10d, (%r9,%rcx)
incq %r11
cmpl %r11d, %edx
jne 0x3d67a
jmp 0x3d727
cmpl %edx, %esi
jg 0x3d727
movslq 0x3f7ee5(%rip), %rcx    # 0x43559c
movslq 0x391692(%rip), %rdi    # 0x3ced50
imulq %rcx, %rdi
movslq 0x3da79b(%rip), %rcx    # 0x417e64
shrq $0x10, %rdi
movslq %edi, %rdi
movzwl 0x390658(%rip), %r8d    # 0x3cdd30
leaq (,%rsi,4), %r14
movq %rsi, %r10
subq %rcx, %r10
imulq %rdi, %r10
subl %esi, %edx
incl %edx
xorl %esi, %esi
movq %r10, %r11
shrq $0x17, %r11
addl %r8d, %r11d
andl $0x7ff, %r11d           # imm = 0x7FF
movl %r12d, %ecx
shrl %cl, %r11d
leaq (%r14,%rsi,4), %rcx
leaq 0x567c0e(%rip), %r9     # 0x5a5320
movl %r11d, (%r9,%rcx)
leaq 0x567c03(%rip), %r9     # 0x5a5320
incq %rsi
addq %rdi, %r10
cmpl %esi, %edx
jne 0x3d6f0
leaq 0x22d342(%rip), %r10    # 0x26aa70
movslq (%r10,%rbp,4), %rcx
cmpb $0x2, %al
jne 0x3d7c8
leaq 0x23133f(%rip), %rax    # 0x26ea80
movl (%rax,%rbp,4), %eax
cmpl %eax, %ecx
jg 0x3d865
movl %ecx, %edi
movslq 0x3905df(%rip), %rdx    # 0x3cdd34
movslq 0x3915f4(%rip), %rsi    # 0x3ced50
imulq %rdx, %rsi
shrq $0x10, %rsi
movslq %esi, %rdx
leaq (%rcx,%rcx), %rsi
shlq $0x2, %rcx
subl %edi, %eax
incl %eax
xorl %edi, %edi
leaq 0x41b984(%rip), %r14    # 0x459100
leaq 0x3905cd(%rip), %r13    # 0x3cdd50
leaq (%rsi,%rdi,2), %r8
movzwl (%r14,%r8), %r8d
addl $0x200, %r8d            # imm = 0x200
andl $0x7ff, %r8d            # imm = 0x7FF
movswq (%r13,%r8,2), %r8
imulq %rdx, %r8
shrq $0xe, %r8
leaq (%rcx,%rdi,4), %r11
leaq 0x56b76d(%rip), %rbx    # 0x5a8f20
movl %r8d, (%rbx,%r11)
incq %rdi
cmpl %edi, %eax
jne 0x3d783
movl 0x1c(%rsp), %r13d
jmp 0x3d85e
leaq 0x56b751(%rip), %rax    # 0x5a8f20
leaq (%rax,%rcx,4), %rdi
leaq 0x2312a6(%rip), %rax    # 0x26ea80
movl (%rax,%rbp,4), %esi
subl %ecx, %esi
incl %esi
movslq 0x39054c(%rip), %rax    # 0x3cdd34
movslq 0x391561(%rip), %rdx    # 0x3ced50
imulq %rax, %rdx
shrq $0x10, %rdx
callq 0x4abc9
leaq 0x567b1d(%rip), %r9     # 0x5a5320
leaq 0x22d266(%rip), %r10    # 0x26aa70
jmp 0x3d865
decq %rsi
movl %r15d, %edi
jmp 0x3d827
movl %r15d, %edi
cmpl %r15d, %edi
movl 0x1c(%rsp), %r13d
jge 0x3d850
decl %r15d
movl %r15d, %esi
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rcx
leaq 0x56b6e8(%rip), %r8     # 0x5a8f20
callq 0x3de63
movq 0x28(%rsp), %r8
leaq 0x567ad7(%rip), %r9     # 0x5a5320
leaq 0x22d220(%rip), %r10    # 0x26aa70
movw %r8w, 0x3d17b8(%rip)    # 0x40f010
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
leaq 0x3a0f6b(%rip), %rbx    # 0x3de7d0
movzwl (%rbx,%rbp,2), %eax
testw %ax, %ax
jns 0x3d4eb
jmp 0x3d87a
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %r15d, %r15d
js 0x3d9d5
movswq 0x3d1785(%rip), %rbp    # 0x40f010
leaq 0x3d5fbe(%rip), %rax    # 0x413850
movzbl (%rbp,%rax), %r11d
andl $0xf, %r11d
movl %r15d, %eax
leaq 0x567a7a(%rip), %r8     # 0x5a5320
movl (%r8,%rax,4), %edx
movl %edx, %esi
movl %r11d, %ecx
sarl %cl, %esi
movslq %esi, %rcx
leaq 0x31f005(%rip), %r9     # 0x35c8c0
movzwl (%r9,%rcx,2), %ecx
addw %bp, %cx
movw %cx, 0x3d1746(%rip)     # 0x40f010
leaq 0x39aeef(%rip), %r10    # 0x3d87c0
movq 0x20(%rsp), %rdi
movswq (%r10,%rdi,2), %rcx
leaq 0x23119e(%rip), %r12    # 0x26ea80
movslq (%r12,%rcx,4), %rsi
xorl (%r8,%rsi,4), %edx
movl %r11d, %ecx
sarl %cl, %edx
testl %edx, %edx
je 0x3d909
movswq (%r10,%rdi,2), %rcx
cmpl (%r12,%rcx,4), %r15d
jle 0x3d91f
movl %r15d, %esi
movl %r15d, %edi
jmp 0x3d9ad
leaq 0x56b610(%rip), %r8     # 0x5a8f20
leaq 0x567a09(%rip), %r9     # 0x5a5320
movl %r15d, %edi
jmp 0x3d9bf
movq %rdi, %rdx
leaq 0x5679f7(%rip), %rcx    # 0x5a5320
leaq (%rcx,%rax,4), %r13
movl %r15d, %edi
movl (%r13), %eax
movl %r11d, %ecx
sarl %cl, %eax
cltq
movswl (%r9,%rax,2), %ebx
addl %ebp, %ebx
movswl 0x3d16c7(%rip), %eax    # 0x40f010
cmpl %eax, %ebx
je 0x3d997
leal -0x1(%r15), %esi
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rcx
leaq 0x56b5be(%rip), %r8     # 0x5a8f20
leaq 0x5679b7(%rip), %r9     # 0x5a5320
movq %r10, %r14
movl %r11d, %r12d
callq 0x3de63
movl %r12d, %r11d
leaq 0x231102(%rip), %r12    # 0x26ea80
movq %r14, %r10
leaq 0x31ef38(%rip), %r9     # 0x35c8c0
movq 0x20(%rsp), %rdx
movw %bx, 0x3d167c(%rip)     # 0x40f010
movl %r15d, %edi
movswq (%r10,%rdx,2), %rax
leal 0x1(%r15), %esi
addq $0x4, %r13
cmpl %r15d, (%r12,%rax,4)
movl %esi, %r15d
jg 0x3d930
cmpl %esi, %edi
jg 0x3d9ce
leaq 0x56b568(%rip), %r8     # 0x5a8f20
leaq 0x567961(%rip), %r9     # 0x5a5320
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rcx
callq 0x3de63
movw %bp, 0x3d163b(%rip)     # 0x40f010
movl 0x34(%rsp), %eax
movl %eax, 0x23d0bd(%rip)    # 0x27aa9c
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq