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

	if (x2 >= xdim) x2 = xdim-1;

	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);

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

	fpalookup = (intptr_t)palookup[globalpal];

	setupvlineasm(globalshiftval);

#ifndef USING_A_C

	x = x1;
	while ((umost[x] > dmost[x]) && (x <= x2)) x++;

	for(;(x<=x2)&&((x+frameoffset)&3);x++)
	{
		y1ve[0] = max(uwal[x],umost[x]);
		y2ve[0] = min(dwal[x],dmost[x]);
		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);

		vlineasm1(vince[0],(void *)palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],(void *)(bufplce[0]+waloff[globalpicnum]),(void *)(x+frameoffset+ylookup[y1ve[0]]));
	}
	for(;x<=x2-3;x+=4)
	{
		bad = 0;
		for(z=3;z>=0;z--)
		{
			y1ve[z] = max(uwal[x+z],umost[x+z]);
			y2ve[z] = min(dwal[x+z],dmost[x+z])-1;
			if (y2ve[z] < y1ve[z]) { bad += pow2char[z]; continue; }

			i = lwal[x+z] + 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[x+z]*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)) prevlineasm1(vince[0],(void *)palookupoffse[0],y2ve[0]-y1ve[0],vplce[0],(void *)bufplce[0],(void *)(ylookup[y1ve[0]]+x+frameoffset+0));
			if (!(bad&2)) prevlineasm1(vince[1],(void *)palookupoffse[1],y2ve[1]-y1ve[1],vplce[1],(void *)bufplce[1],(void *)(ylookup[y1ve[1]]+x+frameoffset+1));
			if (!(bad&4)) prevlineasm1(vince[2],(void *)palookupoffse[2],y2ve[2]-y1ve[2],vplce[2],(void *)bufplce[2],(void *)(ylookup[y1ve[2]]+x+frameoffset+2));
			if (!(bad&8)) prevlineasm1(vince[3],(void *)palookupoffse[3],y2ve[3]-y1ve[3],vplce[3],(void *)bufplce[3],(void *)(ylookup[y1ve[3]]+x+frameoffset+3));
			continue;
		}

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

		if (d4 >= u4) vlineasm4(d4-u4+1,(void *)(ylookup[u4]+x+frameoffset));

		i = x+frameoffset+ylookup[d4+1];
		if (y2ve[0] > d4) prevlineasm1(vince[0],(void *)palookupoffse[0],y2ve[0]-d4-1,vplce[0],(void *)bufplce[0],(void *)(i+0));
		if (y2ve[1] > d4) prevlineasm1(vince[1],(void *)palookupoffse[1],y2ve[1]-d4-1,vplce[1],(void *)bufplce[1],(void *)(i+1));
		if (y2ve[2] > d4) prevlineasm1(vince[2],(void *)palookupoffse[2],y2ve[2]-d4-1,vplce[2],(void *)bufplce[2],(void *)(i+2));
		if (y2ve[3] > d4) prevlineasm1(vince[3],(void *)palookupoffse[3],y2ve[3]-d4-1,vplce[3],(void *)bufplce[3],(void *)(i+3));
	}
	for(;x<=x2;x++)
	{
		y1ve[0] = max(uwal[x],umost[x]);
		y2ve[0] = min(dwal[x],dmost[x]);
		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);

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

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

	for(x=x1;x<=x2;x++)
	{
		y1ve[0] = max(uwal[x],umost[x]);
		y2ve[0] = min(dwal[x],dmost[x]);
		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);

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

#endif

	faketimerhandler();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rbp
