// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: cansee
int cansee(int x1, int y1, int z1, short sect1, int x2, int y2, int z2, short sect2)
{
	sectortype *sec;
	walltype *wal, *wal2;
	int i, cnt, nexts, x, y, z, cz, fz, dasectnum, dacnt, danum;
	int x21, y21, z21, x31, y31, x34, y34, bot, t;

	if ((x1 == x2) && (y1 == y2)) return(sect1 == sect2);

	x21 = x2-x1; y21 = y2-y1; z21 = z2-z1;

	clipsectorlist[0] = sect1; danum = 1;
	for(dacnt=0;dacnt<danum;dacnt++)
	{
		dasectnum = clipsectorlist[dacnt]; sec = &sector[dasectnum];
		for(cnt=sec->wallnum,wal=&wall[sec->wallptr];cnt>0;cnt--,wal++)
		{
			wal2 = &wall[wal->point2];
			x31 = wal->x-x1; x34 = wal->x-wal2->x;
			y31 = wal->y-y1; y34 = wal->y-wal2->y;

			bot = y21*x34-x21*y34; if (bot <= 0) continue;
			t = y21*x31-x21*y31; if ((unsigned)t >= (unsigned)bot) continue;
			t = y31*x34-x31*y34; if ((unsigned)t >= (unsigned)bot) continue;

			nexts = wal->nextsector;
			if ((nexts < 0) || (wal->cstat&32)) return(0);

			t = divscale24(t,bot);
			x = x1 + mulscale24(x21,t);
			y = y1 + mulscale24(y21,t);
			z = z1 + mulscale24(z21,t);

			getzsofslope((short)dasectnum,x,y,&cz,&fz);
			if ((z <= cz) || (z >= fz)) return(0);
			getzsofslope((short)nexts,x,y,&cz,&fz);
			if ((z <= cz) || (z >= fz)) return(0);

			for(i=danum-1;i>=0;i--) if (clipsectorlist[i] == nexts) break;
			if (i < 0) clipsectorlist[danum++] = nexts;
		}
	}
	for(i=danum-1;i>=0;i--) if (clipsectorlist[i] == sect2) return(1);
	return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %r14d
movzwl 0x88(%rsp), %esi
movl %r8d, %eax
xorl %edi, %eax
movl %r9d, %r10d
xorl %r14d, %r10d
orl %eax, %r10d
jne 0x33865
xorl %eax, %eax
cmpw %si, %cx
sete %al
jmp 0x33ab7
movl 0x80(%rsp), %eax
subl %edi, %r8d
subl %r14d, %r9d
subl %edx, %eax
movw %cx, 0x3f6cc5(%rip)     # 0x42a540
movslq %r8d, %rcx
movq %rcx, 0x40(%rsp)
movslq %r9d, %rcx
movq %rcx, 0x38(%rsp)
cltq
movq %rax, 0x30(%rsp)
pushq $0x1
popq %r10
xorl %ecx, %ecx
leaq 0x3f6ca1(%rip), %r15    # 0x42a540
movl %r9d, 0x1c(%rsp)
movl %r8d, 0x18(%rsp)
movl %edx, 0x20(%rsp)
movl %r14d, 0x14(%rsp)
movl %edi, 0x10(%rsp)
movslq %r10d, %rax
cmpq %rax, %rcx
jge 0x33a9a
movl %r10d, 0x4(%rsp)
movq %rcx, 0x28(%rsp)
movswq (%r15,%rcx,2), %rax
imulq $0x28, %rax, %rcx
leaq 0x209184(%rip), %rdx    # 0x23ca60
movswl 0x2(%rcx,%rdx), %r12d
movswq (%rcx,%rdx), %rbx
shlq $0x5, %rbx
leaq 0x17e15e(%rip), %rcx    # 0x1b1a50
addq %rcx, %rbx
cwtl
movl %eax, 0x24(%rsp)
testl %r12d, %r12d
jle 0x33a80
movswq 0x8(%rbx), %rcx
shlq $0x5, %rcx
movl (%rbx), %edx
movl 0x4(%rbx), %r13d
movl %edx, %ebp
leaq 0x17e135(%rip), %r10    # 0x1b1a50
subl (%rcx,%r10), %ebp
movl %r13d, %esi
subl 0x4(%rcx,%r10), %esi
movl %ebp, %ecx
imull %r9d, %ecx
movl %esi, %r10d
imull %r8d, %r10d
subl %r10d, %ecx
jle 0x33a74
subl %edi, %edx
subl %r14d, %r13d
movl %edx, %r11d
imull %r9d, %r11d
movl %r13d, %r10d
imull %r8d, %r10d
subl %r10d, %r11d
cmpl %ecx, %r11d
jae 0x33a74
imull %ebp, %r13d
imull %edx, %esi
subl %esi, %r13d
cmpl %ecx, %r13d
jae 0x33a74
movzwl 0xc(%rbx), %ebp
xorl %eax, %eax
testw %bp, %bp
js 0x33ab7
testb $0x20, 0xe(%rbx)
jne 0x33ab7
movl %r13d, %eax
shlq $0x18, %rax
movl %ecx, %ecx
xorl %edx, %edx
divq %rcx
movslq %eax, %r13
movl %r14d, %eax
movq %r13, %r14
imulq 0x40(%rsp), %r14
shrq $0x18, %r14
addl %edi, %r14d
movq %r13, %r15
imulq 0x38(%rsp), %r15
shrq $0x18, %r15
addl %eax, %r15d
imulq 0x30(%rsp), %r13
shrq $0x18, %r13
addl 0x20(%rsp), %r13d
movl 0x24(%rsp), %edi
movl %r14d, %esi
movl %r15d, %edx
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x2373c
cmpl 0xc(%rsp), %r13d
jle 0x33ab5
cmpl 0x8(%rsp), %r13d
jge 0x33ab5
movswl %bp, %edi
movl %r14d, %esi
movl %r15d, %edx
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x2373c
cmpl 0xc(%rsp), %r13d
jle 0x33ab5
cmpl 0x8(%rsp), %r13d
movl 0x1c(%rsp), %r9d
movl 0x18(%rsp), %r8d
movl 0x14(%rsp), %r14d
movl 0x10(%rsp), %edi
leaq 0x3f6b04(%rip), %r15    # 0x42a540
movl 0x4(%rsp), %ecx
movl $0x0, %eax
jge 0x33ab7
movl %ecx, 0x4(%rsp)
movl %ecx, %eax
testl %eax, %eax
jle 0x33a62
leaq -0x1(%rax), %rcx
cmpw %bp, -0x2(%r15,%rax,2)
movq %rcx, %rax
jne 0x33a4d
jmp 0x33a74
movl 0x4(%rsp), %ecx
movslq %ecx, %rax
incl %ecx
movl %ecx, 0x4(%rsp)
movw %bp, (%r15,%rax,2)
decl %r12d
addq $0x20, %rbx
jmp 0x338fa
movq 0x28(%rsp), %rcx
incq %rcx
movzwl 0x88(%rsp), %esi
movl 0x4(%rsp), %r10d
jmp 0x338b6
movl %r10d, %edx
pushq $0x1
popq %rax
testl %edx, %edx
jle 0x33ab5
leaq -0x1(%rdx), %rcx
cmpw %si, -0x2(%r15,%rdx,2)
movq %rcx, %rdx
jne 0x33aa0
jmp 0x33ab7
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq