// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: hitscan
int hitscan(int xs, int ys, int zs, short sectnum, int vx, int vy, int vz,
	short *hitsect, short *hitwall, short *hitsprite,
	int *hitx, int *hity, int *hitz, unsigned int cliptype)
{
	sectortype *sec;
	walltype *wal, *wal2;
	spritetype *spr;
	int z, zz, x1, y1=0, z1=0, x2, y2, x3, y3, x4, y4, intx, inty, intz;
	int topt, topu, bot, dist, offx, offy, cstat;
	int i, j, k, l, tilenum, xoff, yoff, dax, day, daz, daz2;
	int ang, cosang, sinang, xspan, yspan, xrepeat, yrepeat;
	int dawalclipmask, dasprclipmask;
	short tempshortcnt, tempshortnum, dasector, startwall, endwall;
	short nextsector;
	unsigned char clipyou;

	*hitsect = -1; *hitwall = -1; *hitsprite = -1;
	if (sectnum < 0) return(-1);

	*hitx = hitscangoalx; *hity = hitscangoaly;

	dawalclipmask = (cliptype&65535);
	dasprclipmask = (cliptype>>16);

	clipsectorlist[0] = sectnum;
	tempshortcnt = 0; tempshortnum = 1;
	do
	{
		dasector = clipsectorlist[tempshortcnt]; sec = &sector[dasector];

		x1 = 0x7fffffff;
		if (sec->ceilingstat&2)
		{
			wal = &wall[sec->wallptr]; wal2 = &wall[wal->point2];
			dax = wal2->x-wal->x; day = wal2->y-wal->y;
			i = nsqrtasm(dax*dax+day*day); if (i == 0) continue;
			i = divscale15(sec->ceilingheinum,i);
			dax *= i; day *= i;

			j = (vz<<8)-dmulscale15(dax,vy,-day,vx);
			if (j != 0)
			{
				i = ((sec->ceilingz-zs)<<8)+dmulscale15(dax,ys-wal->y,-day,xs-wal->x);
				if (((i^j) >= 0) && ((klabs(i)>>1) < klabs(j)))
				{
					i = divscale30(i,j);
					x1 = xs + mulscale30(vx,i);
					y1 = ys + mulscale30(vy,i);
					z1 = zs + mulscale30(vz,i);
				}
			}
		}
		else if ((vz < 0) && (zs >= sec->ceilingz))
		{
			z1 = sec->ceilingz; i = z1-zs;
			if ((klabs(i)>>1) < -vz)
			{
				i = divscale30(i,vz);
				x1 = xs + mulscale30(vx,i);
				y1 = ys + mulscale30(vy,i);
			}
		}
		if ((x1 != 0x7fffffff) && (klabs(x1-xs)+klabs(y1-ys) < klabs((*hitx)-xs)+klabs((*hity)-ys)))
			if (inside(x1,y1,dasector) != 0)
			{
				*hitsect = dasector; *hitwall = -1; *hitsprite = -1;
				*hitx = x1; *hity = y1; *hitz = z1;
			}

		x1 = 0x7fffffff;
		if (sec->floorstat&2)
		{
			wal = &wall[sec->wallptr]; wal2 = &wall[wal->point2];
			dax = wal2->x-wal->x; day = wal2->y-wal->y;
			i = nsqrtasm(dax*dax+day*day); if (i == 0) continue;
			i = divscale15(sec->floorheinum,i);
			dax *= i; day *= i;

			j = (vz<<8)-dmulscale15(dax,vy,-day,vx);
			if (j != 0)
			{
				i = ((sec->floorz-zs)<<8)+dmulscale15(dax,ys-wal->y,-day,xs-wal->x);
				if (((i^j) >= 0) && ((klabs(i)>>1) < klabs(j)))
				{
					i = divscale30(i,j);
					x1 = xs + mulscale30(vx,i);
					y1 = ys + mulscale30(vy,i);
					z1 = zs + mulscale30(vz,i);
				}
			}
		}
		else if ((vz > 0) && (zs <= sec->floorz))
		{
			z1 = sec->floorz; i = z1-zs;
			if ((klabs(i)>>1) < vz)
			{
				i = divscale30(i,vz);
				x1 = xs + mulscale30(vx,i);
				y1 = ys + mulscale30(vy,i);
			}
		}
		if ((x1 != 0x7fffffff) && (klabs(x1-xs)+klabs(y1-ys) < klabs((*hitx)-xs)+klabs((*hity)-ys)))
			if (inside(x1,y1,dasector) != 0)
			{
				*hitsect = dasector; *hitwall = -1; *hitsprite = -1;
				*hitx = x1; *hity = y1; *hitz = z1;
			}

		startwall = sec->wallptr; endwall = startwall + sec->wallnum;
		for(z=startwall,wal=&wall[startwall];z<endwall;z++,wal++)
		{
			wal2 = &wall[wal->point2];
			x1 = wal->x; y1 = wal->y; x2 = wal2->x; y2 = wal2->y;

			if ((x1-xs)*(y2-ys) < (x2-xs)*(y1-ys)) continue;
			if (rintersect(xs,ys,zs,vx,vy,vz,x1,y1,x2,y2,&intx,&inty,&intz) == 0) continue;

			if (klabs(intx-xs)+klabs(inty-ys) >= klabs((*hitx)-xs)+klabs((*hity)-ys)) continue;

			nextsector = wal->nextsector;
			if ((nextsector < 0) || (wal->cstat&dawalclipmask))
			{
				*hitsect = dasector; *hitwall = z; *hitsprite = -1;
				*hitx = intx; *hity = inty; *hitz = intz;
				continue;
			}
			getzsofslope(nextsector,intx,inty,&daz,&daz2);
			if ((intz <= daz) || (intz >= daz2))
			{
				*hitsect = dasector; *hitwall = z; *hitsprite = -1;
				*hitx = intx; *hity = inty; *hitz = intz;
				continue;
			}

			for(zz=tempshortnum-1;zz>=0;zz--)
				if (clipsectorlist[zz] == nextsector) break;
			if (zz < 0) clipsectorlist[tempshortnum++] = nextsector;
		}

		for(z=headspritesect[dasector];z>=0;z=nextspritesect[z])
		{
			spr = &sprite[z];
			cstat = spr->cstat;
#if USE_POLYMOST
			if (!hitallsprites)
#endif
			if ((cstat&dasprclipmask) == 0) continue;

			x1 = spr->x; y1 = spr->y; z1 = spr->z;
			switch(cstat&48)
			{
				case 0:
					topt = vx*(x1-xs) + vy*(y1-ys); if (topt <= 0) continue;
					bot = vx*vx + vy*vy; if (bot == 0) continue;

					intz = zs+scale(vz,topt,bot);

					i = (tilesizy[spr->picnum]*spr->yrepeat<<2);
					if (cstat&128) z1 += (i>>1);
					if (picanm[spr->picnum]&0x00ff0000) z1 -= ((int)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2);
					if ((intz > z1) || (intz < z1-i)) continue;
					topu = vx*(y1-ys) - vy*(x1-xs);

					offx = scale(vx,topu,bot);
					offy = scale(vy,topu,bot);
					dist = offx*offx + offy*offy;
					i = tilesizx[spr->picnum]*spr->xrepeat; i *= i;
					if (dist > (i>>7)) continue;
					intx = xs + scale(vx,topt,bot);
					inty = ys + scale(vy,topt,bot);

					if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue;

					*hitsect = dasector; *hitwall = -1; *hitsprite = z;
					*hitx = intx; *hity = inty; *hitz = intz;
					break;
				case 16:
						//These lines get the 2 points of the rotated sprite
						//Given: (x1, y1) starts out as the center point
					tilenum = spr->picnum;
					xoff = (int)((signed char)((picanm[tilenum]>>8)&255))+((int)spr->xoffset);
					if ((cstat&4) > 0) xoff = -xoff;
					k = spr->ang; l = spr->xrepeat;
					dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l;
					l = tilesizx[tilenum]; k = (l>>1)+xoff;
					x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l);
					y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l);

					if ((cstat&64) != 0)   //back side of 1-way sprite
						if ((x1-xs)*(y2-ys) < (x2-xs)*(y1-ys)) continue;

					if (rintersect(xs,ys,zs,vx,vy,vz,x1,y1,x2,y2,&intx,&inty,&intz) == 0) continue;

					if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue;

					k = ((tilesizy[spr->picnum]*spr->yrepeat)<<2);
					if (cstat&128) daz = spr->z+(k>>1); else daz = spr->z;
					if (picanm[spr->picnum]&0x00ff0000) daz -= ((int)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2);
					if ((intz < daz) && (intz > daz-k))
					{
						*hitsect = dasector; *hitwall = -1; *hitsprite = z;
						*hitx = intx; *hity = inty; *hitz = intz;
					}
					break;
				case 32:
					if (vz == 0) continue;
					intz = z1;
					if (((intz-zs)^vz) < 0) continue;
					if ((cstat&64) != 0)
						if ((zs > intz) == ((cstat&8)==0)) continue;

					intx = xs+scale(intz-zs,vx,vz);
					inty = ys+scale(intz-zs,vy,vz);

					if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue;

					tilenum = spr->picnum;
					xoff = (int)((signed char)((picanm[tilenum]>>8)&255))+((int)spr->xoffset);
					yoff = (int)((signed char)((picanm[tilenum]>>16)&255))+((int)spr->yoffset);
					if ((cstat&4) > 0) xoff = -xoff;
					if ((cstat&8) > 0) yoff = -yoff;

					ang = spr->ang;
					cosang = sintable[(ang+512)&2047]; sinang = sintable[ang];
					xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat;
					yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat;

					dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat;
					x1 += dmulscale16(sinang,dax,cosang,day)-intx;
					y1 += dmulscale16(sinang,day,-cosang,dax)-inty;
					l = xspan*xrepeat;
					x2 = x1 - mulscale16(sinang,l);
					y2 = y1 + mulscale16(cosang,l);
					l = yspan*yrepeat;
					k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k;
					k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k;

					clipyou = 0;
					if ((y1^y2) < 0)
					{
						if ((x1^x2) < 0) clipyou ^= (x1*y2<x2*y1)^(y1<y2);
						else if (x1 >= 0) clipyou ^= 1;
					}
					if ((y2^y3) < 0)
					{
						if ((x2^x3) < 0) clipyou ^= (x2*y3<x3*y2)^(y2<y3);
						else if (x2 >= 0) clipyou ^= 1;
					}
					if ((y3^y4) < 0)
					{
						if ((x3^x4) < 0) clipyou ^= (x3*y4<x4*y3)^(y3<y4);
						else if (x3 >= 0) clipyou ^= 1;
					}
					if ((y4^y1) < 0)
					{
						if ((x4^x1) < 0) clipyou ^= (x4*y1<x1*y4)^(y4<y1);
						else if (x4 >= 0) clipyou ^= 1;
					}

					if (clipyou != 0)
					{
						*hitsect = dasector; *hitwall = -1; *hitsprite = z;
						*hitx = intx; *hity = inty; *hitz = intz;
					}
					break;
			}
		}
		tempshortcnt++;
	} while (tempshortcnt < tempshortnum);
	return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %edx, 0x4(%rsp)