movq %rcx, %r9
movl %edi, %ebx
movl 0x3c916d(%rip), %eax    # 0x406fec
leal -0x1(%rax), %r13d
cmpl %esi, %eax
cmovgl %esi, %r13d
movswl 0x3d1180(%rip), %edi    # 0x40f010
movslq %edi, %rax
leaq 0x3d1186(%rip), %rcx    # 0x40f020
movswl (%rcx,%rax,2), %r12d
leaq 0x3c293a(%rip), %rcx    # 0x4007e0
movswl (%rcx,%rax,2), %ecx
movl %ecx, 0xc(%rsp)
leaq 0x3ef88b(%rip), %rcx    # 0x42d740
cmpb $-0x39, (%rax,%rcx)
ja 0x3debf
movb $-0x39, (%rax,%rcx)
movl %edi, %ecx
andl $0x7, %ecx
leaq 0x658d5(%rip), %rsi     # 0xa37a0
movb (%rcx,%rsi), %cl
movl %edi, %esi
sarl $0x3, %esi
movslq %esi, %r10
leaq 0x3ef3d3(%rip), %rsi    # 0x42d2b0
orb %cl, (%r10,%rsi)
testw %r12w, %r12w
setle %cl
cmpw $0x0, 0xc(%rsp)
setle %sil
orb %cl, %sil
je 0x3df06
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %ebx, %rcx
movq %rcx, 0x28(%rsp)
movswl (%rdx,%rcx,2), %esi
movl 0x23cb7c(%rip), %ecx    # 0x27aa94
cmpl %esi, %ecx
jge 0x3df27
movslq %r13d, %rsi
movswl (%rdx,%rsi,2), %esi
cmpl %esi, %ecx
jl 0x3def7
movq 0x28(%rsp), %rcx
cmpw $0x0, (%r9,%rcx,2)
jns 0x3df3f
movslq %r13d, %rcx
cmpw $0x0, (%r9,%rcx,2)
js 0x3def7
movq %rdx, 0x40(%rsp)
movq %r9, 0x18(%rsp)
movq %r8, 0x20(%rsp)
leaq 0x35a38b(%rip), %rcx    # 0x3982e0
cmpq $0x0, (%rcx,%rax,8)
jne 0x3df61
callq 0x2f106
movswq 0x3d10a7(%rip), %rax    # 0x40f010
leaq 0x3d58e0(%rip), %rcx    # 0x413850
movzbl (%rax,%rcx), %r14d
movl %r14d, %eax
andl $0xf, %eax
leaq 0x6582e(%rip), %rcx     # 0xa37b0
movl (%rcx,%rax,4), %eax
xorl %r15d, %r15d
movl %r12d, 0x10(%rsp)
movl %eax, 0x30(%rsp)
cmpl %r12d, %eax
sete %r12b
shrl $0x4, %r14d
movl (%rcx,%r14,4), %eax
movl %eax, 0x14(%rsp)
movslq 0x3d1059(%rip), %rax    # 0x40f004
leaq 0x359b2e(%rip), %rcx    # 0x397ae0
movq (%rcx,%rax,8), %rax
movq %rax, 0x50(%rsp)
movswl 0x414b26(%rip), %edi    # 0x452ae8
callq 0x6de86
movq %r13, %rsi
subl %ebx, %esi
jl 0x3e1af
movb %r12b, %r15b
movl 0x10(%rsp), %ecx
subl %r15d, %ecx
movl 0xc(%rsp), %eax
cmpl %eax, 0x14(%rsp)
movzbl %r14b, %edx
cmovnel %eax, %edx
movq %rdx, 0x48(%rsp)
movl %ecx, 0x34(%rsp)
movl %ecx, %eax
movq %rax, 0x38(%rsp)
movq 0x28(%rsp), %rax
leaq (%rax,%rax), %r13
movq 0x40(%rsp), %rcx
leaq (%rcx,%rax,2), %r15
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,2), %r12
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,4), %rbx
leaq (,%rax,4), %rax
addq %rbp, %rax
movq %rax, 0x20(%rsp)
incl %esi
leaq 0x394b58(%rip), %rbp    # 0x3d2b90
leaq 0x396951(%rip), %r8     # 0x3d4990
xorl %r14d, %r14d
movq %rsi, 0x18(%rsp)
movzwl (%r15,%r14,2), %eax
leaq (,%r14,2), %rdx
addq %r13, %rdx
movzwl (%rbp,%rdx), %ecx
cmpw %cx, %ax
cmovgl %eax, %ecx
movzwl (%r12,%r14,2), %eax
movzwl (%r8,%rdx), %edi
cmpw %di, %ax
cmovll %eax, %edi
cmpw %cx, %di
jle 0x3e1a3
movslq (%rbx,%r14,4), %rax
movslq 0x3d57aa(%rip), %rdx    # 0x413830
imulq %rax, %rdx
shrq $0x10, %rdx
sarl $0x8, %edx
addl 0x3d5795(%rip), %edx    # 0x41382c
testl %edx, %edx
movl $0x0, %eax
cmovlel %eax, %edx
movswl 0x3d5780(%rip), %eax    # 0x413828
decl %eax
cmpl %eax, %edx
cmovll %edx, %eax
shll $0x8, %eax
movslq %eax, %rsi
addq 0x50(%rsp), %rsi
movq %rsi, 0x4149df(%rip)    # 0x452aa0
movq 0x20(%rsp), %rax
movslq (%rax,%r14,4), %rdx
movslq 0x414a0f(%rip), %rax    # 0x452ae0
addq %rdx, %rax
movq %rax, 0x4149e5(%rip)    # 0x452ac0
cmpl 0x34(%rsp), %eax
jl 0x3e102
movl 0x30(%rsp), %edx
cmpl 0x10(%rsp), %edx
jne 0x3e0f1
andl 0x38(%rsp), %eax
jmp 0x3e0fb
xorl %edx, %edx
divq 0x38(%rsp)
movq %rdx, %rax
movq %rax, 0x4149be(%rip)    # 0x452ac0
movswl %cx, %edx
movswl %di, %eax
movq 0x4149b1(%rip), %r8     # 0x452ac0
movq %r8, %rdi
movq 0x48(%rsp), %rcx
shlq %cl, %rdi
imulq %rcx, %r8
movl 0x14(%rsp), %ecx
cmpl 0xc(%rsp), %ecx
cmoveq %rdi, %r8
movq %r8, 0x41498f(%rip)     # 0x452ac0
movl 0x4149b9(%rip), %edi    # 0x452af0
imull (%rbx,%r14,4), %edi
movl %edi, 0x41494e(%rip)    # 0x452a90
movl %edx, %ecx
subl 0x23c952(%rip), %ecx    # 0x27aa9c
incl %ecx
imull %edi, %ecx
addl 0x414997(%rip), %ecx    # 0x452aec
movl %ecx, 0x414925(%rip)    # 0x452a80
movslq %edx, %r9
notl %edx
addl %eax, %edx
movswq 0x3d0ea6(%rip), %rax    # 0x40f010
leaq 0x35a16f(%rip), %r10    # 0x3982e0
addq (%r10,%rax,8), %r8
leaq 0x3d7b24(%rip), %rax    # 0x415ca0
movslq (%rax,%r9,4), %r9
addq 0x398609(%rip), %r9     # 0x3d6790
movq 0x28(%rsp), %rax
addq %r14, %rax
addq %rax, %r9
callq 0x6de8d
movq 0x18(%rsp), %rsi
leaq 0x3967ed(%rip), %r8     # 0x3d4990
incq %r14
cmpl %r14d, %esi
jne 0x3e047
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xab51