// File: /workspace/github_c_makefile_star2_O1/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 0x35dc6
xorl %eax, %eax
cmpw 0x88(%rsp), %cx
sete %al
movl %eax, (%rsp)
jmp 0x36036
movl 0x80(%rsp), %eax
subl %edi, %r8d
subl %esi, %r9d
movl %edx, 0x1c(%rsp)
subl %edx, %eax
movw %cx, 0x3fa760(%rip)     # 0x430540
movslq %r8d, %rcx
movq %rcx, 0x40(%rsp)
movslq %r9d, %rcx
movq %rcx, 0x38(%rsp)
cltq
movq %rax, 0x30(%rsp)
movl $0x1, %r13d
xorl %ecx, %ecx
leaq 0x3fa73a(%rip), %r15    # 0x430540
leaq 0x20cc53(%rip), %rdx    # 0x242a60
movl %r9d, 0x18(%rsp)
movl %r8d, 0x14(%rsp)
movl %esi, 0x10(%rsp)
movl %edi, 0xc(%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 0x35fed
leaq (%rdx,%rcx,8), %rcx
movswq (%rcx), %r14
shlq $0x5, %r14
leaq 0x181c01(%rip), %rcx    # 0x1b7a50
addq %rcx, %r14
cwtl
movl %eax, 0x20(%rsp)
movswq 0x8(%r14), %rcx
shlq $0x5, %rcx
movl (%r14), %edx
movl 0x4(%r14), %eax
movl %edx, %ebp
leaq 0x181be0(%rip), %r10    # 0x1b7a50
subl (%rcx,%r10), %ebp
movl %eax, %ebx
subl 0x4(%rcx,%r10), %ebx
movl %ebp, %ecx
imull %r9d, %ecx
movl %ebx, %r10d
imull %r8d, %r10d
subl %r10d, %ecx
jle 0x35fd7
subl %edi, %edx
subl %esi, %eax
movl %edx, %r11d
imull %r9d, %r11d
movl %eax, %r10d
imull %r8d, %r10d
subl %r10d, %r11d
cmpl %ecx, %r11d
jae 0x35fd7
imull %ebp, %eax
imull %edx, %ebx
subl %ebx, %eax
cmpl %ecx, %eax
jae 0x35fd7
movzwl 0xc(%r14), %ebx
testw %bx, %bx
js 0x3602f
movl $0x0, (%rsp)
testb $0x20, 0xe(%r14)
jne 0x36036
movl %r13d, 0x24(%rsp)
cltq
shlq $0x18, %rax
movl %ecx, %ecx
cqto
idivq %rcx
movslq %eax, %r13
movq %r13, %rbp
imulq 0x40(%rsp), %rbp
shrq $0x18, %rbp
addl %edi, %ebp
movq %r13, %r15
imulq 0x38(%rsp), %r15
shrq $0x18, %r15
addl %esi, %r15d
imulq 0x30(%rsp), %r13
shrq $0x18, %r13
addl 0x1c(%rsp), %r13d
movl 0x20(%rsp), %edi
movl %ebp, %esi
movl %r15d, %edx
leaq 0x8(%rsp), %rcx
leaq 0x4(%rsp), %r8
callq 0x2600d
cmpl 0x8(%rsp), %r13d
jle 0x36036
cmpl 0x4(%rsp), %r13d
jge 0x36036
movswl %bx, %edi
movl %ebp, %esi
movl %r15d, %edx
leaq 0x8(%rsp), %rcx
leaq 0x4(%rsp), %r8
callq 0x2600d
cmpl 0x8(%rsp), %r13d
jle 0x36036
cmpl 0x4(%rsp), %r13d
leaq 0x3fa5c2(%rip), %r15    # 0x430540
jge 0x36036
movl 0x24(%rsp), %r13d
movl %r13d, %ecx
movl %r13d, %eax
sarl $0x1f, %eax
andl %r13d, %eax
leaq (%r15,%rcx,2), %rdx
addq $-0x2, %rdx
movl %r13d, %ecx
movl 0x18(%rsp), %r9d
movl 0x14(%rsp), %r8d
movl 0x10(%rsp), %esi
movl 0xc(%rsp), %edi
testl %ecx, %ecx
jle 0x35fc8
decl %ecx
leaq -0x2(%rdx), %r10
cmpw %bx, (%rdx)
movq %r10, %rdx
jne 0x35fb2
incl %ecx
movl %ecx, %eax
testl %eax, %eax
jg 0x35fd7
movslq %r13d, %rax
incl %r13d
movw %bx, (%r15,%rax,2)
leal -0x1(%r12), %eax
addq $0x20, %r14
cmpl $0x1, %r12d
movl %eax, %r12d
jg 0x35e57
movq 0x28(%rsp), %rcx
incq %rcx
movslq %r13d, %rax
cmpq %rax, %rcx
leaq 0x20ca5e(%rip), %rdx    # 0x242a60
jl 0x35e1f
movl %r13d, %eax
testl %eax, %eax
jle 0x3602f
leaq -0x1(%rax), %rcx
movl $0x1, (%rsp)
movzwl 0x88(%rsp), %edx
cmpw %dx, -0x2(%r15,%rax,2)
movq %rcx, %rax
jne 0x3600b
jmp 0x36036
movl $0x0, (%rsp)
movl (%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq