// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movl %esi, %ebx
movl %edi, %r12d
movswl 0x3d0c60(%rip), %edi    # 0x40f010
movslq %edi, %rax
leaq 0x3d0c66(%rip), %rcx    # 0x40f020
movswl (%rcx,%rax,2), %r15d
leaq 0x3c241a(%rip), %rcx    # 0x4007e0
movswl (%rcx,%rax,2), %ecx
movl %ecx, 0xc(%rsp)
leaq 0x3ef36b(%rip), %rcx    # 0x42d740
cmpb $-0x39, (%rax,%rcx)
ja 0x3e3df
movb $-0x39, (%rax,%rcx)
movl %edi, %ecx
andl $0x7, %ecx
leaq 0x653b5(%rip), %rdx     # 0xa37a0
movb (%rcx,%rdx), %cl
movl %edi, %edx
sarl $0x3, %edx
movslq %edx, %rdx
leaq 0x3eeeb3(%rip), %rsi    # 0x42d2b0
orb %cl, (%rdx,%rsi)
testw %r15w, %r15w
setle %cl
cmpw $0x0, 0xc(%rsp)
setle %dl
orb %cl, %dl
je 0x3e423
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %r12d, %r13
leaq 0x5650f3(%rip), %rsi    # 0x5a3520
movswl (%rsi,%r13,2), %edx
movl 0x23c65c(%rip), %ecx    # 0x27aa94
cmpl %edx, %ecx
jge 0x3e447
movslq %ebx, %rdx
movswl (%rsi,%rdx,2), %edx
cmpl %edx, %ecx
jl 0x3e414
leaq 0x469ac2(%rip), %rdx    # 0x4a7f10
cmpw $0x0, (%rdx,%r13,2)
jns 0x3e460
movslq %ebx, %rcx
cmpw $0x0, (%rdx,%rcx,2)
js 0x3e414
leaq 0x359e79(%rip), %rcx    # 0x3982e0
cmpq $0x0, (%rcx,%rax,8)
jne 0x3e473
callq 0x2f106
movswq 0x3d0b95(%rip), %rax    # 0x40f010
leaq 0x3d53ce(%rip), %rcx    # 0x413850
movzbl (%rax,%rcx), %r14d
movl %r14d, %eax
andl $0xf, %eax
leaq 0x6531c(%rip), %rcx     # 0xa37b0
movl (%rcx,%rax,4), %eax
xorl %ebp, %ebp
movl %r15d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
cmpl %r15d, %eax
sete %r15b
shrl $0x4, %r14d
movl (%rcx,%r14,4), %eax
movl %eax, 0x14(%rsp)
movslq 0x3d0b48(%rip), %rax    # 0x40f004
leaq 0x35961d(%rip), %rcx    # 0x397ae0
movq (%rcx,%rax,8), %rax
movq %rax, 0x40(%rsp)
movswl 0x414615(%rip), %edi    # 0x452ae8
callq 0x6dece
cmpl %ebx, %r12d
leaq 0x56503e(%rip), %rdi    # 0x5a3520
leaq 0x469a27(%rip), %r8     # 0x4a7f10
jg 0x3e6d3
movb %r15b, %bpl
movl 0x10(%rsp), %eax
subl %ebp, %eax
movl 0xc(%rsp), %edx
cmpl %edx, 0x14(%rsp)
movq 0x398289(%rip), %rcx    # 0x3d6790
movq %rcx, 0x38(%rsp)
movzbl %r14b, %ecx
cmovnel %edx, %ecx
movq %rcx, 0x28(%rsp)
movl %eax, 0x1c(%rsp)
movl %eax, %eax
movq %rax, 0x20(%rsp)
leaq (,%r13,2), %r14
leaq (,%r13,4), %rax
movq %rax, 0x30(%rsp)
subl %r12d, %ebx
incl %ebx
leaq 0x390a2c(%rip), %r12    # 0x3cef70
leaq 0x392835(%rip), %rbp    # 0x3d0d80
xorl %r15d, %r15d
leaq (%r14,%r15), %rax
movswl (%rdi,%rax), %ecx
movslq 0x392813(%rip), %rdx    # 0x3d0d70
addq %r13, %rdx
movswl (%r12,%rdx,2), %r9d
movl 0x394615(%rip), %esi    # 0x3d2b80
subl %esi, %r9d
cmpl %ecx, %r9d
cmovlel %ecx, %r9d
movswl (%r8,%rax), %eax
movswl (%rbp,%rdx,2), %r10d
subl %esi, %r10d
cmpl %eax, %r10d
cmovgel %eax, %r10d
cmpl %r9d, %r10d
jle 0x3e6c4
movq 0x30(%rsp), %rax
leaq (%rax,%r15,2), %rax
leaq 0x46b76d(%rip), %rcx    # 0x4a9d10
movslq (%rcx,%rax), %rdi
movslq 0x3d5282(%rip), %rcx    # 0x413830
imulq %rdi, %rcx
shrq $0x10, %rcx
sarl $0x8, %ecx
addl 0x3d526d(%rip), %ecx    # 0x41382c
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
movswl 0x3d5258(%rip), %edx    # 0x413828
decl %edx
cmpl %edx, %ecx
cmovll %ecx, %edx
shll $0x8, %edx
movslq %edx, %rsi
addq 0x40(%rsp), %rsi
movq %rsi, 0x4144b7(%rip)    # 0x452aa0
leaq 0x46f320(%rip), %rcx    # 0x4ad910
movslq (%rcx,%rax), %rcx
movslq 0x4144e5(%rip), %rax    # 0x452ae0
addq %rcx, %rax
movq %rax, 0x4144bb(%rip)    # 0x452ac0
cmpl 0x1c(%rsp), %eax
jl 0x3e62c
movl 0x18(%rsp), %ecx
cmpl 0x10(%rsp), %ecx
jne 0x3e61b
andl 0x20(%rsp), %eax
jmp 0x3e625
xorl %edx, %edx
divq 0x20(%rsp)
movq %rdx, %rax
movq %rax, 0x414494(%rip)    # 0x452ac0
movq 0x41448d(%rip), %r8     # 0x452ac0
movq %r8, %rax
movq 0x28(%rsp), %rcx
shlq %cl, %rax
imulq %rcx, %r8
movl 0xc(%rsp), %ecx
cmpl %ecx, 0x14(%rsp)
cmoveq %rax, %r8
movq %r8, 0x41446b(%rip)     # 0x452ac0
imull 0x414494(%rip), %edi    # 0x452af0
movl %edi, 0x41442e(%rip)    # 0x452a90
movl %r9d, %ecx
subl 0x23c431(%rip), %ecx    # 0x27aa9c
incl %ecx
imull %edi, %ecx
addl 0x414476(%rip), %ecx    # 0x452aec
movl %ecx, 0x414404(%rip)    # 0x452a80
movswq 0x3d098c(%rip), %rax    # 0x40f010
leaq 0x359c55(%rip), %rdx    # 0x3982e0
addq (%rdx,%rax,8), %r8
movslq %r9d, %rax
notl %r9d
addl %r9d, %r10d
leaq 0x3d7601(%rip), %rdx    # 0x415ca0
movslq (%rdx,%rax,4), %r9
movq 0x38(%rsp), %rax
addq %r13, %rax
addq %rax, %r9
movl %r10d, %edx
callq 0x6ded5
leaq 0x564e63(%rip), %rdi    # 0x5a3520
leaq 0x46984c(%rip), %r8     # 0x4a7f10
incq %r13
addq $0x2, %r15
decl %ebx
jne 0x3e54e
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xab51