// File: /workspace/github_c_makefile_star2_O3/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 %r8d, %eax
xorl %edi, %eax
movl %r9d, %r10d
xorl %esi, %r10d
orl %eax, %r10d
jne 0x3701b
xorl %eax, %eax
cmpw 0x88(%rsp), %cx
sete %al
jmp 0x37278
movl 0x80(%rsp), %eax
subl %edi, %r8d
subl %esi, %r9d
movl %edx, 0x20(%rsp)
subl %edx, %eax
movw %cx, 0x3fa50b(%rip)     # 0x431540
movslq %r8d, %rcx
movq %rcx, 0x40(%rsp)
movslq %r9d, %rcx
movq %rcx, 0x38(%rsp)
cltq
movq %rax, 0x30(%rsp)
movl $0x1, 0x4(%rsp)
xorl %ecx, %ecx
leaq 0x3fa4e3(%rip), %r15    # 0x431540
leaq 0x20c9fc(%rip), %rdx    # 0x243a60
movl %r9d, 0x1c(%rsp)
movl %r8d, 0x18(%rsp)
movl %esi, 0x14(%rsp)
movl %edi, 0x10(%rsp)
movq %rcx, 0x28(%rsp)
movswq (%r15,%rcx,2), %rax
leaq (%rax,%rax,4), %rcx
movswl 0x2(%rdx,%rcx,8), %r12d
testl %r12d, %r12d
jle 0x37233
leaq (%rdx,%rcx,8), %rcx
movswq (%rcx), %rbx
shlq $0x5, %rbx
leaq 0x1819aa(%rip), %rcx    # 0x1b8a50
addq %rcx, %rbx
cwtl
movl %eax, 0x24(%rsp)
movswq 0x8(%rbx), %rcx
shlq $0x5, %rcx
movl (%rbx), %edx
movl 0x4(%rbx), %r13d
movl %edx, %r14d
leaq 0x181989(%rip), %r10    # 0x1b8a50
subl (%rcx,%r10), %r14d
movl %r13d, %ebp
subl 0x4(%rcx,%r10), %ebp
movl %r14d, %ecx
imull %r9d, %ecx
movl %ebp, %r10d
imull %r8d, %r10d
subl %r10d, %ecx
jle 0x3721d
subl %edi, %edx
subl %esi, %r13d
movl %edx, %r11d
imull %r9d, %r11d
movl %r13d, %r10d
imull %r8d, %r10d
subl %r10d, %r11d
cmpl %ecx, %r11d
jae 0x3721d
imull %r14d, %r13d
imull %edx, %ebp
subl %ebp, %r13d
cmpl %ecx, %r13d
jae 0x3721d
movzwl 0xc(%rbx), %ebp
xorl %eax, %eax
testw %bp, %bp
js 0x37278
testb $0x20, 0xe(%rbx)
jne 0x37278
movl %r13d, %eax
shlq $0x18, %rax
movl %ecx, %ecx
xorl %edx, %edx
divq %rcx
movslq %eax, %r13
movq %r13, %r14
imulq 0x40(%rsp), %r14
shrq $0x18, %r14
addl %edi, %r14d
movq %r13, %r15
imulq 0x38(%rsp), %r15
shrq $0x18, %r15
addl %esi, %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 0x26766
cmpl 0xc(%rsp), %r13d
jle 0x37276
cmpl 0x8(%rsp), %r13d
jge 0x37276
movswl %bp, %edi
movl %r14d, %esi
movl %r15d, %edx
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x26766
cmpl 0xc(%rsp), %r13d
jle 0x37276
cmpl 0x8(%rsp), %r13d
movl 0x1c(%rsp), %r9d
movl 0x18(%rsp), %r8d
movl 0x14(%rsp), %esi
movl 0x10(%rsp), %edi
leaq 0x3fa35b(%rip), %r15    # 0x431540
movl 0x4(%rsp), %edx
movl $0x0, %eax
jge 0x37278
movl %edx, %eax
testl %eax, %eax
jle 0x3720f
leaq -0x1(%rax), %rcx
cmpw %bp, -0x2(%r15,%rax,2)
movq %rcx, %rax
jne 0x371f6
movl %edx, 0x4(%rsp)
jmp 0x3721d
movslq %edx, %rax
incl %edx
movl %edx, 0x4(%rsp)
movw %bp, (%r15,%rax,2)
leal -0x1(%r12), %eax
addq $0x20, %rbx
cmpl $0x1, %r12d
movl %eax, %r12d
jg 0x370ae
movq 0x28(%rsp), %rcx
incq %rcx
movslq 0x4(%rsp), %rax
cmpq %rax, %rcx
leaq 0x20c816(%rip), %rdx    # 0x243a60
jl 0x37076
movl 0x4(%rsp), %esi
testl %esi, %esi
jle 0x37276
leaq -0x1(%rsi), %rcx
movl $0x1, %eax
movzwl 0x88(%rsp), %edx
cmpw %dx, -0x2(%r15,%rsi,2)
movq %rcx, %rsi
jne 0x37254
jmp 0x37278
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq