// File: /workspace/github_c_makefile_star2_O3/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 $0x88, %rsp
movq %rdx, 0x48(%rsp)
movq %rsi, 0x78(%rsp)
movq %rcx, 0x58(%rsp)
cmpw $0x0, (%rcx)
js 0x3b0ab
movl %r8d, %r13d
addl $-0x4, %r13d
decl %r9d
movl %r9d, 0x30(%rsp)
movl $0x1, %ebx
movl $0x20, 0x24(%rsp)
leaq 0x3f684b(%rip), %r12    # 0x431540
movq %rdi, 0x18(%rsp)
movl %r13d, 0x14(%rsp)
movq 0x58(%rsp), %rax
movzwl (%rax), %eax
movw %ax, 0x3f6832(%rip)     # 0x431540
movslq %ebx, %rbp
xorl %ecx, %ecx
movw $0x1, %ax
movl %eax, 0xc(%rsp)
shlq $0x5, %rbp
movl $0x0, 0x20(%rsp)
movq %rbp, 0x70(%rsp)
movl %ebx, 0x10(%rsp)
movq %rcx, 0x50(%rsp)
movswq (%r12,%rcx,2), %rax
leaq (%rax,%rax,4), %rax
leaq 0x208d1b(%rip), %rcx    # 0x243a60
movzwl 0x2(%rcx,%rax,8), %esi
movl (%rcx,%rax,8), %ecx
leal (%rsi,%rcx), %eax
testl %ebx, %ebx
movl %ecx, %edx
cmovgl %eax, %edx
testw %si, %si
je 0x3b083
movswl %dx, %edx
movl %edx, 0x3c(%rsp)
testl %ebx, %ebx
cmovgl %ecx, %eax
movswq %ax, %rsi
shlq $0x5, %rsi
leaq 0x17dcd5(%rip), %rcx    # 0x1b8a50
addq %rcx, %rsi
movswl %ax, %ecx
movq %rsi, 0x28(%rsp)
movl (%rdi), %r15d
movq 0x78(%rsp), %rax
movl (%rax), %r14d
movl %ecx, 0x40(%rsp)
movswl %cx, %edx
movl %r15d, %edi
movl %r14d, %esi
movl %edx, 0x44(%rsp)
movl %r13d, %ecx
callq 0x3664d
cmpl $0x1, %eax
jne 0x3ae3b
movq 0x28(%rsp), %rdx
movzwl 0xc(%rdx), %r8d
movzwl 0xe(%rdx), %eax
testl %eax, 0xc8(%rsp)
sete %al
testw %r8w, %r8w
setns %cl
testb %cl, %al
je 0x3ae45
movswq 0x8(%rdx), %rax
shlq $0x5, %rax
leaq 0x17dc6a(%rip), %rcx    # 0x1b8a50
movslq (%rax,%rcx), %r9
movslq (%rdx), %rsi
subq %rsi, %r9
movslq 0x4(%rax,%rcx), %rbp
movslq 0x4(%rdx), %rcx
subq %rcx, %rbp
movl %r15d, %eax
subl %esi, %eax
imull %r9d, %eax
subl %ecx, %r14d
imull %ebp, %r14d
addl %eax, %r14d
jle 0x3ae66
movl %r9d, %eax
imull %r9d, %eax
movl %ebp, %edx
imull %ebp, %edx
addl %eax, %edx
movl $0x40000000, %eax       # imm = 0x40000000
cmpl %edx, %r14d
jge 0x3ae68
movl %r14d, %eax
shlq $0x1e, %rax
movl %edx, %edi
xorl %edx, %edx
divq %rdi
cltq
jmp 0x3ae68
movq 0x18(%rsp), %rdi
jmp 0x3b052
movswq 0x8(%rdx), %rax
shlq $0x5, %rax
leaq 0x17dbfb(%rip), %rcx    # 0x1b8a50
movl (%rax,%rcx), %edi
movl 0x4(%rax,%rcx), %esi
subl (%rdx), %edi
subl 0x4(%rdx), %esi
jmp 0x3af9d
xorl %eax, %eax
movzwl %r8w, %edx
leaq (%rdx,%rdx,4), %rdx
leaq 0x208be9(%rip), %rdi    # 0x243a60
leaq (%rdi,%rdx,8), %rbx
movq %r9, 0x68(%rsp)
movq %r9, %r14
imulq %rax, %r14
shrq $0x1e, %r14
addl %esi, %r14d
movq %rbp, 0x60(%rsp)
imulq %rax, %rbp
shrq $0x1e, %rbp
addl %ecx, %ebp
movq 0x50(%rsp), %rax
movswl (%r12,%rax,2), %edi
movl %edi, 0x38(%rsp)
movl %r14d, %esi
movl %ebp, %edx
movl %r8d, %r12d
callq 0x3aaf4
movl %eax, %r13d
movw %r12w, 0xa(%rsp)
movswl %r12w, %edi
movl %edi, 0x34(%rsp)
movl %r14d, %esi
movl %ebp, %edx
callq 0x3aaf4
addl $0xffffff00, %r13d      # imm = 0xFFFFFF00
movb $0x1, %cl
cmpl %r13d, %eax
movq %rbx, 0x80(%rsp)
jge 0x3af02
testb $0x1, 0xe(%rbx)
jne 0x3af02
subl 0xc0(%rsp), %eax
incl %eax
movq 0x48(%rsp), %rcx
cmpl %eax, (%rcx)
setl %cl
movl %ecx, %ebx
movl 0x38(%rsp), %edi
movl %r14d, %esi
movl %ebp, %edx
callq 0x3abce
movl %eax, %r12d
movl 0x34(%rsp), %edi
movl %r14d, %esi
movl %ebp, %edx
callq 0x3abce
addl $0x100, %r12d           # imm = 0x100
cmpl %r12d, %eax
jle 0x3af4f
movq 0x80(%rsp), %rcx
testb $0x1, 0xc(%rcx)
jne 0x3af4f
addl 0x30(%rsp), %eax
movq 0x48(%rsp), %rcx
cmpl %eax, (%rcx)
setg %al
testb %bl, %al
jmp 0x3af51
testb %bl, %bl
movzwl 0xa(%rsp), %r13d
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
je 0x3af9d
movswq 0xc(%rsp), %rax
movl %eax, %ecx
movq 0x18(%rsp), %rdi
leaq 0x3f65c9(%rip), %r12    # 0x431540
movq 0x70(%rsp), %rbp
movq 0x28(%rsp), %rsi
testl %ecx, %ecx
jle 0x3b06c
leaq -0x1(%rcx), %rdx
cmpw -0x2(%r12,%rcx,2), %r13w
movq %rdx, %rcx
jne 0x3af81
jmp 0x3b078
movl 0x14(%rsp), %ebx
callq 0x36893
movl %eax, %ecx
xorl $0x400, %ecx            # imm = 0x400
leaq 0x393d9b(%rip), %rdx    # 0x3ced50
movswl (%rdx,%rcx,2), %r14d
sarl $0xb, %r14d
addl $0x200, %eax            # imm = 0x200
andl $0x7ff, %eax            # imm = 0x7FF
movswl (%rdx,%rax,2), %r12d
sarl $0xb, %r12d
movb $-0x10, %r13b
movq 0x18(%rsp), %rcx
addl %r14d, %r15d
movl %r15d, (%rcx)
movq 0x78(%rsp), %rax
movl (%rax), %ebp
addl %r12d, %ebp
movl %ebp, (%rax)
incb %r13b
je 0x3b00c
movl (%rcx), %r15d
movl %r15d, %edi
movl %ebp, %esi
movl 0x44(%rsp), %edx
movl %ebx, %ecx
callq 0x3664d
movq 0x18(%rsp), %rcx
testl %eax, %eax
jne 0x3afd9
movl 0x24(%rsp), %eax
cmpl $0x2, %eax
leaq 0x3f6526(%rip), %r12    # 0x431540
jl 0x3b0ab
decl %eax
movl %eax, 0x24(%rsp)
movq 0x18(%rsp), %rax
movl (%rax), %edi
movl %ebp, %esi
movq 0x58(%rsp), %rdx
callq 0x2668d
movq 0x18(%rsp), %rdi
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
movl %ebx, %r13d
movl 0x10(%rsp), %ebx
movq 0x70(%rsp), %rbp
movq 0x28(%rsp), %rsi
movl 0x40(%rsp), %ecx
addl %ebx, %ecx
addq %rbp, %rsi
cmpl 0x3c(%rsp), %ecx
jne 0x3ad81
jmp 0x3b083
leal 0x1(%rax), %ecx
movl %ecx, 0xc(%rsp)
movw %r13w, (%r12,%rax,2)
movl 0x14(%rsp), %r13d
movl 0x10(%rsp), %ebx
jmp 0x3b057
movq 0x50(%rsp), %rcx
incq %rcx
movswq 0xc(%rsp), %rax
cmpq %rax, %rcx
jl 0x3ad30
negl %ebx
xorl %eax, %eax
cmpl $0x0, 0x20(%rsp)
jne 0x3acff
jmp 0x3b0b0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq