// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: maskwallscan
static void maskwallscan(int x1, int x2, short *uwal, short *dwal, int *swal, int *lwal)
{
	int x, startx, xnice, ynice;
	intptr_t i, fpalookup, p;
	int y1ve[4], y2ve[4], u4, d4, dax, z, tsizx, tsizy;
	char bad;

	tsizx = tilesizx[globalpicnum];
	tsizy = tilesizy[globalpicnum];
	setgotpic(globalpicnum);
	if ((tsizx <= 0) || (tsizy <= 0)) return;
	if ((uwal[x1] > ydimen) && (uwal[x2] > ydimen)) return;
	if ((dwal[x1] < 0) && (dwal[x2] < 0)) return;

	if (waloff[globalpicnum] == 0) loadtile(globalpicnum);

	startx = x1;

	xnice = (pow2long[picsiz[globalpicnum]&15] == tsizx);
	if (xnice) tsizx = (tsizx-1);
	ynice = (pow2long[picsiz[globalpicnum]>>4] == tsizy);
	if (ynice) tsizy = (picsiz[globalpicnum]>>4);

	fpalookup = (intptr_t)palookup[globalpal];

	setupmvlineasm(globalshiftval);

#ifndef USING_A_C

	x = startx;
	while ((startumost[x+windowx1] > startdmost[x+windowx1]) && (x <= x2)) x++;

	p = x+frameoffset;

	for(;(x<=x2)&&(p&3);x++,p++)
	{
		y1ve[0] = max(uwal[x],startumost[x+windowx1]-windowy1);
		y2ve[0] = min(dwal[x],startdmost[x+windowx1]-windowy1);
		if (y2ve[0] <= y1ve[0]) continue;

		palookupoffse[0] = fpalookup+(getpalookup((int)mulscale16(swal[x],globvis),globalshade)<<8);

		bufplce[0] = lwal[x] + globalxpanning;
		if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; }
		if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy;

		vince[0] = swal[x]*globalyscale;
		vplce[0] = globalzd + vince[0]*(y1ve[0]-globalhoriz+1);

		mvlineasm1(vince[0],(void *)palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],(void *)(bufplce[0]+waloff[globalpicnum]),(void *)(p+ylookup[y1ve[0]]));
	}
	for(;x<=x2-3;x+=4,p+=4)
	{
		bad = 0;
		for(z=3,dax=x+3;z>=0;z--,dax--)
		{
			y1ve[z] = max(uwal[dax],startumost[dax+windowx1]-windowy1);
			y2ve[z] = min(dwal[dax],startdmost[dax+windowx1]-windowy1)-1;
			if (y2ve[z] < y1ve[z]) { bad += pow2char[z]; continue; }

			i = lwal[dax] + globalxpanning;
			if (i >= tsizx) { if (xnice == 0) i %= tsizx; else i &= tsizx; }
			if (ynice == 0) i *= tsizy; else i <<= tsizy;
			bufplce[z] = waloff[globalpicnum]+i;

			vince[z] = swal[dax]*globalyscale;
			vplce[z] = globalzd + vince[z]*(y1ve[z]-globalhoriz+1);
		}
		if (bad == 15) continue;

		palookupoffse[0] = fpalookup+(getpalookup((int)mulscale16(swal[x],globvis),globalshade)<<8);
		palookupoffse[3] = fpalookup+(getpalookup((int)mulscale16(swal[x+3],globvis),globalshade)<<8);

		if ((palookupoffse[0] == palookupoffse[3]) && ((bad&0x9) == 0))
		{
			palookupoffse[1] = palookupoffse[0];
			palookupoffse[2] = palookupoffse[0];
		}
		else
		{
			palookupoffse[1] = fpalookup+(getpalookup((int)mulscale16(swal[x+1],globvis),globalshade)<<8);
			palookupoffse[2] = fpalookup+(getpalookup((int)mulscale16(swal[x+2],globvis),globalshade)<<8);
		}

		u4 = max(max(y1ve[0],y1ve[1]),max(y1ve[2],y1ve[3]));
		d4 = min(min(y2ve[0],y2ve[1]),min(y2ve[2],y2ve[3]));

		if ((bad > 0) || (u4 >= d4))
		{
			if (!(bad&1)) mvlineasm1(vince[0],(void *)palookupoffse[0],y2ve[0]-y1ve[0],vplce[0],(void *)bufplce[0],(void *)(ylookup[y1ve[0]]+p+0));
			if (!(bad&2)) mvlineasm1(vince[1],(void *)palookupoffse[1],y2ve[1]-y1ve[1],vplce[1],(void *)bufplce[1],(void *)(ylookup[y1ve[1]]+p+1));
			if (!(bad&4)) mvlineasm1(vince[2],(void *)palookupoffse[2],y2ve[2]-y1ve[2],vplce[2],(void *)bufplce[2],(void *)(ylookup[y1ve[2]]+p+2));
			if (!(bad&8)) mvlineasm1(vince[3],(void *)palookupoffse[3],y2ve[3]-y1ve[3],vplce[3],(void *)bufplce[3],(void *)(ylookup[y1ve[3]]+p+3));
			continue;
		}

		if (u4 > y1ve[0]) vplce[0] = mvlineasm1(vince[0],(void *)palookupoffse[0],u4-y1ve[0]-1,vplce[0],(void *)bufplce[0],(void *)(ylookup[y1ve[0]]+p+0));
		if (u4 > y1ve[1]) vplce[1] = mvlineasm1(vince[1],(void *)palookupoffse[1],u4-y1ve[1]-1,vplce[1],(void *)bufplce[1],(void *)(ylookup[y1ve[1]]+p+1));
		if (u4 > y1ve[2]) vplce[2] = mvlineasm1(vince[2],(void *)palookupoffse[2],u4-y1ve[2]-1,vplce[2],(void *)bufplce[2],(void *)(ylookup[y1ve[2]]+p+2));
		if (u4 > y1ve[3]) vplce[3] = mvlineasm1(vince[3],(void *)palookupoffse[3],u4-y1ve[3]-1,vplce[3],(void *)bufplce[3],(void *)(ylookup[y1ve[3]]+p+3));

		if (d4 >= u4) mvlineasm4(d4-u4+1,(void *)(ylookup[u4]+p));

		i = p+ylookup[d4+1];
		if (y2ve[0] > d4) mvlineasm1(vince[0],(void *)palookupoffse[0],y2ve[0]-d4-1,vplce[0],(void *)bufplce[0],(void *)(i+0));
		if (y2ve[1] > d4) mvlineasm1(vince[1],(void *)palookupoffse[1],y2ve[1]-d4-1,vplce[1],(void *)bufplce[1],(void *)(i+1));
		if (y2ve[2] > d4) mvlineasm1(vince[2],(void *)palookupoffse[2],y2ve[2]-d4-1,vplce[2],(void *)bufplce[2],(void *)(i+2));
		if (y2ve[3] > d4) mvlineasm1(vince[3],(void *)palookupoffse[3],y2ve[3]-d4-1,vplce[3],(void *)bufplce[3],(void *)(i+3));
	}
	for(;x<=x2;x++,p++)
	{
		y1ve[0] = max(uwal[x],startumost[x+windowx1]-windowy1);
		y2ve[0] = min(dwal[x],startdmost[x+windowx1]-windowy1);
		if (y2ve[0] <= y1ve[0]) continue;

		palookupoffse[0] = fpalookup+(getpalookup((int)mulscale16(swal[x],globvis),globalshade)<<8);

		bufplce[0] = lwal[x] + globalxpanning;
		if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; }
		if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy;

		vince[0] = swal[x]*globalyscale;
		vplce[0] = globalzd + vince[0]*(y1ve[0]-globalhoriz+1);

		mvlineasm1(vince[0],(void *)palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],(void *)(bufplce[0]+waloff[globalpicnum]),(void *)(p+ylookup[y1ve[0]]));
	}

#else	// USING_A_C
	(void)i; (void)u4; (void)d4; (void)dax; (void)z; (void)bad;

	p = startx+frameoffset;
	for(x=startx;x<=x2;x++,p++)
	{
		y1ve[0] = max(uwal[x],startumost[x+windowx1]-windowy1);
		y2ve[0] = min(dwal[x],startdmost[x+windowx1]-windowy1);
		if (y2ve[0] <= y1ve[0]) continue;

		palookupoffse[0] = fpalookup+(getpalookup((int)mulscale16(swal[x],globvis),globalshade)<<8);

		bufplce[0] = lwal[x] + globalxpanning;
		if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; }
		if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy;

		vince[0] = swal[x]*globalyscale;
		vplce[0] = globalzd + vince[0]*(y1ve[0]-globalhoriz+1);

		mvlineasm1(vince[0],(void *)palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],(void *)(bufplce[0]+waloff[globalpicnum]),(void *)(p+ylookup[y1ve[0]]));
	}

#endif

	faketimerhandler();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebx
movl %edi, %ebp
movswl 0x3cd925(%rip), %eax    # 0x409010
movslq %eax, %rdi
leaq 0x3cd92b(%rip), %rax    # 0x409020
movswl (%rax,%rdi,2), %eax
movl %eax, 0x8(%rsp)
testl %eax, %eax
setle %r15b
leaq 0x3bf0d6(%rip), %rax    # 0x3fa7e0
movzwl (%rax,%rdi,2), %r14d
callq 0x2cc16
testw %r14w, %r14w
setle %al
orb %r15b, %al
je 0x3b72f
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %ebp, %r15
leaq 0x561de7(%rip), %rdx    # 0x59d520
movswl (%rdx,%r15,2), %ecx
movl 0x239350(%rip), %eax    # 0x274a94
movslq %ebx, %r13
cmpl %ecx, %eax
jge 0x3b754
movswl (%rdx,%r13,2), %ecx
cmpl %ecx, %eax
jl 0x3b720
leaq 0x4667b5(%rip), %rax    # 0x4a1f10
cmpw $0x0, (%rax,%r15,2)
jns 0x3b76b
cmpw $0x0, (%rax,%r13,2)
js 0x3b720
movswl %r14w, %eax
movl %eax, 0xc(%rsp)
movswq 0x3cd895(%rip), %rdi    # 0x409010
leaq 0x356b5e(%rip), %rax    # 0x3922e0
cmpq $0x0, (%rax,%rdi,8)
jne 0x3b796
callq 0x2cc4a
movswq 0x3cd87a(%rip), %rdi    # 0x409010
leaq 0x3d20b3(%rip), %rax    # 0x40d850
movzbl (%rdi,%rax), %ebx
movl %ebx, %eax
andl $0xf, %eax
leaq 0x62003(%rip), %rcx     # 0x9d7b0
movl (%rcx,%rax,4), %esi
xorl %eax, %eax
movl 0x8(%rsp), %edx
movl %esi, 0x10(%rsp)
cmpl %edx, %esi
sete %al
movl %edx, %r12d
subl %eax, %r12d
shrl $0x4, %ebx
movl (%rcx,%rbx,4), %eax
movl %eax, 0x14(%rsp)
movslq 0x3cd82e(%rip), %rax    # 0x409004
leaq 0x356303(%rip), %rcx    # 0x391ae0
movq (%rcx,%rax,8), %rax
movq %rax, 0x30(%rsp)
movswl 0x4112fb(%rip), %edi    # 0x44cae8
callq 0x64399
movq 0x394f97(%rip), %rax    # 0x3d0790
movq %rax, 0x28(%rsp)
movl 0xc(%rsp), %eax
movq %rax, 0x20(%rsp)
leaq (%r15,%r15), %rbp
leaq (,%r15,4), %rax
movq %rax, 0x18(%rsp)
leaq 0x38d751(%rip), %r11    # 0x3c8f70
xorl %r14d, %r14d
leaq 0x561cf7(%rip), %rdi    # 0x59d520
leaq 0x4666e0(%rip), %r10    # 0x4a1f10
cmpq %r13, %r15
jg 0x3b9b1
leaq (%r14,%rbp), %rax
movswl (%rdi,%rax), %ecx
movslq 0x38f528(%rip), %rdx    # 0x3cad70
addq %r15, %rdx
movswl (%r11,%rdx,2), %r9d
movl 0x39132a(%rip), %esi    # 0x3ccb80
subl %esi, %r9d
cmpl %ecx, %r9d
cmovlel %ecx, %r9d
movswl (%r10,%rax), %eax
leaq 0x38f514(%rip), %rcx    # 0x3cad80
movswl (%rcx,%rdx,2), %r8d
subl %esi, %r8d
cmpl %eax, %r8d
cmovgel %eax, %r8d
cmpl %r9d, %r8d
jle 0x3b9a5
movq 0x18(%rsp), %rax
leaq (%rax,%r14,2), %rax
leaq 0x46847c(%rip), %rcx    # 0x4a3d10
movslq (%rcx,%rax), %rdi
movslq 0x3d1f91(%rip), %rcx    # 0x40d830
imulq %rdi, %rcx
shrq $0x10, %rcx
sarl $0x8, %ecx
addl 0x3d1f7c(%rip), %ecx    # 0x40d82c
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
movswl 0x3d1f67(%rip), %edx    # 0x40d828
decl %edx
cmpl %edx, %ecx
cmovll %ecx, %edx
shll $0x8, %edx
movslq %edx, %rsi
addq 0x30(%rsp), %rsi
movq %rsi, 0x4111c6(%rip)    # 0x44caa0
leaq 0x46c02f(%rip), %rcx    # 0x4a7910
movslq (%rcx,%rax), %rcx
movslq 0x4111f4(%rip), %rax    # 0x44cae0
addq %rcx, %rax
cmpl %r12d, %eax
jl 0x3b90b
movl 0x10(%rsp), %ecx
cmpl 0x8(%rsp), %ecx
jne 0x3b903
andl %r12d, %eax
jmp 0x3b90b
xorl %edx, %edx
divq %r12
movq %rdx, %rax
movq %rax, %rdx
movl %ebx, %ecx
shlq %cl, %rdx
imulq 0x20(%rsp), %rax
movl 0x14(%rsp), %ecx
cmpl 0xc(%rsp), %ecx
cmoveq %rdx, %rax
movq %rax, 0x411194(%rip)    # 0x44cac0
imull 0x4111bd(%rip), %edi    # 0x44caf0
movl %edi, 0x411157(%rip)    # 0x44ca90
movl %r9d, %ecx
subl 0x23915a(%rip), %ecx    # 0x274a9c
incl %ecx
imull %edi, %ecx
addl 0x41119f(%rip), %ecx    # 0x44caec
movl %ecx, 0x41112d(%rip)    # 0x44ca80
movswq 0x3cd6b5(%rip), %rdx    # 0x409010
leaq 0x35697e(%rip), %r10    # 0x3922e0
addq (%r10,%rdx,8), %rax
movslq %r9d, %rdx
notl %r9d
addl %r9d, %r8d
leaq 0x3d432a(%rip), %r9     # 0x40fca0
movslq (%r9,%rdx,4), %r9
movq 0x28(%rsp), %rdx
addq %r15, %rdx
addq %rdx, %r9
movl %r8d, %edx
movq %rax, %r8
callq 0x643a0
leaq 0x561b89(%rip), %rdi    # 0x59d520
leaq 0x466572(%rip), %r10    # 0x4a1f10
leaq 0x38d5cb(%rip), %r11    # 0x3c8f70
incq %r15
addq $0x2, %r14
jmp 0x3b830
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9fd2