// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: pushmove
int pushmove (int *x, int *y, int *z, short *sectnum,
		 int walldist, int ceildist, int flordist, unsigned int cliptype)
{
	sectortype *sec, *sec2;
	walltype *wal;
	int i, j, k, t, dx, dy, dax, day, daz, daz2, bad, dir;
	int dawalclipmask;
	short startwall, endwall, clipsectcnt;
	char bad2;

	if ((*sectnum) < 0) return(-1);

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

	k = 32;
	dir = 1;
	do
	{
		bad = 0;

		clipsectorlist[0] = *sectnum;
		clipsectcnt = 0; clipsectnum = 1;
		do
		{
			/*Push FACE sprites
			for(i=headspritesect[clipsectorlist[clipsectcnt]];i>=0;i=nextspritesect[i])
			{
				spritetype *spr = &sprite[i];
				if (((spr->cstat&48) != 0) && ((spr->cstat&48) != 48)) continue;
				if ((spr->cstat&dasprclipmask) == 0) continue;

				dax = (*x)-spr->x; day = (*y)-spr->y;
				t = (spr->clipdist<<2)+walldist;
				if ((klabs(dax) < t) && (klabs(day) < t))
				{
					t = ((tilesizy[spr->picnum]*spr->yrepeat)<<2);
					if (spr->cstat&128) daz = spr->z+(t>>1); else daz = spr->z;
					if (picanm[spr->picnum]&0x00ff0000) daz -= ((int)((signed char)((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2);
					if (((*z) < daz+ceildist) && ((*z) > daz-t-flordist))
					{
						t = (spr->clipdist<<2)+walldist;

						j = getangle(dax,day);
						dx = (sintable[(j+512)&2047]>>11);
						dy = (sintable[(j)&2047]>>11);
						bad2 = 16;
						do
						{
							*x = (*x) + dx; *y = (*y) + dy;
							bad2--; if (bad2 == 0) break;
						} while ((klabs((*x)-spr->x) < t) && (klabs((*y)-spr->y) < t));
						bad = -1;
						k--; if (k <= 0) return(bad);
						updatesector(*x,*y,sectnum);
					}
				}
			}*/

			sec = &sector[clipsectorlist[clipsectcnt]];
			if (dir > 0)
				startwall = sec->wallptr, endwall = startwall + sec->wallnum;
			else
				endwall = sec->wallptr, startwall = endwall + sec->wallnum;

			for(i=startwall,wal=&wall[startwall];i!=endwall;i+=dir,wal+=dir)
				if (clipinsidebox(*x,*y,i,walldist-4) == 1)
				{
					j = 0;
					if (wal->nextsector < 0) j = 1;
					if (wal->cstat&dawalclipmask) j = 1;
					if (j == 0)
					{
						sec2 = &sector[wal->nextsector];


							//Find closest point on wall (dax, day) to (*x, *y)
						dax = wall[wal->point2].x-wal->x;
						day = wall[wal->point2].y-wal->y;
						daz = dax*((*x)-wal->x) + day*((*y)-wal->y);
						if (daz <= 0)
							t = 0;
						else
						{
							daz2 = dax*dax+day*day;
							if (daz >= daz2) t = (1<<30); else t = divscale30(daz,daz2);
						}
						dax = wal->x + mulscale30(dax,t);
						day = wal->y + mulscale30(day,t);


						daz = getflorzofslope(clipsectorlist[clipsectcnt],dax,day);
						daz2 = getflorzofslope(wal->nextsector,dax,day);
						if ((daz2 < daz-(1<<8)) && ((sec2->floorstat&1) == 0))
							if (*z >= daz2-(flordist-1)) j = 1;

						daz = getceilzofslope(clipsectorlist[clipsectcnt],dax,day);
						daz2 = getceilzofslope(wal->nextsector,dax,day);
						if ((daz2 > daz+(1<<8)) && ((sec2->ceilingstat&1) == 0))
							if (*z <= daz2+(ceildist-1)) j = 1;
					}
					if (j != 0)
					{
						j = getangle(wall[wal->point2].x-wal->x,wall[wal->point2].y-wal->y);
						dx = (sintable[(j+1024)&2047]>>11);
						dy = (sintable[(j+512)&2047]>>11);
						bad2 = 16;
						do
						{
							*x = (*x) + dx; *y = (*y) + dy;
							bad2--; if (bad2 == 0) break;
						} while (clipinsidebox(*x,*y,i,walldist-4) != 0);
						bad = -1;
						k--; if (k <= 0) return(bad);
						updatesector(*x,*y,sectnum);
					}
					else
					{
						for(j=clipsectnum-1;j>=0;j--)
							if (wal->nextsector == clipsectorlist[j]) break;
						if (j < 0) clipsectorlist[clipsectnum++] = wal->nextsector;
					}
				}

			clipsectcnt++;
		} while (clipsectcnt < clipsectnum);
		dir = -dir;
	} while (bad != 0);

	return(bad);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, 0x48(%rsp)
movq %rsi, 0x68(%rsp)
movq %rcx, 0x50(%rsp)
cmpw $0x0, (%rcx)
js 0x39d96
movl %r8d, %r14d
movq %rdi, %r13
addl $-0x4, %r14d
decl %r9d
movl %r9d, 0x3c(%rsp)
movl $0x1, %r15d
movl $0x20, 0x2c(%rsp)
movl %r14d, 0x8(%rsp)
movq 0x50(%rsp), %rax
movzwl (%rax), %eax
movw %ax, 0x3f6b67(%rip)     # 0x430540
movslq %r15d, %rax
xorl %ecx, %ecx
movw $0x1, %dx
movl %edx, 0xc(%rsp)
shlq $0x5, %rax
movq %rax, 0x70(%rsp)
movl $0x0, 0x24(%rsp)
movl %r15d, 0x10(%rsp)
leaq 0x3f6b3d(%rip), %rax    # 0x430540
movq %rcx, 0x58(%rsp)
movswq (%rax,%rcx,2), %rax
leaq (%rax,%rax,4), %rax
leaq 0x209048(%rip), %rcx    # 0x242a60
movzwl 0x2(%rcx,%rax,8), %esi
movl (%rcx,%rax,8), %ecx
leal (%rsi,%rcx), %eax
testl %r15d, %r15d
movl %ecx, %edx
cmovgl %eax, %edx
testw %si, %si
je 0x39d6d
movswl %dx, %edx
movl %edx, 0x44(%rsp)
testl %r15d, %r15d
cmovgl %ecx, %eax
movswq %ax, %rdx
shlq $0x5, %rdx
leaq 0x17e000(%rip), %rcx    # 0x1b7a50
addq %rcx, %rdx
movq %rdx, 0x18(%rsp)
movswl %ax, %edi
movl 0xc(%rsp), %eax
movq %rax, 0x30(%rsp)
movl (%r13), %r12d
movq 0x68(%rsp), %rax
movl (%rax), %ebp
movl %edi, 0x14(%rsp)
movswl %di, %ebx
movl %r12d, %edi
movl %ebp, %esi
movl %ebx, %edx
movl %r14d, %ecx
callq 0x353fd
cmpl $0x1, %eax
jne 0x39cec
movq 0x18(%rsp), %rax
movzwl 0xc(%rax), %r8d
movzwl 0xe(%rax), %eax
testl %eax, 0xb8(%rsp)
sete %al
testw %r8w, %r8w
setns %cl
andb %al, %cl
movl $0x1, %edx
cmpb $0x1, %cl
jne 0x39c31
movq 0x18(%rsp), %rdx
movswq 0x8(%rdx), %rax
shlq $0x5, %rax
leaq 0x17df7e(%rip), %rcx    # 0x1b7a50
movslq (%rax,%rcx), %r15
movslq (%rdx), %rsi
subq %rsi, %r15
movslq 0x4(%rax,%rcx), %r14
movslq 0x4(%rdx), %rcx
subq %rcx, %r14
subl %esi, %r12d
imull %r15d, %r12d
subl %ecx, %ebp
imull %r14d, %ebp
addl %r12d, %ebp
jle 0x39b24
movl %r15d, %eax
imull %r15d, %eax
movl %r14d, %edx
imull %r14d, %edx
addl %eax, %edx
movl $0x40000000, %eax       # imm = 0x40000000
cmpl %edx, %ebp
jge 0x39b26
movl %ebp, %eax
shlq $0x1e, %rax
movl %edx, %edi
xorl %edx, %edx
divq %rdi
cltq
jmp 0x39b26
xorl %eax, %eax
movzwl %r8w, %edx
leaq (%rdx,%rdx,4), %rdx
leaq 0x208f2b(%rip), %rdi    # 0x242a60
leaq (%rdi,%rdx,8), %rdx
movq %rdx, 0x60(%rsp)
imulq %rax, %r15
shrq $0x1e, %r15
addl %esi, %r15d
imulq %rax, %r14
shrq $0x1e, %r14
addl %ecx, %r14d
leaq 0x3f69e5(%rip), %rax    # 0x430540
movq 0x58(%rsp), %rcx
movswl (%rax,%rcx,2), %edi
movl %edi, 0x40(%rsp)
movl %r15d, %esi
movl %r14d, %edx
movl %r8d, %r12d
callq 0x397ca
movl %eax, %ebp
movw %r12w, 0x6(%rsp)
movswl %r12w, %r12d
movl %r12d, %edi
movl %r15d, %esi
movl %r14d, %edx
callq 0x397ca
addl $0xffffff00, %ebp       # imm = 0xFFFFFF00
xorl %edx, %edx
cmpl %ebp, %eax
jge 0x39bbc
movq 0x60(%rsp), %rcx
testb $0x1, 0xe(%rcx)
jne 0x39bbc
subl 0xb0(%rsp), %eax
incl %eax
xorl %edx, %edx
movq 0x48(%rsp), %rcx
cmpl %eax, (%rcx)
setge %dl
movl %edx, 0x28(%rsp)
movl 0x40(%rsp), %edi
movl %r15d, %esi
movl %r14d, %edx
callq 0x398a4
movl %eax, %ebp
movl %r12d, %edi
movl %r15d, %esi
movl %r14d, %edx
callq 0x398a4
addl $0x100, %ebp            # imm = 0x100
cmpl %ebp, %eax
jle 0x39c1d
movq 0x60(%rsp), %rcx
testb $0x1, 0xc(%rcx)
movl 0x8(%rsp), %r14d
movl 0x10(%rsp), %r15d
movzwl 0x6(%rsp), %r8d
movl 0x28(%rsp), %edx
jne 0x39c31
addl 0x3c(%rsp), %eax
movq 0x48(%rsp), %rcx
cmpl %eax, (%rcx)
movl $0x1, %eax
cmovlel %eax, %edx
jmp 0x39c31
movl 0x8(%rsp), %r14d
movl 0x10(%rsp), %r15d
movzwl 0x6(%rsp), %r8d
movl 0x28(%rsp), %edx
testl %edx, %edx
je 0x39d0e
movq 0x18(%rsp), %rdx
movswq 0x8(%rdx), %rax
shlq $0x5, %rax
leaq 0x17de02(%rip), %rcx    # 0x1b7a50
movl (%rax,%rcx), %edi
movl 0x4(%rax,%rcx), %esi
subl (%rdx), %edi
subl 0x4(%rdx), %esi
callq 0x35643
movl %eax, %ecx
xorl $0x400, %ecx            # imm = 0x400
leaq 0x3940e2(%rip), %rdx    # 0x3cdd50
movswl (%rdx,%rcx,2), %r14d
sarl $0xb, %r14d
addl $0x200, %eax            # imm = 0x200
andl $0x7ff, %eax            # imm = 0x7FF
movswl (%rdx,%rax,2), %r15d
sarl $0xb, %r15d
movb $-0x10, %r12b
addl %r14d, (%r13)
movq 0x68(%rsp), %rax
movl (%rax), %ebp
addl %r15d, %ebp
movl %ebp, (%rax)
incb %r12b
je 0x39cb7
movl (%r13), %edi
movl %ebp, %esi
movl %ebx, %edx
movl 0x8(%rsp), %ecx
callq 0x353fd
testl %eax, %eax
jne 0x39c8d
movl 0x2c(%rsp), %eax
cmpl $0x2, %eax
jl 0x39d96
decl %eax
movl %eax, 0x2c(%rsp)
movl (%r13), %edi
movl %ebp, %esi
movq 0x50(%rsp), %rdx
callq 0x25f34
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
movl 0x8(%rsp), %r14d
movl 0x10(%rsp), %r15d
movl 0x14(%rsp), %edi
addl %r15d, %edi
movq 0x18(%rsp), %rax
addq 0x70(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpl 0x44(%rsp), %edi
jne 0x39a64
jmp 0x39d6d
movswl 0x30(%rsp), %ecx
movl %ecx, %eax
sarl $0x1f, %eax
andl %ecx, %eax
leaq 0x3f681f(%rip), %rdx    # 0x430540
leaq (%rdx,%rcx,2), %rdx
addq $-0x2, %rdx
movl 0x14(%rsp), %edi
testl %ecx, %ecx
jle 0x39d44
decl %ecx
leaq -0x2(%rdx), %rsi
cmpw (%rdx), %r8w
movq %rsi, %rdx
jne 0x39d2d
incl %ecx
movl %ecx, %eax
testl %eax, %eax
jg 0x39cf0
movq 0x30(%rsp), %rax
leal 0x1(%rax), %edx
movswq %ax, %rax
leaq 0x3f67e5(%rip), %rcx    # 0x430540
movw %r8w, (%rcx,%rax,2)
movl %edx, 0xc(%rsp)
movl %edx, %eax
movq %rax, 0x30(%rsp)
jmp 0x39cf0
movq 0x58(%rsp), %rcx
incq %rcx
movswq 0xc(%rsp), %rax
cmpq %rax, %rcx
jl 0x399fc
negl %r15d
xorl %eax, %eax
cmpl $0x0, 0x24(%rsp)
jne 0x399ca
jmp 0x39d9b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq