// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %r8, %r13
movq %rcx, 0x18(%rsp)
movq %rdx, 0x8(%rsp)
movl %edi, %ebx
movl 0x3c5dd7(%rip), %eax    # 0x400fec
leal -0x1(%rax), %r15d
cmpl %esi, %eax
cmovgl %esi, %r15d
movswl 0x3cddea(%rip), %eax    # 0x409010
movslq %eax, %rdi
leaq 0x3cddf0(%rip), %rax    # 0x409020
movswl (%rax,%rdi,2), %eax
movl %eax, 0x10(%rsp)
testl %eax, %eax
setle %r14b
leaq 0x3bf59b(%rip), %rax    # 0x3fa7e0
movzwl (%rax,%rdi,2), %ebp
callq 0x2cc16
testw %bp, %bp
setle %al
orb %r14b, %al
je 0x3b268
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %ebx, %rsi
movq 0x8(%rsp), %rax
movswl (%rax,%rsi,2), %ecx
movl 0x23981a(%rip), %eax    # 0x274a94
movslq %r15d, %rdx
cmpl %ecx, %eax
jge 0x3b28e
movq 0x8(%rsp), %rcx
movswl (%rcx,%rdx,2), %ecx
cmpl %ecx, %eax
jl 0x3b259
movq 0x18(%rsp), %rax
cmpw $0x0, (%rax,%rsi,2)
jns 0x3b2a6
movq 0x18(%rsp), %rax
cmpw $0x0, (%rax,%rdx,2)
js 0x3b259
movq %rsi, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
movswl %bp, %eax
movl %eax, 0x14(%rsp)
movswq 0x3cdd51(%rip), %rdi    # 0x409010
leaq 0x35701a(%rip), %rax    # 0x3922e0
cmpq $0x0, (%rax,%rdi,8)
je 0x3b2d2
movq %r12, %r14
jmp 0x3b2e2
movq %r12, %r14
callq 0x2cc4a
movswq 0x3cdd2e(%rip), %rdi    # 0x409010
leaq 0x3d2567(%rip), %rax    # 0x40d850
movzbl (%rdi,%rax), %esi
movl %esi, %eax
andl $0xf, %eax
leaq 0x624b7(%rip), %rcx     # 0x9d7b0
movl (%rcx,%rax,4), %edi
xorl %eax, %eax
movl 0x10(%rsp), %edx
movl %edi, 0x28(%rsp)
cmpl %edx, %edi
sete %al
subl %eax, %edx
movq %rdx, 0x20(%rsp)
shrl $0x4, %esi
movq %rsi, 0x50(%rsp)
movl (%rcx,%rsi,4), %eax
movl %eax, 0x2c(%rsp)
movslq 0x3cdcdc(%rip), %rax    # 0x409004
leaq 0x3567b1(%rip), %rcx    # 0x391ae0
movq (%rcx,%rax,8), %rax
movq %rax, 0x48(%rsp)
movswl 0x4117a9(%rip), %edi    # 0x44cae8
callq 0x64355
movl 0x14(%rsp), %eax
movq %rax, 0x40(%rsp)
movq 0x30(%rsp), %r8
leaq (%r8,%r8), %r12
movq 0x8(%rsp), %rax
leaq (%rax,%r8,2), %rbp
movq 0x18(%rsp), %rax
leaq (%rax,%r8,2), %rbx
leaq (%r13,%r8,4), %r13
leaq (%r14,%r8,4), %rax
movq %rax, 0x8(%rsp)
leaq 0x391813(%rip), %rdi    # 0x3ccb90
leaq 0x39360c(%rip), %r14    # 0x3ce990
xorl %r15d, %r15d
movq 0x38(%rsp), %rsi
leaq (%r8,%r15), %r9
cmpq %rsi, %r9
jg 0x3b4eb
movzwl (%rbp,%r15,2), %eax
leaq (%r12,%r15,2), %rdx
movzwl (%rdi,%rdx), %ecx
cmpw %cx, %ax
cmovgl %eax, %ecx
movzwl (%rbx,%r15,2), %eax
movzwl (%r14,%rdx), %r10d
cmpw %r10w, %ax
cmovll %eax, %r10d
cmpw %cx, %r10w
jle 0x3b4e3
movslq (%r13,%r15,4), %rax
movslq 0x3d245b(%rip), %rdx    # 0x40d830
imulq %rax, %rdx
shrq $0x10, %rdx
sarl $0x8, %edx
addl 0x3d2446(%rip), %edx    # 0x40d82c
testl %edx, %edx
movl $0x0, %eax
cmovlel %eax, %edx
movswl 0x3d2431(%rip), %eax    # 0x40d828
decl %eax
cmpl %eax, %edx
cmovll %edx, %eax
shll $0x8, %eax
movslq %eax, %rsi
addq 0x48(%rsp), %rsi
movq %rsi, 0x411690(%rip)    # 0x44caa0
movq 0x8(%rsp), %rax
movslq (%rax,%r15,4), %rax
movslq 0x4116c0(%rip), %r8     # 0x44cae0
addq %rax, %r8
cmpl 0x20(%rsp), %r8d
jl 0x3b448
movl 0x28(%rsp), %eax
cmpl 0x10(%rsp), %eax
jne 0x3b43b
andl 0x20(%rsp), %r8d
jmp 0x3b448
movq %r8, %rax
xorl %edx, %edx
divq 0x20(%rsp)
movq %rdx, %r8
movswl %cx, %edx
movq %r8, %rax
movq 0x50(%rsp), %rcx
shlq %cl, %rax
imulq 0x40(%rsp), %r8
movl 0x2c(%rsp), %ecx
cmpl 0x14(%rsp), %ecx
cmoveq %rax, %r8
movq %r8, 0x411651(%rip)     # 0x44cac0
movl 0x41167b(%rip), %edi    # 0x44caf0
imull (%r13,%r15,4), %edi
movswl %r10w, %eax
movl %edx, %ecx
subl 0x239615(%rip), %ecx    # 0x274a9c
incl %ecx
imull %edi, %ecx
addl 0x41165a(%rip), %ecx    # 0x44caec
movl %edi, 0x4115f8(%rip)    # 0x44ca90
movl %ecx, 0x4115e2(%rip)    # 0x44ca80
movslq %edx, %r10
notl %edx
addl %eax, %edx
movswq 0x3cdb63(%rip), %rax    # 0x409010
leaq 0x356e2c(%rip), %r11    # 0x3922e0
addq (%r11,%rax,8), %r8
leaq 0x3d47e1(%rip), %rax    # 0x40fca0
movslq (%rax,%r10,4), %rax
addq 0x3952c6(%rip), %rax    # 0x3d0790
addq %rax, %r9
callq 0x6435c
movq 0x38(%rsp), %rsi
leaq 0x3916b2(%rip), %rdi    # 0x3ccb90
movq 0x30(%rsp), %r8
incq %r15
jmp 0x3b38c
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9fd2