// File: /workspace/github_c_makefile_star2_O2/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, 0x50(%rsp)
movq %rsi, 0x80(%rsp)
movq %rcx, 0x60(%rsp)
cmpw $0x0, (%rcx)
js 0x37679
movl %r8d, %r12d
addl $-0x4, %r12d
decl %r9d
movl %r9d, 0x3c(%rsp)
pushq $0x1
popq %rbx
pushq $0x20
popq %rax
movl %eax, 0x2c(%rsp)
leaq 0x3f3266(%rip), %r13    # 0x42a540
movq %rdi, 0x18(%rsp)
movl %r12d, 0x24(%rsp)
movq 0x60(%rsp), %rax
movzwl (%rax), %eax
movw %ax, 0x3f324d(%rip)     # 0x42a540
movslq %ebx, %rbp
xorl %ecx, %ecx
movw $0x1, %ax
movl %eax, 0xc(%rsp)
shlq $0x5, %rbp
movl $0x0, 0x28(%rsp)
movq %rbp, 0x78(%rsp)
movl %ebx, 0x10(%rsp)
movq %rcx, 0x58(%rsp)
movswq (%r13,%rcx,2), %rax
imulq $0x28, %rax, %rax
leaq 0x205735(%rip), %rdx    # 0x23ca60
movl (%rax,%rdx), %ecx
movzwl 0x2(%rax,%rdx), %eax
addw %cx, %ax
testl %ebx, %ebx
movl %eax, %edx
cmovgl %ecx, %edx
cmovgl %eax, %ecx
movswl %dx, %esi
movswq %dx, %r8
shlq $0x5, %r8
leaq 0x17a6fe(%rip), %rax    # 0x1b1a50
addq %rax, %r8
movswl %cx, %eax
movl %eax, 0x48(%rsp)
cmpl 0x48(%rsp), %esi
je 0x37651
movq %r8, 0x30(%rsp)
movl (%rdi), %r15d
movq 0x80(%rsp), %rax
movl (%rax), %r14d
movl %esi, 0x14(%rsp)
movswl %si, %edx
movl %r15d, %edi
movl %r14d, %esi
movl %edx, 0x4c(%rsp)
movl %r12d, %ecx
callq 0x32f1e
cmpl $0x1, %eax
jne 0x37421
movq 0x30(%rsp), %rdx
movzwl 0xc(%rdx), %ebx
movzwl 0xe(%rdx), %eax
testl %eax, 0xc8(%rsp)
sete %al
testw %bx, %bx
setns %cl
testb %cl, %al
je 0x3742b
movswq 0x8(%rdx), %rax
shlq $0x5, %rax
leaq 0x17a684(%rip), %rcx    # 0x1b1a50
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 0x3744c
movl %r9d, %eax
imull %r9d, %eax
movl %ebp, %edx
imull %ebp, %edx
addl %eax, %edx
movl $0x40000000, %eax       # imm = 0x40000000
cmpl %edx, %r14d
jge 0x3744e
movl %r14d, %eax
shlq $0x1e, %rax
movl %edx, %edi
xorl %edx, %edx
divq %rdi
cltq
jmp 0x3744e
movq 0x18(%rsp), %rdi
jmp 0x3762b
movswq 0x8(%rdx), %rax
shlq $0x5, %rax
leaq 0x17a615(%rip), %rcx    # 0x1b1a50
movl (%rax,%rcx), %edi
movl 0x4(%rax,%rcx), %esi
subl (%rdx), %edi
subl 0x4(%rdx), %esi
jmp 0x37577
xorl %eax, %eax
movzwl %bx, %edx
imulq $0x28, %rdx, %r12
leaq 0x205604(%rip), %rdx    # 0x23ca60
addq %rdx, %r12
movq %r9, 0x70(%rsp)
movq %r9, %r14
imulq %rax, %r14
shrq $0x1e, %r14
addl %esi, %r14d
movq %rbp, 0x68(%rsp)
imulq %rax, %rbp
shrq $0x1e, %rbp
addl %ecx, %ebp
movq 0x58(%rsp), %rax
movswl (%r13,%rax,2), %edi
movl %edi, 0x44(%rsp)
movl %r14d, %esi
movl %ebp, %edx
callq 0x370fb
movl %eax, %r13d
movw %bx, 0xa(%rsp)
movswl %bx, %edi
movl %edi, 0x40(%rsp)
movl %r14d, %esi
movl %ebp, %edx
callq 0x370fb
addl $0xffffff00, %r13d      # imm = 0xFFFFFF00
movb $0x1, %bl
cmpl %r13d, %eax
jge 0x374dc
testb $0x1, 0xe(%r12)
jne 0x374dc
subl 0xc0(%rsp), %eax
incl %eax
movq 0x50(%rsp), %rcx
cmpl %eax, (%rcx)
setl %bl
movl 0x44(%rsp), %edi
movl %r14d, %esi
movl %ebp, %edx
callq 0x371c4
movl %eax, %r13d
movl 0x40(%rsp), %edi
movl %r14d, %esi
movl %ebp, %edx
callq 0x371c4
addl $0x100, %r13d           # imm = 0x100
cmpl %r13d, %eax
leaq 0x3f3034(%rip), %r13    # 0x42a540
jle 0x37528
testb $0x1, 0xc(%r12)
jne 0x37528
addl 0x3c(%rsp), %eax
movq 0x50(%rsp), %rcx
cmpl %eax, (%rcx)
setg %al
testb %bl, %al
jmp 0x3752a
testb %bl, %bl
movzwl 0xa(%rsp), %ebx
movl 0x24(%rsp), %r12d
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %rsi
je 0x37577
movswq 0xc(%rsp), %rax
movl %eax, %ecx
movq 0x18(%rsp), %rdi
movq 0x78(%rsp), %rbp
movl 0x14(%rsp), %esi
movq 0x30(%rsp), %r8
testl %ecx, %ecx
jle 0x3763e
leaq -0x1(%rcx), %rdx
cmpw -0x2(%r13,%rcx,2), %bx
movq %rdx, %rcx
jne 0x3755b
jmp 0x3764b
movl %r12d, %r13d
callq 0x33164
movl %eax, %ecx
xorl $0x400, %ecx            # imm = 0x400
leaq 0x3907c2(%rip), %rdx    # 0x3c7d50
movswl (%rdx,%rcx,2), %r14d
sarl $0xb, %r14d
addl $0x200, %eax            # imm = 0x200
andl $0x7ff, %eax            # imm = 0x7FF
movswl (%rdx,%rax,2), %ebx
sarl $0xb, %ebx
movb $-0x10, %r12b
movq 0x18(%rsp), %rcx
addl %r14d, %r15d
movl %r15d, (%rcx)
movq 0x80(%rsp), %rax
movl (%rax), %ebp
addl %ebx, %ebp
movl %ebp, (%rax)
incb %r12b
je 0x375e6
movl (%rcx), %r15d
movl %r15d, %edi
movl %ebp, %esi
movl 0x4c(%rsp), %edx
movl %r13d, %ecx
callq 0x32f1e
movq 0x18(%rsp), %rcx
testl %eax, %eax
jne 0x375b0
movl 0x2c(%rsp), %eax
cmpl $0x2, %eax
jl 0x37679
decl %eax
movl %eax, 0x2c(%rsp)
movq 0x18(%rsp), %rax
movl (%rax), %edi
movl %ebp, %esi
movq 0x60(%rsp), %rdx
callq 0x23663
movq 0x18(%rsp), %rdi
pushq $-0x1
popq %rax
movl %eax, 0x28(%rsp)
movl %r13d, %r12d
movl 0x10(%rsp), %ebx
leaq 0x3f2f1a(%rip), %r13    # 0x42a540
movq 0x78(%rsp), %rbp
movl 0x14(%rsp), %esi
movq 0x30(%rsp), %r8
addl %ebx, %esi
addq %rbp, %r8
jmp 0x3735c
leal 0x1(%rax), %ecx
movl %ecx, 0xc(%rsp)
movw %bx, (%r13,%rax,2)
movl 0x10(%rsp), %ebx
jmp 0x37634
movq 0x58(%rsp), %rcx
incq %rcx
movswq 0xc(%rsp), %rax
cmpq %rax, %rcx
jl 0x37315
negl %ebx
xorl %eax, %eax
cmpl $0x0, 0x28(%rsp)
jne 0x372e4
jmp 0x3767c
pushq $-0x1
popq %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq