// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq -0x28(%rbp), %rax
movswl (%rax), %eax
cmpl $0x0, %eax
jge 0x55741
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x55c90
movl 0x18(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, -0x7c(%rbp)
movl $0x20, -0x54(%rbp)
movl $0x1, -0x78(%rbp)
movl $0x0, -0x74(%rbp)
movq -0x28(%rbp), %rax
movw (%rax), %ax
movw %ax, 0x416611(%rip)     # 0x46bd80
movw $0x0, -0x82(%rbp)
movw $0x1, 0x416e01(%rip)    # 0x46c582
movswq -0x82(%rbp), %rcx
leaq 0x4165f0(%rip), %rax    # 0x46bd80
movswq (%rax,%rcx,2), %rcx
leaq 0x22ae24(%rip), %rax    # 0x2805c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x78(%rbp)
jle 0x557cc
movq -0x38(%rbp), %rax
movw (%rax), %ax
movw %ax, -0x7e(%rbp)
movswl -0x7e(%rbp), %eax
movq -0x38(%rbp), %rcx
movswl 0x2(%rcx), %ecx
addl %ecx, %eax
movw %ax, -0x80(%rbp)
jmp 0x557e9
movq -0x38(%rbp), %rax
movw (%rax), %ax
movw %ax, -0x80(%rbp)
movswl -0x80(%rbp), %eax
movq -0x38(%rbp), %rcx
movswl 0x2(%rcx), %ecx
addl %ecx, %eax
movw %ax, -0x7e(%rbp)
movswl -0x7e(%rbp), %eax
movl %eax, -0x4c(%rbp)
movswq -0x7e(%rbp), %rcx
leaq 0x19fdb4(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x4c(%rbp), %eax
movswl -0x80(%rbp), %ecx
cmpl %ecx, %eax
je 0x55c50
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rax
movl (%rax), %esi
movl -0x4c(%rbp), %eax
movl -0x2c(%rbp), %ecx
subl $0x4, %ecx
movswl %ax, %edx
callq 0x4eaf0
cmpl $0x1, %eax
jne 0x55c2b
movl $0x0, -0x50(%rbp)
movq -0x48(%rbp), %rax
movswl 0xc(%rax), %eax
cmpl $0x0, %eax
jge 0x55857
movl $0x1, -0x50(%rbp)
movq -0x48(%rbp), %rax
movswl 0xe(%rax), %eax
andl -0x7c(%rbp), %eax
cmpl $0x0, %eax
je 0x5586e
movl $0x1, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jne 0x55a87
movq -0x48(%rbp), %rax
movswq 0xc(%rax), %rcx
leaq 0x22ad38(%rip), %rax    # 0x2805c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movswq 0x8(%rax), %rcx
leaq 0x19fd0d(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movq -0x48(%rbp), %rcx
subl (%rcx), %eax
movl %eax, -0x64(%rbp)
movq -0x48(%rbp), %rax
movswq 0x8(%rax), %rcx
leaq 0x19fceb(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x48(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
movq -0x48(%rbp), %rdx
subl (%rdx), %ecx
imull %ecx, %eax
movl -0x68(%rbp), %ecx
movq -0x18(%rbp), %rdx
movl (%rdx), %edx
movq -0x48(%rbp), %rsi
subl 0x4(%rsi), %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jg 0x55912
movl $0x0, -0x58(%rbp)
jmp 0x55946
movl -0x64(%rbp), %eax
imull -0x64(%rbp), %eax
movl -0x68(%rbp), %ecx
imull -0x68(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x70(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x70(%rbp), %eax
jl 0x55936
movl $0x40000000, -0x58(%rbp) # imm = 0x40000000
jmp 0x55944
movl -0x6c(%rbp), %edi
movl -0x70(%rbp), %esi
callq 0x376e0
movl %eax, -0x58(%rbp)
jmp 0x55946
movq -0x48(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
movl -0x64(%rbp), %edi
movl -0x58(%rbp), %esi
callq 0x37700
movl %eax, %ecx
movl -0x8c(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x64(%rbp)
movq -0x48(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x88(%rbp)
movl -0x68(%rbp), %edi
movl -0x58(%rbp), %esi
callq 0x37700
movl %eax, %ecx
movl -0x88(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x68(%rbp)
movswq -0x82(%rbp), %rcx
leaq 0x4163e2(%rip), %rax    # 0x46bd80
movw (%rax,%rcx,2), %ax
movl -0x64(%rbp), %esi
movl -0x68(%rbp), %edx
movswl %ax, %edi
callq 0x55060
movl %eax, -0x6c(%rbp)
movq -0x48(%rbp), %rax
movw 0xc(%rax), %ax
movl -0x64(%rbp), %esi
movl -0x68(%rbp), %edx
movswl %ax, %edi
callq 0x55060
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
movl -0x6c(%rbp), %ecx
subl $0x100, %ecx            # imm = 0x100
cmpl %ecx, %eax
jge 0x55a0a
movq -0x40(%rbp), %rax
movswl 0xe(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x55a0a
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl -0x70(%rbp), %ecx
movl 0x10(%rbp), %edx
subl $0x1, %edx
subl %edx, %ecx
cmpl %ecx, %eax
jl 0x55a08
movl $0x1, -0x50(%rbp)
jmp 0x55a0a
movswq -0x82(%rbp), %rcx
leaq 0x416367(%rip), %rax    # 0x46bd80
movw (%rax,%rcx,2), %ax
movl -0x64(%rbp), %esi
movl -0x68(%rbp), %edx
movswl %ax, %edi
callq 0x551d0
movl %eax, -0x6c(%rbp)
movq -0x48(%rbp), %rax
movw 0xc(%rax), %ax
movl -0x64(%rbp), %esi
movl -0x68(%rbp), %edx
movswl %ax, %edi
callq 0x551d0
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
movl -0x6c(%rbp), %ecx
addl $0x100, %ecx            # imm = 0x100
cmpl %ecx, %eax
jle 0x55a85
movq -0x40(%rbp), %rax
movswl 0xc(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x55a85
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl -0x70(%rbp), %ecx
movl -0x30(%rbp), %edx
subl $0x1, %edx
addl %edx, %ecx
cmpl %ecx, %eax
jg 0x55a83
movl $0x1, -0x50(%rbp)
jmp 0x55a85
jmp 0x55a87
cmpl $0x0, -0x50(%rbp)
je 0x55bb8
movq -0x48(%rbp), %rax
movswq 0x8(%rax), %rcx
leaq 0x19fb0f(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %edi
movq -0x48(%rbp), %rax
subl (%rax), %edi
movq -0x48(%rbp), %rax
movswq 0x8(%rax), %rcx
leaq 0x19faf0(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %esi
movq -0x48(%rbp), %rax
subl 0x4(%rax), %esi
callq 0x4efb0
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
addl $0x400, %eax            # imm = 0x400
andl $0x7ff, %eax            # imm = 0x7FF
movslq %eax, %rcx
leaq 0x3b5dc0(%rip), %rax    # 0x40b8b0
movswl (%rax,%rcx,2), %eax
sarl $0xb, %eax
movl %eax, -0x5c(%rbp)
movl -0x50(%rbp), %eax
addl $0x200, %eax            # imm = 0x200
andl $0x7ff, %eax            # imm = 0x7FF
movslq %eax, %rcx
leaq 0x3b5d9f(%rip), %rax    # 0x40b8b0
movswl (%rax,%rcx,2), %eax
sarl $0xb, %eax
movl %eax, -0x60(%rbp)
movb $0x10, -0x83(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl -0x5c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl -0x60(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movb -0x83(%rbp), %al
addb $-0x1, %al
movb %al, -0x83(%rbp)
movsbl -0x83(%rbp), %eax
cmpl $0x0, %eax
jne 0x55b5c
jmp 0x55b80
jmp 0x55b5e
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rax
movl (%rax), %esi
movl -0x4c(%rbp), %eax
movl -0x2c(%rbp), %ecx
subl $0x4, %ecx
movswl %ax, %edx
callq 0x4eaf0
cmpl $0x0, %eax
jne 0x55b22
movl $0xffffffff, -0x74(%rbp) # imm = 0xFFFFFFFF
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jg 0x55ba1
movl -0x74(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x55c90
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rax
movl (%rax), %esi
movq -0x28(%rbp), %rdx
callq 0x392a0
jmp 0x55c29
movswl 0x4169c3(%rip), %eax    # 0x46c582
subl $0x1, %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jl 0x55bf5
movq -0x48(%rbp), %rax
movswl 0xc(%rax), %eax
movslq -0x50(%rbp), %rdx
leaq 0x4161a2(%rip), %rcx    # 0x46bd80
movswl (%rcx,%rdx,2), %ecx
cmpl %ecx, %eax
jne 0x55be8
jmp 0x55bf5
jmp 0x55bea
movl -0x50(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x55bc5
cmpl $0x0, -0x50(%rbp)
jge 0x55c27
movq -0x48(%rbp), %rax
movw 0xc(%rax), %dx
movw 0x416978(%rip), %ax     # 0x46c582
movw %ax, %cx
addw $0x1, %cx
movw %cx, 0x41696a(%rip)     # 0x46c582
movswq %ax, %rcx
leaq 0x41615d(%rip), %rax    # 0x46bd80
movw %dx, (%rax,%rcx,2)
jmp 0x55c29
jmp 0x55c2b
jmp 0x55c2d
movl -0x78(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x78(%rbp), %ecx
movq -0x48(%rbp), %rax
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x55807
movw -0x82(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x82(%rbp)
movswl -0x82(%rbp), %eax
movswl 0x416912(%rip), %ecx    # 0x46c582
cmpl %ecx, %eax
jl 0x55781
xorl %eax, %eax
subl -0x78(%rbp), %eax
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x74(%rbp)
jne 0x5575a
movl -0x74(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)