// File: /workspace/github_c_makefile_star2_O3/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, 0x18(%rsp)
movq %r8, %r12
movq %rcx, %r13
movl %edi, %r15d
movl 0x3c8cdb(%rip), %eax    # 0x407fec
leal -0x1(%rax), %r14d
cmpl %esi, %eax
cmovgl %esi, %r14d
movswl 0x3d0cee(%rip), %edi    # 0x410010
movslq %edi, %rax
leaq 0x3d0cf4(%rip), %rcx    # 0x410020
movswl (%rcx,%rax,2), %ebp
leaq 0x3c24a9(%rip), %rcx    # 0x4017e0
movswl (%rcx,%rax,2), %ecx
movl %ecx, 0x8(%rsp)
leaq 0x3ef3fa(%rip), %rcx    # 0x42e740
cmpb $-0x39, (%rax,%rcx)
ja 0x3f350
movb $-0x39, (%rax,%rcx)
movl %edi, %ecx
andl $0x7, %ecx
leaq 0x65444(%rip), %rsi     # 0xa47a0
movb (%rcx,%rsi), %cl
movl %edi, %esi
sarl $0x3, %esi
movslq %esi, %r8
leaq 0x3eef42(%rip), %rsi    # 0x42e2b0
orb %cl, (%r8,%rsi)
testw %bp, %bp
setle %cl
cmpw $0x0, 0x8(%rsp)
setle %sil
orb %cl, %sil
je 0x3f396
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %r15d, %rcx
movq %rcx, 0x20(%rsp)
movswl (%rdx,%rcx,2), %esi
movl 0x23c6ec(%rip), %ecx    # 0x27ba94
cmpl %esi, %ecx
jge 0x3f3b7
movslq %r14d, %rsi
movswl (%rdx,%rsi,2), %esi
cmpl %esi, %ecx
jl 0x3f387
movq 0x20(%rsp), %rcx
cmpw $0x0, (%r13,%rcx,2)
jns 0x3f3d1
movslq %r14d, %rcx
cmpw $0x0, (%r13,%rcx,2)
js 0x3f387
movq %rdx, 0x10(%rsp)
leaq 0x359f03(%rip), %rcx    # 0x3992e0
cmpq $0x0, (%rcx,%rax,8)
jne 0x3f3f1
callq 0x2fc7e
movswq 0x3d0c1f(%rip), %rax    # 0x410010
leaq 0x3d5458(%rip), %rcx    # 0x414850
movzbl (%rax,%rcx), %edx
movl %edx, %eax
andl $0xf, %eax
leaq 0x653a8(%rip), %rcx     # 0xa47b0
movl (%rcx,%rax,4), %eax
xorl %ebx, %ebx
movl %ebp, 0xc(%rsp)
movl %eax, 0x2c(%rsp)
cmpl %ebp, %eax
sete %bpl
shrl $0x4, %edx
movq %rdx, 0x50(%rsp)
movl (%rcx,%rdx,4), %eax
movl %eax, 0x34(%rsp)
movslq 0x3d0bd3(%rip), %rax    # 0x410004
leaq 0x3596a8(%rip), %rcx    # 0x398ae0
movq (%rcx,%rax,8), %rax
movq %rax, 0x48(%rsp)
movswl 0x4146a0(%rip), %edi    # 0x453ae8
callq 0x6fc10
subl %r15d, %r14d
jl 0x3f612
movb %bpl, %bl
movl 0xc(%rsp), %eax
subl %ebx, %eax
movl %eax, 0x30(%rsp)
movl %eax, %eax
movq %rax, 0x38(%rsp)
movl 0x8(%rsp), %eax
movq %rax, 0x40(%rsp)
movq 0x20(%rsp), %rax
movq %r12, %rdx
leaq (%rax,%rax), %r12
movq %r13, %rsi
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,2), %r13
leaq (%rsi,%rax,2), %r15
leaq (%rdx,%rax,4), %r9
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, 0x18(%rsp)
incl %r14d
leaq 0x3946e5(%rip), %rbp    # 0x3d3b90
leaq 0x3964de(%rip), %rsi    # 0x3d5990
xorl %ebx, %ebx
movq %r14, 0x10(%rsp)
movzwl (%r13,%rbx,2), %eax
leaq (%r12,%rbx,2), %rdx
movzwl (%rbp,%rdx), %ecx
cmpw %cx, %ax
cmovgl %eax, %ecx
movzwl (%r15,%rbx,2), %eax
movzwl (%rsi,%rdx), %edi
cmpw %di, %ax
cmovll %eax, %edi
cmpw %cx, %di
jle 0x3f606
movslq (%r9,%rbx,4), %rax
movslq 0x3d533f(%rip), %rdx    # 0x414830
imulq %rax, %rdx
shrq $0x10, %rdx
sarl $0x8, %edx
addl 0x3d532a(%rip), %edx    # 0x41482c
testl %edx, %edx
movl $0x0, %eax
cmovlel %eax, %edx
movswl 0x3d5315(%rip), %eax    # 0x414828
decl %eax
cmpl %eax, %edx
cmovll %edx, %eax
shll $0x8, %eax
movslq %eax, %rsi
addq 0x48(%rsp), %rsi
movq %rsi, 0x414574(%rip)    # 0x453aa0
movq 0x18(%rsp), %rax
movslq (%rax,%rbx,4), %rax
movslq 0x4145a4(%rip), %r8     # 0x453ae0
addq %rax, %r8
cmpl 0x30(%rsp), %r8d
jl 0x3f564
movl 0x2c(%rsp), %eax
cmpl 0xc(%rsp), %eax
jne 0x3f557
andl 0x38(%rsp), %r8d
jmp 0x3f564
movq %r8, %rax
xorl %edx, %edx
divq 0x38(%rsp)
movq %rdx, %r8
movswl %cx, %edx
movswl %di, %eax
movq %r8, %rdi
movq 0x50(%rsp), %rcx
shlq %cl, %rdi
imulq 0x40(%rsp), %r8
movl 0x34(%rsp), %ecx
cmpl 0x8(%rsp), %ecx
cmoveq %rdi, %r8
movq %r8, 0x414532(%rip)     # 0x453ac0
movl 0x41455c(%rip), %edi    # 0x453af0
imull (%r9,%rbx,4), %edi
movl %edi, 0x4144f1(%rip)    # 0x453a90
movl %edx, %ecx
subl 0x23c4f5(%rip), %ecx    # 0x27ba9c
incl %ecx
imull %edi, %ecx
addl 0x41453a(%rip), %ecx    # 0x453aec
movl %ecx, 0x4144c8(%rip)    # 0x453a80
movq %r9, %r14
movslq %edx, %r9
notl %edx
addl %eax, %edx
movswq 0x3d0a46(%rip), %rax    # 0x410010
leaq 0x359d0f(%rip), %r10    # 0x3992e0
addq (%r10,%rax,8), %r8
leaq 0x3d76c4(%rip), %rax    # 0x416ca0
movslq (%rax,%r9,4), %r9
addq 0x3981a9(%rip), %r9     # 0x3d7790
movq 0x20(%rsp), %rax
addq %rbx, %rax
addq %rax, %r9
callq 0x6fc17
movq %r14, %r9
movq 0x10(%rsp), %r14
leaq 0x39638a(%rip), %rsi    # 0x3d5990
incq %rbx
cmpl %ebx, %r14d
jne 0x3f4b9
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xacd7