// File: /workspace/github_c_makefile_star2_O3/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, %r12d
movswl 0x3d07fd(%rip), %edi    # 0x410010
movslq %edi, %rax
leaq 0x3d0803(%rip), %rcx    # 0x410020
movswl (%rcx,%rax,2), %r15d
leaq 0x3c1fb7(%rip), %rcx    # 0x4017e0
movswl (%rcx,%rax,2), %ecx
movl %ecx, (%rsp)
leaq 0x3eef09(%rip), %rcx    # 0x42e740
cmpb $-0x39, (%rax,%rcx)
ja 0x3f841
movb $-0x39, (%rax,%rcx)
movl %edi, %ecx
andl $0x7, %ecx
leaq 0x64f53(%rip), %rdx     # 0xa47a0
movb (%rcx,%rdx), %cl
movl %edi, %edx
sarl $0x3, %edx
movslq %edx, %rdx
leaq 0x3eea51(%rip), %rsi    # 0x42e2b0
orb %cl, (%rdx,%rsi)
testw %r15w, %r15w
setle %cl
cmpw $0x0, (%rsp)
setle %dl
orb %cl, %dl
je 0x3f884
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %r12d, %r13
leaq 0x564c92(%rip), %rsi    # 0x5a4520
movswl (%rsi,%r13,2), %edx
movl 0x23c1fb(%rip), %ecx    # 0x27ba94
cmpl %edx, %ecx
jge 0x3f8a8
movslq %ebx, %rdx
movswl (%rsi,%rdx,2), %edx
cmpl %edx, %ecx
jl 0x3f875
leaq 0x469661(%rip), %rdx    # 0x4a8f10
cmpw $0x0, (%rdx,%r13,2)
jns 0x3f8c1
movslq %ebx, %rcx
cmpw $0x0, (%rdx,%rcx,2)
js 0x3f875
leaq 0x359a18(%rip), %rcx    # 0x3992e0
cmpq $0x0, (%rcx,%rax,8)
jne 0x3f8dc
callq 0x2fc7e
movswq 0x3d0734(%rip), %rax    # 0x410010
leaq 0x3d4f6d(%rip), %rcx    # 0x414850
movzbl (%rax,%rcx), %r14d
movl %r14d, %eax
andl $0xf, %eax
leaq 0x64ebb(%rip), %rcx     # 0xa47b0
movl (%rcx,%rax,4), %eax
xorl %ebp, %ebp
movl %r15d, 0x4(%rsp)
movl %eax, 0x8(%rsp)
cmpl %r15d, %eax
sete %r15b
shrl $0x4, %r14d
movl (%rcx,%r14,4), %eax
movl %eax, 0xc(%rsp)
movslq 0x3d06e7(%rip), %rax    # 0x410004
leaq 0x3591bc(%rip), %rcx    # 0x398ae0
movq (%rcx,%rax,8), %rax
movq %rax, 0x30(%rsp)
movswl 0x4141b4(%rip), %edi    # 0x453ae8
callq 0x6fc56
cmpl %ebx, %r12d
leaq 0x564bdd(%rip), %r10    # 0x5a4520
leaq 0x4695c6(%rip), %r11    # 0x4a8f10
jg 0x3fb21
movb %r15b, %bpl
movl 0x4(%rsp), %r15d
subl %ebp, %r15d
movq 0x397e2e(%rip), %rax    # 0x3d7790
movq %rax, 0x28(%rsp)
movl %r15d, %eax
movq %rax, 0x10(%rsp)
movl (%rsp), %eax
movq %rax, 0x20(%rsp)
movl 0x3923f3(%rip), %eax    # 0x3d1d70
movl 0x3941fd(%rip), %ecx    # 0x3d3b80
leaq (,%r13,2), %rbp
leaq (,%r13,4), %rdx
movq %rdx, 0x18(%rsp)
subl %r12d, %ebx
incl %ebx
xorl %r12d, %r12d
leaq (%r12,%rbp), %rdx
movswl (%r10,%rdx), %esi
movslq %eax, %rdi
addq %r13, %rdi
leaq 0x3905ba(%rip), %r8     # 0x3cff70
movswl (%r8,%rdi,2), %r9d
subl %ecx, %r9d
cmpl %esi, %r9d
cmovlel %esi, %r9d
movswl (%r11,%rdx), %edx
leaq 0x3923af(%rip), %rsi    # 0x3d1d80
movswl (%rsi,%rdi,2), %r8d
subl %ecx, %r8d
cmpl %edx, %r8d
cmovgel %edx, %r8d
cmpl %r9d, %r8d
jle 0x3fb12
movq 0x18(%rsp), %rax
leaq (%rax,%r12,2), %rax
leaq 0x46b317(%rip), %rcx    # 0x4aad10
movslq (%rcx,%rax), %rdi
movslq 0x3d4e2c(%rip), %rcx    # 0x414830
imulq %rdi, %rcx
shrq $0x10, %rcx
sarl $0x8, %ecx
addl 0x3d4e17(%rip), %ecx    # 0x41482c
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
movswl 0x3d4e02(%rip), %edx    # 0x414828
decl %edx
cmpl %edx, %ecx
cmovll %ecx, %edx
shll $0x8, %edx
movslq %edx, %rsi
addq 0x30(%rsp), %rsi
movq %rsi, 0x414061(%rip)    # 0x453aa0
leaq 0x46eeca(%rip), %rcx    # 0x4ae910
movslq (%rcx,%rax), %rcx
movslq 0x41408f(%rip), %rax    # 0x453ae0
addq %rcx, %rax
cmpl %r15d, %eax
jl 0x3fa73
movl 0x8(%rsp), %ecx
cmpl 0x4(%rsp), %ecx
jne 0x3fa69
andl 0x10(%rsp), %eax
jmp 0x3fa73
xorl %edx, %edx
divq 0x10(%rsp)
movq %rdx, %rax
movq %rax, %rdx
movl %r14d, %ecx
shlq %cl, %rdx
imulq 0x20(%rsp), %rax
movl 0xc(%rsp), %ecx
cmpl (%rsp), %ecx
cmoveq %rdx, %rax
movq %rax, 0x41402c(%rip)    # 0x453ac0
imull 0x414055(%rip), %edi    # 0x453af0
movl %edi, 0x413fef(%rip)    # 0x453a90
movl %r9d, %ecx
subl 0x23bff2(%rip), %ecx    # 0x27ba9c
incl %ecx
imull %edi, %ecx
addl 0x414037(%rip), %ecx    # 0x453aec
movl %ecx, 0x413fc5(%rip)    # 0x453a80
movswq 0x3d054d(%rip), %rdx    # 0x410010
leaq 0x359816(%rip), %r10    # 0x3992e0
addq (%r10,%rdx,8), %rax
movslq %r9d, %rdx
notl %r9d
addl %r9d, %r8d
leaq 0x3d71c2(%rip), %r9     # 0x416ca0
movslq (%r9,%rdx,4), %r9
movq 0x28(%rsp), %rdx
addq %r13, %rdx
addq %rdx, %r9
movl %r8d, %edx
movq %rax, %r8
callq 0x6fc5d
movl 0x392272(%rip), %eax    # 0x3d1d70
movl 0x39407c(%rip), %ecx    # 0x3d3b80
leaq 0x564a15(%rip), %r10    # 0x5a4520
leaq 0x4693fe(%rip), %r11    # 0x4a8f10
incq %r13
addq $0x2, %r12
decl %ebx
jne 0x3f9a0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xacd7