movq %rsi, 0x8(%rsp)
movl %edi, %r12d
movq 0xf8(%rsp), %rax
movq 0xf0(%rsp), %rdx
movq 0xe8(%rsp), %rsi
movw $0xffff, %di            # imm = 0xFFFF
movw %di, (%rsi)
movw %di, (%rdx)
movw %di, (%rax)
testw %cx, %cx
js 0x38373
movl 0x118(%rsp), %edx
movq 0x108(%rsp), %rsi
movq 0x100(%rsp), %rdi
movl 0xe0(%rsp), %r15d
movl 0x6d53d(%rip), %eax     # 0xa4834
movl %eax, (%rdi)
movl 0x6d539(%rip), %eax     # 0xa4838
movl %eax, (%rsi)
shrl $0x10, %edx
movl %edx, 0x88(%rsp)
movw %cx, 0x3fa22e(%rip)     # 0x431540
movl %r15d, %eax
shll $0x8, %eax
movl %eax, 0x64(%rsp)
movslq %r9d, %rbp
movl %r8d, 0x3c(%rsp)
movslq %r8d, %rax
movslq %r15d, %rcx
movl %ecx, %edx
movq %rdx, 0x98(%rsp)
movq %rcx, 0x50(%rsp)
negl %ecx
movl %ecx, 0x84(%rsp)
movq %rax, 0x48(%rsp)
imull %eax, %eax
movl %ebp, %ecx
imull %ecx, %ecx
addl %eax, %ecx
movq %rcx, 0x90(%rsp)
movw $0x1, %ax
movl %eax, 0x40(%rsp)
xorl %r10d, %r10d
leaq 0x3fa1d5(%rip), %r11    # 0x431540
movl %r9d, 0x10(%rsp)
movq 0x8(%rsp), %r9
movq %r12, 0x18(%rsp)
movq %rbp, 0x70(%rsp)
movswq %r10w, %rax
movzwl (%r11,%rax,2), %eax
movw %ax, 0x2(%rsp)
movswq %ax, %rax
movq %rax, 0x58(%rsp)
leaq (%rax,%rax,4), %rax
leaq 0x20c6bf(%rip), %rcx    # 0x243a60
leaq (%rcx,%rax,8), %r14
testb $0x2, 0xc(%r14)
jne 0x373f3
movl %r10d, 0x44(%rsp)
testl %r15d, %r15d
jns 0x37603
movl 0x4(%r14), %r15d
movl %r15d, %eax
subl 0x4(%rsp), %eax
jg 0x37603
movl %eax, %ecx
negl %ecx
shrl %ecx
cmpl 0x84(%rsp), %ecx
jae 0x37603
cltq
shlq $0x1e, %rax
cqto
idivq 0x50(%rsp)
movslq %eax, %r13
jmp 0x37539
movswq (%r14), %rax
shlq $0x5, %rax
leaq 0x18164e(%rip), %rdx    # 0x1b8a50
movswq 0x8(%rax,%rdx), %rcx
shlq $0x5, %rcx
movl (%rax,%rdx), %esi
movl 0x4(%rax,%rdx), %edi
movl (%rcx,%rdx), %r9d
movl 0x4(%rcx,%rdx), %r8d
subl %esi, %r9d
subl %edi, %r8d
movl %r9d, %eax
imull %r9d, %eax
movl %r8d, %edx
imull %edx, %edx
addl %eax, %edx
movl %edx, %eax
shrl $0x18, %eax
orl $0x1000, %eax           # imm = 0x1000
movl %edx, %ecx
shrl $0xc, %ecx
cmpl $0x1000000, %edx        # imm = 0x1000000
cmovael %eax, %ecx
leaq 0x41eab0(%rip), %rax    # 0x455f00
movzwl (%rax,%rcx,2), %ecx
shrl %cl, %edx
leaq 0x420ca3(%rip), %rax    # 0x458100
movzwl (%rax,%rdx,2), %edx
shrl $0x8, %ecx
shrl %cl, %edx
testl %edx, %edx
je 0x38354
movl %r10d, 0x44(%rsp)
movswq 0x12(%r14), %rax
shlq $0xf, %rax
movl %edx, %ecx
cqto
idivq %rcx
imull %eax, %r9d
imull %eax, %r8d
negl %r8d
movslq %r9d, %rdx
movq %rdx, %rcx
imulq %rbp, %rcx
movslq %r8d, %rax
movq %rax, %r8
imulq 0x48(%rsp), %r8
addq %rcx, %r8
shrq $0xf, %r8
movl 0x64(%rsp), %ecx
subl %r8d, %ecx
movq 0x8(%rsp), %r9
je 0x37603
movl 0x4(%r14), %r8d
subl 0x4(%rsp), %r8d
shll $0x8, %r8d
movq 0x8(%rsp), %r9
subl %edi, %r9d
movl %r12d, %edi
subl %esi, %edi
movslq %r9d, %rsi
movq 0x8(%rsp), %r9
imulq %rsi, %rdx
movslq %edi, %rsi
imulq %rsi, %rax
addq %rdx, %rax
shrq $0xf, %rax
addl %r8d, %eax
movl %eax, %edx
xorl %ecx, %edx
js 0x37603
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
shrl %edx
movl %ecx, %esi
negl %esi
cmovsl %ecx, %esi
cmpl %esi, %edx
jae 0x37603
cltq
shlq $0x1e, %rax
movslq %ecx, %rcx
cqto
idivq %rcx
movslq %eax, %r13
movq %r13, %r15
imulq 0x50(%rsp), %r15
shrq $0x1e, %r15
addl 0x4(%rsp), %r15d
movq %r13, %rax
imulq 0x48(%rsp), %rax
shrq $0x1e, %rax
leal (%rax,%r12), %ebx
cmpl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
je 0x37603
imulq %rbp, %r13
shrq $0x1e, %r13
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %r13d, %eax
negl %eax
cmovsl %r13d, %eax
addl %ecx, %eax
movq 0x100(%rsp), %rcx
movl (%rcx), %ecx
subl %r12d, %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
movq 0x108(%rsp), %rcx
movl (%rcx), %ecx
subl %r9d, %ecx
movl %ecx, %esi
negl %esi
cmovsl %ecx, %esi
addl %edx, %esi
cmpl %esi, %eax
jae 0x37603
addl %r9d, %r13d
movswl 0x2(%rsp), %edx
movl %ebx, %edi
movl %r13d, %esi
callq 0x367f7
movq 0x8(%rsp), %r9
testl %eax, %eax
je 0x37603
movq 0xe8(%rsp), %rax
movzwl 0x2(%rsp), %ecx
movw %cx, (%rax)
movq 0xf0(%rsp), %rax
movw $0xffff, %cx            # imm = 0xFFFF
movw %cx, (%rax)
movq 0xf8(%rsp), %rax
movw %cx, (%rax)
movq 0x100(%rsp), %rax
movl %ebx, (%rax)
movq 0x108(%rsp), %rax
movl %r13d, (%rax)
movq 0x110(%rsp), %rax
movl %r15d, (%rax)
testb $0x2, 0xe(%r14)
jne 0x37652
cmpl $0x0, 0xe0(%rsp)
jle 0x3785d
movl 0x8(%r14), %r15d
movl %r15d, %eax
subl 0x4(%rsp), %eax
jl 0x3785d
movl %eax, %ecx
shrl %ecx
cmpl 0xe0(%rsp), %ecx
jae 0x3785d
cltq
shlq $0x1e, %rax
cqto
idivq 0x98(%rsp)
movslq %eax, %r13
jmp 0x37793
movswq (%r14), %rax
shlq $0x5, %rax
leaq 0x1813ef(%rip), %rdx    # 0x1b8a50
movswq 0x8(%rax,%rdx), %rcx
shlq $0x5, %rcx
movl (%rax,%rdx), %esi
movl 0x4(%rax,%rdx), %edi
movl (%rcx,%rdx), %r9d
movl 0x4(%rcx,%rdx), %r8d
subl %esi, %r9d
subl %edi, %r8d
movl %r9d, %eax
imull %r9d, %eax
movl %r8d, %edx
imull %edx, %edx
addl %eax, %edx
movl %edx, %eax
shrl $0x18, %eax
orl $0x1000, %eax           # imm = 0x1000
movl %edx, %ecx
shrl $0xc, %ecx
cmpl $0x1000000, %edx        # imm = 0x1000000
cmovael %eax, %ecx
leaq 0x41e851(%rip), %rax    # 0x455f00
movzwl (%rax,%rcx,2), %ecx
shrl %cl, %edx
leaq 0x420a44(%rip), %rax    # 0x458100
movzwl (%rax,%rdx,2), %edx
shrl $0x8, %ecx
shrl %cl, %edx
testl %edx, %edx
je 0x3835b
movswq 0x1a(%r14), %rax
shlq $0xf, %rax
movl %edx, %ecx
cqto
idivq %rcx
imull %eax, %r9d
imull %eax, %r8d
negl %r8d
movslq %r9d, %rdx
movq %rdx, %rcx
imulq %rbp, %rcx
movslq %r8d, %rax
movq %rax, %r8
imulq 0x48(%rsp), %r8
addq %rcx, %r8
shrq $0xf, %r8
movl 0x64(%rsp), %ecx
subl %r8d, %ecx
movq 0x8(%rsp), %r9
je 0x3785d
movl 0x8(%r14), %r8d
subl 0x4(%rsp), %r8d
shll $0x8, %r8d
movq 0x8(%rsp), %r9
subl %edi, %r9d
movl %r12d, %edi
subl %esi, %edi
movslq %r9d, %rsi
movq 0x8(%rsp), %r9
imulq %rsi, %rdx
movslq %edi, %rsi
imulq %rsi, %rax
addq %rdx, %rax
shrq $0xf, %rax
addl %r8d, %eax
movl %eax, %edx
xorl %ecx, %edx
js 0x3785d
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
shrl %edx
movl %ecx, %esi
negl %esi
cmovsl %ecx, %esi
cmpl %esi, %edx
jae 0x3785d
cltq
shlq $0x1e, %rax
movslq %ecx, %rcx
cqto
idivq %rcx
movslq %eax, %r13
movq %r13, %r15
imulq 0x50(%rsp), %r15
shrq $0x1e, %r15
addl 0x4(%rsp), %r15d
movq %r13, %rax
imulq 0x48(%rsp), %rax
shrq $0x1e, %rax
leal (%rax,%r12), %ebx
cmpl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
je 0x3785d
imulq %rbp, %r13
shrq $0x1e, %r13
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %r13d, %eax
negl %eax
cmovsl %r13d, %eax
addl %ecx, %eax
movq 0x100(%rsp), %rcx
movl (%rcx), %ecx
subl %r12d, %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
movq 0x108(%rsp), %rcx
movl (%rcx), %ecx
subl %r9d, %ecx
movl %ecx, %esi
negl %esi
cmovsl %ecx, %esi
addl %edx, %esi
cmpl %esi, %eax
jae 0x3785d
addl %r9d, %r13d
movswl 0x2(%rsp), %edx
movl %ebx, %edi
movl %r13d, %esi
callq 0x367f7
movq 0x8(%rsp), %r9
testl %eax, %eax
je 0x3785d
movq 0xe8(%rsp), %rax
movzwl 0x2(%rsp), %ecx
movw %cx, (%rax)
movq 0xf0(%rsp), %rax
movw $0xffff, %cx            # imm = 0xFFFF
movw %cx, (%rax)
movq 0xf8(%rsp), %rax
movw %cx, (%rax)
movq 0x100(%rsp), %rax
movl %ebx, (%rax)
movq 0x108(%rsp), %rax
movl %r13d, (%rax)
movq 0x110(%rsp), %rax
movl %r15d, (%rax)
movswq (%r14), %r15
movzwl 0x2(%r14), %eax
addw %r15w, %ax
cmpw %ax, %r15w
jge 0x37b15
movswl %ax, %r13d
movq %r15, %rbp
shlq $0x5, %rbp
leaq 0x1811ca(%rip), %rax    # 0x1b8a50
addq %rax, %rbp
movl 0x10(%rsp), %r14d
leaq 0x24541b(%rip), %rdi    # 0x27ccb0
movl %r13d, 0x30(%rsp)
movswq 0x8(%rbp), %rcx
shlq $0x5, %rcx
movl (%rbp), %eax
movl 0x4(%rbp), %r10d
leaq 0x18119f(%rip), %rdx    # 0x1b8a50
movl (%rcx,%rdx), %r11d
movl 0x4(%rcx,%rdx), %ebx
movl %eax, %ecx
subl %r12d, %ecx
movl %ebx, %edx
subl %r9d, %edx
imull %ecx, %edx
movl %r11d, %ecx
subl %r12d, %ecx
movl %r10d, %esi
subl %r9d, %esi
imull %ecx, %esi
cmpl %esi, %edx
jl 0x37a20
subq $0x8, %rsp
movl %r12d, %edi
movl %r9d, %esi
movl 0xc(%rsp), %edx
movl 0x44(%rsp), %ecx
movl %r14d, %r8d
movq %r9, %r12
movl 0xe8(%rsp), %r9d
leaq 0x1c(%rsp), %r13
pushq %r13
leaq 0x38(%rsp), %r13
pushq %r13
leaq 0x44(%rsp), %r13
pushq %r13
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0x3838a
addq $0x40, %rsp
testl %eax, %eax
je 0x37a05
movl 0x2c(%rsp), %r14d
movl %r14d, %eax
movq 0x18(%rsp), %rsi
subl %esi, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl 0x28(%rsp), %ebx
movl %ebx, %eax
subl %r12d, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
addl %ecx, %edx
movq 0x100(%rsp), %rax
movl (%rax), %eax
subl %esi, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movq 0x108(%rsp), %rax
movl (%rax), %eax
subl %r12d, %eax
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
addl %ecx, %esi
cmpl %esi, %edx
movq %r12, %r9
jae 0x37a0a
movzwl 0xc(%rbp), %r12d
testw %r12w, %r12w
leaq 0x24531b(%rip), %rdi    # 0x27ccb0
movl 0x30(%rsp), %r13d
js 0x379ad
movzwl 0xe(%rbp), %eax
testl %eax, 0x118(%rsp)
je 0x37a35
movq 0xe8(%rsp), %rax
movzwl 0x2(%rsp), %ecx
movw %cx, (%rax)
movq 0xf0(%rsp), %rax
movw %r15w, (%rax)
movq 0xf8(%rsp), %rax
movw $0xffff, (%rax)         # imm = 0xFFFF
movq 0x100(%rsp), %rax
movl %r14d, (%rax)
movq 0x108(%rsp), %rax
movl %ebx, (%rax)
movl 0x14(%rsp), %eax
movq 0x110(%rsp), %rcx
movl %eax, (%rcx)
movl 0x10(%rsp), %r14d
movq 0x18(%rsp), %r12
jmp 0x37a20
movq %r12, %r9
jmp 0x37a0f
movl 0x10(%rsp), %r14d
movq 0x18(%rsp), %r12
leaq 0x245295(%rip), %rdi    # 0x27ccb0
movl 0x30(%rsp), %r13d
incl %r15d
addq $0x20, %rbp
cmpl %r13d, %r15d
jne 0x3789a
jmp 0x37b1c
movswl %r12w, %edi
movl %r14d, %esi
movl %ebx, %edx
leaq 0x6c(%rsp), %rcx
leaq 0x8c(%rsp), %r8
callq 0x26766
movl 0x14(%rsp), %eax
movl 0x6c(%rsp), %ecx
movl %ecx, 0x68(%rsp)
cmpl %ecx, %eax
jle 0x37aa1
cmpl 0x8c(%rsp), %eax
jge 0x37aa1
movswq 0x40(%rsp), %rax
movl %eax, %ecx
movl 0x10(%rsp), %r14d
movq 0x8(%rsp), %r9
leaq 0x3f9abe(%rip), %rsi    # 0x431540
leaq 0x245227(%rip), %rdi    # 0x27ccb0
testl %ecx, %ecx
jle 0x37b04
leaq -0x1(%rcx), %rdx
cmpw %r12w, -0x2(%rsi,%rcx,2)
movq %rdx, %rcx
jne 0x37a89
jmp 0x379fe
movq 0xe8(%rsp), %rcx
movzwl 0x2(%rsp), %edx
movw %dx, (%rcx)
movq 0xf0(%rsp), %rcx
movw %r15w, (%rcx)
movq 0xf8(%rsp), %rcx
movw $0xffff, (%rcx)         # imm = 0xFFFF
movq 0x100(%rsp), %rcx
movl %r14d, (%rcx)
movq 0x108(%rsp), %rcx
movl %ebx, (%rcx)
movq 0x110(%rsp), %rcx
movl %eax, (%rcx)
movl 0x10(%rsp), %r14d
movq 0x8(%rsp), %r9
movq 0x18(%rsp), %r12
leaq 0x2451b1(%rip), %rdi    # 0x27ccb0
jmp 0x37a20
leal 0x1(%rax), %ecx
movl %ecx, 0x40(%rsp)
movw %r12w, (%rsi,%rax,2)
jmp 0x379fe
leaq 0x245194(%rip), %rdi    # 0x27ccb0
leaq 0x3749ed(%rip), %rax    # 0x3ac510
movq 0x58(%rsp), %rcx
movzwl (%rax,%rcx,2), %r13d
movl 0xe0(%rsp), %r15d
testw %r13w, %r13w
js 0x3832a
movzwl %r13w, %ebx
imulq $0x2c, %rbx, %rbp
movzwl 0xc(%rbp,%rdi), %r14d
movl 0x88(%rsp), %eax
andl %r14d, %eax
orl 0x180edb(%rip), %eax    # 0x1b8a38
jne 0x37b6d
leaq 0x37e9ba(%rip), %rax    # 0x3b6520
movzwl (%rax,%rbx,2), %r13d
jmp 0x37b35
addq %rdi, %rbp
movl (%rbp), %r11d
movl 0x4(%rbp), %r10d
movl 0x8(%rbp), %esi
movl %r14d, %eax
shrl $0x4, %eax
andl $0x3, %eax
leaq 0x3f3c5(%rip), %rcx     # 0x76f50
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x90(%rsp), %rdi
testl %edi, %edi
sete %cl
subl %r12d, %r11d
movl %r11d, %edx
imull 0x3c(%rsp), %edx
subl %r9d, %r10d
movl %r10d, %eax
imull 0x10(%rsp), %eax
addl %edx, %eax
setle %dl
orb %cl, %dl
jne 0x37e86
movl %eax, %r15d
movq %r15, %rax
imulq 0x50(%rsp), %rax
cqto
idivq %rdi
movq %rax, %rcx
addl 0x4(%rsp), %ecx
movl %ecx, 0x14(%rsp)
movswq 0xe(%rbp), %r9
leaq 0x3c9bf4(%rip), %rax    # 0x4017e0
movswl (%rax,%r9,2), %eax
movzbl 0x15(%rbp), %edi
imull %edi, %eax
movsbl %r14b, %r8d
sarl $0x7, %r8d
leal (%rax,%rax), %edx
andl %r8d, %edx
addl %esi, %edx
leaq 0x202e51(%rip), %r8     # 0x23aa60
movl (%r8,%r9,4), %r8d
testl $0xff0000, %r8d         # imm = 0xFF0000
je 0x37c2d
shrl $0x10, %r8d
movsbl %r8b, %r8d
imull %r8d, %edi
shll $0x2, %edi
subl %edi, %edx
leaq 0x24507c(%rip), %rdi    # 0x27ccb0
cmpl %edx, %ecx
movq 0x48(%rsp), %r14
jg 0x37fe3
shll $0x2, %eax
subl %eax, %edx
cmpl %edx, %ecx
jl 0x37fe3
imull 0x3c(%rsp), %r10d
imull 0x10(%rsp), %r11d
subl %r11d, %r10d
movslq %r10d, %rdi
movq %rdi, %rax
imulq %r14, %rax
cqto
movq 0x90(%rsp), %r11
idivq %r11
movq %rax, %r8
movq 0x70(%rsp), %r10
imulq %r10, %rdi
movq %rdi, %rax
cqto
idivq %r11
imull %r8d, %r8d
imull %eax, %eax
addl %r8d, %eax
leaq 0x3d8387(%rip), %rdx    # 0x410020
movswl (%rdx,%r9,2), %edx
movzbl 0x14(%rbp), %edi
imull %edx, %edi
imull %edi, %edi
shrl $0x7, %edi
cmpl %edi, %eax
jbe 0x38116
movq 0x8(%rsp), %r9
leaq 0x244ff1(%rip), %rdi    # 0x27ccb0
jmp 0x37fe8
movl %esi, 0x24(%rsp)
movq %rbx, 0x30(%rsp)
movq %r10, 0x58(%rsp)
movq %r11, %r10
movq %r12, %r11
movswq 0xe(%rbp), %r12
leaq 0x202d7c(%rip), %rax    # 0x23aa60
movl (%rax,%r12,4), %eax
movl %eax, 0x78(%rsp)
shrl $0x8, %eax
movsbl %al, %eax
movsbl 0x16(%rbp), %ecx
addl %eax, %ecx
movl %ecx, %edx
negl %edx
testb $0x4, %r14b
cmovel %ecx, %edx
movzwl 0x1c(%rbp), %ecx
movzbl 0x14(%rbp), %esi
movl %ecx, %eax
movl $0x7ff, %r8d            # imm = 0x7FF
andl %r8d, %eax
leaq 0x397033(%rip), %rbx    # 0x3ced50
movswq (%rbx,%rax,2), %rax
imulq %rsi, %rax
addl $0x600, %ecx            # imm = 0x600
andl %r8d, %ecx
movswq (%rbx,%rcx,2), %r15
imulq %rsi, %r15
leaq 0x3d82e1(%rip), %rcx    # 0x410020
movq %r12, 0xa0(%rsp)
movswq (%rcx,%r12,2), %rcx
movq %r11, %r12
movq %r10, %r11
movq 0x58(%rsp), %r10
movl %ecx, %esi
sarl %esi
addl %edx, %esi
movslq %esi, %rdx
movq %rdx, %rsi
imulq %rax, %rsi
shrq $0x10, %rsi
subl %esi, %r11d
imulq %rcx, %rax
shrq $0x10, %rax
addl %r11d, %eax
imulq %r15, %rdx
shrq $0x10, %rdx
subl %edx, %r10d
imulq %rcx, %r15
shrq $0x10, %r15
addl %r10d, %r15d
testb $0x40, %r14b
je 0x37e92
movl %r11d, %ecx
subl %r12d, %ecx
movl %r15d, %edx
subl %r9d, %edx
imull %ecx, %edx
movl %eax, %ecx
subl %r12d, %ecx
movl %r10d, %esi
subl %r9d, %esi
imull %ecx, %esi
cmpl %esi, %edx
jge 0x37e92
movl 0xe0(%rsp), %r15d
jmp 0x37fd9
testl %r15d, %r15d
je 0x37b5f
movl %esi, 0x14(%rsp)
movl %esi, %eax
subl 0x4(%rsp), %eax
movl %eax, %ecx
xorl %r15d, %ecx
js 0x37b5f
testb $0x40, %r14b
je 0x37e05
cmpl 0x4(%rsp), %esi
setl %cl
testb $0x8, %r14b
sete %dl
cmpb %cl, %dl
je 0x37b5f
movl %esi, 0x24(%rsp)
movslq %eax, %rcx
movq %rcx, %rax
imulq 0x48(%rsp), %rax
cqto
movq 0x50(%rsp), %rdi
idivq %rdi
movq %rax, %rsi
addl %r12d, %eax
movl %eax, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
imulq 0x70(%rsp), %rcx
movq %rcx, %rax
cqto
idivq %rdi
leal (%rax,%r9), %r8d
movl %esi, %ecx
negl %ecx
cmovsl %esi, %ecx
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
movl %r8d, 0x28(%rsp)
addl %ecx, %esi
movq 0x100(%rsp), %rax
movl (%rax), %eax
subl %r12d, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movq 0x108(%rsp), %rax
movl (%rax), %eax
subl %r9d, %eax
movl %eax, %edi
negl %edi
cmovsl %eax, %edi
addl %ecx, %edi
cmpl %edi, %esi
jbe 0x37ff5
leaq 0x244e23(%rip), %rdi    # 0x27ccb0
jmp 0x37b5f
subq $0x8, %rsp
movl %r12d, %edi
movl %r9d, %esi
movl 0xc(%rsp), %edx
movl 0x44(%rsp), %ecx
movl 0x18(%rsp), %r8d
movq %r9, %r12
movl 0xe8(%rsp), %r9d
leaq 0x1c(%rsp), %rbx
pushq %rbx
leaq 0x38(%rsp), %rbx
pushq %rbx
leaq 0x44(%rsp), %rbx
pushq %rbx
pushq %r15
pushq %rax
pushq %r10
pushq %r11
callq 0x3838a
addq $0x40, %rsp
testl %eax, %eax
je 0x37fc2
movl 0x2c(%rsp), %r8d
movl %r8d, %eax
movq 0x18(%rsp), %r10
subl %r10d, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl 0x28(%rsp), %edx
movl %edx, %eax
subl %r12d, %eax
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
addl %ecx, %esi
movq 0x100(%rsp), %rax
movl (%rax), %eax
subl %r10d, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movq 0x108(%rsp), %rax
movl (%rax), %eax
subl %r12d, %eax
movl %eax, %edi
negl %edi
cmovsl %eax, %edi
addl %ecx, %edi
cmpl %edi, %esi
movq %r12, %r9
movq %r10, %r12
movl 0xe0(%rsp), %r15d
leaq 0x244d68(%rip), %rdi    # 0x27ccb0
movq 0x30(%rsp), %rbx
ja 0x37b5f
leaq 0x3c9886(%rip), %rax    # 0x4017e0
movq 0xa0(%rsp), %rcx
movswl (%rax,%rcx,2), %eax
movzbl 0x15(%rbp), %ecx
imull %ecx, %eax
movsbl %r14b, %esi
sarl $0x7, %esi
leal (%rax,%rax), %r10d
andl %esi, %r10d
addl 0x24(%rsp), %r10d
movl 0x78(%rsp), %esi
testl $0xff0000, %esi         # imm = 0xFF0000
je 0x37f9b
shll $0x8, %esi
sarl $0x16, %esi
andl $-0x4, %esi
imull %ecx, %esi
subl %esi, %r10d
movl 0x14(%rsp), %ecx
cmpl %r10d, %ecx
movl %r10d, 0x68(%rsp)
jge 0x37b5f
shll $0x2, %eax
movl %r10d, %esi
subl %eax, %esi
cmpl %esi, %ecx
jg 0x382dd
jmp 0x37b5f
movq %r12, %r9
movq 0x18(%rsp), %r12
movl 0xe0(%rsp), %r15d
leaq 0x244cd7(%rip), %rdi    # 0x27ccb0
movq 0x30(%rsp), %rbx
jmp 0x37b5f
movq 0x8(%rsp), %r9
movl 0xe0(%rsp), %r15d
jmp 0x37b5f
movswq 0xe(%rbp), %rax
leaq 0x202a5f(%rip), %rcx    # 0x23aa60
movl (%rcx,%rax,4), %ecx
movl %ecx, %esi
shrl $0x8, %esi
movsbl %sil, %esi
movsbl 0x16(%rbp), %edi
addl %esi, %edi
shrl $0x10, %ecx
movsbl %cl, %ecx
movsbl 0x17(%rbp), %esi
addl %ecx, %esi
movl %edi, %r15d
negl %r15d
testb $0x4, %r14b
cmovel %edi, %r15d
movl %esi, %ecx
negl %ecx
testb $0x8, %r14b
cmovel %esi, %ecx
movswq 0x1c(%rbp), %rdi
leal 0x200(%rdi), %esi
andl $0x7ff, %esi            # imm = 0x7FF
leaq 0x396d00(%rip), %r9     # 0x3ced50
movswq (%r9,%rsi,2), %rsi
movswq (%r9,%rdi,2), %rdx
movq %rdx, 0x78(%rsp)
leaq 0x3d7fba(%rip), %rdi    # 0x410020
movswq (%rdi,%rax,2), %rdx
movzbl 0x14(%rbp), %r9d
leaq 0x3c9769(%rip), %rdi    # 0x4017e0
movl %r8d, %r14d
movswq (%rdi,%rax,2), %r8
movzbl 0x15(%rbp), %edi
movl %edx, %eax
movq %rdx, %r12
sarl %eax
addl %r15d, %eax
movslq %eax, %r15
imulq %r9, %r15
movq %r8, 0x58(%rsp)
movl %r8d, %eax
movl 0x30(%rsp), %r8d
movl %r14d, %edx
movq 0x78(%rsp), %r14
sarl %eax
addl %ecx, %eax
cltq
imulq %rdi, %rax
movq %r15, %rbp
imulq %r14, %rbp
movq %rax, %rcx
imulq %rsi, %rcx
addq %rbp, %rcx
shrq $0x10, %rcx
subl %r8d, %ecx
addl %r11d, %ecx
imulq %r14, %rax
imulq %rsi, %r15
subq %r15, %rax
shrq $0x10, %rax
subl %edx, %eax
addl %r10d, %eax
imulq %r12, %r9
movq %r9, %r11
imulq %r14, %r11
shrq $0x10, %r11
movl %ecx, %r10d
subl %r11d, %r10d
imulq %rsi, %r9
shrq $0x10, %r9
leal (%rax,%r9), %r11d
movl %r11d, %ebp
xorl %eax, %ebp
js 0x381a5
xorl %r9d, %r9d
jmp 0x381d2
movq %r15, %rax
imulq %r14, %rax
cqto
idivq %r11
movq %rax, %rdi
leal (%rax,%r12), %r8d
movl %r8d, 0x2c(%rsp)
imulq %r10, %r15
movq %r15, %rax
cqto
idivq %r11
movq 0x8(%rsp), %r10
leal (%rax,%r10), %edx
movl %edi, %esi
negl %esi
cmovsl %edi, %esi
movl %eax, %edi
negl %edi
cmovsl %eax, %edi
movl %edx, 0x28(%rsp)
addl %esi, %edi
movq 0x100(%rsp), %rax
movl (%rax), %eax
subl %r12d, %eax
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
movq 0x108(%rsp), %rax
movl (%rax), %eax
subl %r10d, %eax
movl %eax, %r9d
negl %r9d
cmovsl %eax, %r9d
addl %esi, %r9d
cmpl %r9d, %edi
movq %r10, %r9
leaq 0x244b1e(%rip), %rdi    # 0x27ccb0
movl 0xe0(%rsp), %r15d
ja 0x37b5f
jmp 0x382dd
movl %r10d, %ebp
xorl %ecx, %ebp
js 0x381b4
testl %ecx, %ecx
setns %r9b
jmp 0x381d2
movl %r11d, %ebp
imull %ecx, %ebp
movl %r10d, %r15d
imull %eax, %r15d
cmpl %r15d, %ebp
setl %bpl
testl %r9d, %r9d
setg %r9b
xorb %bpl, %r9b
movq 0x18(%rsp), %r12
imulq 0x58(%rsp), %rdi
imulq %rdi, %rsi
shrq $0x10, %rsi
movl %r10d, %ebp
subl %esi, %ebp
imulq %r14, %rdi
shrq $0x10, %rdi
movl %r11d, %r14d
subl %edi, %r14d
movl %r14d, %r15d
xorl %r11d, %r15d
jns 0x38239
movl %ebp, %r15d
xorl %r10d, %r15d
js 0x38217
testl %r10d, %r10d
setns %r10b
xorb %r9b, %r10b
movl %r10d, %r9d
jmp 0x38239
imull %r14d, %r10d
movl %ebp, %r15d
imull %r11d, %r15d
cmpl %r15d, %r10d
setl %r10b
cmpl %r14d, %r11d
setl %r11b
xorb %r9b, %r11b
xorb %r10b, %r11b
movl %r11d, %r9d
movl %ecx, %r10d
subl %esi, %r10d
movl %eax, %esi
subl %edi, %esi
movl %r14d, %edi
xorl %esi, %edi
movl 0xe0(%rsp), %r15d
jns 0x38287
movl %ebp, %edi
xorl %r10d, %edi
js 0x38267
testl %ebp, %ebp
setns %dil
xorb %r9b, %dil
movl %edi, %r9d
jmp 0x38287
imull %esi, %ebp
movl %r14d, %edi
imull %r10d, %edi
cmpl %edi, %ebp
setl %dil
cmpl %esi, %r14d
setl %r11b
xorb %r9b, %r11b
xorb %dil, %r11b
movl %r11d, %r9d
movl %esi, %edi
xorl %eax, %edi
js 0x38298
movl 0x24(%rsp), %eax
movl %eax, %ecx
testb %r9b, %r9b
jmp 0x382cb
movl %r10d, %edi
xorl %ecx, %edi
js 0x382b0
testl %r10d, %r10d
setns %al
xorb %r9b, %al
movl 0x24(%rsp), %eax
movl %eax, %ecx
jmp 0x382cb
imull %eax, %r10d
imull %esi, %ecx
cmpl %ecx, %r10d
setl %cl
cmpl %eax, %esi
setl %al
xorb %cl, %al
movl 0x24(%rsp), %ecx
cmpb %r9b, %al
movq 0x8(%rsp), %r9
leaq 0x2449d9(%rip), %rdi    # 0x27ccb0
je 0x37b5f
movq 0xe8(%rsp), %rax
movzwl 0x2(%rsp), %esi
movw %si, (%rax)
movq 0xf0(%rsp), %rax
movw $0xffff, (%rax)         # imm = 0xFFFF
movq 0xf8(%rsp), %rax
movw %r13w, (%rax)
movq 0x100(%rsp), %rax
movl %r8d, (%rax)
movq 0x108(%rsp), %rax
movl %edx, (%rax)
movq 0x110(%rsp), %rax
movl %ecx, (%rax)
jmp 0x37b5f
movl 0x68(%rsp), %eax
movl %eax, 0x6c(%rsp)
movl 0x44(%rsp), %r10d
incl %r10d
movq 0x70(%rsp), %rbp
leaq 0x3f91fa(%rip), %r11    # 0x431540
cmpw 0x40(%rsp), %r10w
jl 0x3737f
jmp 0x3836f
movq 0x8(%rsp), %r9
jmp 0x38346
movq 0x8(%rsp), %r9
movl 0xe0(%rsp), %r15d
movl 0x44(%rsp), %r10d
jmp 0x3833f
xorl %eax, %eax
jmp 0x38378
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq