// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/polymost.c
// Function: polymost_scansector
static void polymost_scansector (int sectnum)
{
	double d, xp1, yp1, xp2, yp2;
	walltype *wal, *wal2;
	spritetype *spr;
	int z, zz, startwall, endwall, numscansbefore, scanfirst, bunchfrst, nextsectnum;
	int xs, ys, x1, y1, x2, y2;

	if (sectnum < 0) return;
	if (automapping) show2dsector[sectnum>>3] |= pow2char[sectnum&7];

	sectorborder[0] = sectnum, sectorbordercnt = 1;
	do
	{
		sectnum = sectorborder[--sectorbordercnt];

		for(z=headspritesect[sectnum];z>=0;z=nextspritesect[z])
		{
			spr = &sprite[z];
			if ((((spr->cstat&0x8000) == 0) || (showinvisibility)) &&
				  (spr->xrepeat > 0) && (spr->yrepeat > 0) &&
				  (spritesortcnt < MAXSPRITESONSCREEN))
			{
				xs = spr->x-globalposx; ys = spr->y-globalposy;
				if ((spr->cstat&48) || (xs*gcosang+ys*gsinang > 0))
				{
					copybufbyte(spr,&tsprite[spritesortcnt],sizeof(spritetype));
					tsprite[spritesortcnt++].owner = z;
				}
			}
		}

		gotsector[sectnum>>3] |= pow2char[sectnum&7];

		bunchfrst = numbunches;
		numscansbefore = numscans;

		startwall = sector[sectnum].wallptr; endwall = sector[sectnum].wallnum+startwall;
		scanfirst = numscans;
		xp2 = 0; yp2 = 0;
		for(z=startwall,wal=&wall[z];z<endwall;z++,wal++)
		{
			wal2 = &wall[wal->point2];
			x1 = wal->x-globalposx; y1 = wal->y-globalposy;
			x2 = wal2->x-globalposx; y2 = wal2->y-globalposy;

			nextsectnum = wal->nextsector; //Scan close sectors
			if ((nextsectnum >= 0) && (!(wal->cstat&32)) && (!(gotsector[nextsectnum>>3]&pow2char[nextsectnum&7])))
			{
				d = (double)x1*(double)y2 - (double)x2*(double)y1; xp1 = (double)(x2-x1); yp1 = (double)(y2-y1);
				if (d*d <= (xp1*xp1 + yp1*yp1)*(SCISDIST*SCISDIST*260.0))
					sectorborder[sectorbordercnt++] = nextsectnum;
			}

			if ((z == startwall) || (wall[z-1].point2 != z))
			{
				xp1 = ((double)y1*(double)cosglobalang             - (double)x1*(double)singlobalang            )/64.0;
				yp1 = ((double)x1*(double)cosviewingrangeglobalang + (double)y1*(double)sinviewingrangeglobalang)/64.0;
			}
			else { xp1 = xp2; yp1 = yp2; }
			xp2 = ((double)y2*(double)cosglobalang             - (double)x2*(double)singlobalang            )/64.0;
			yp2 = ((double)x2*(double)cosviewingrangeglobalang + (double)y2*(double)sinviewingrangeglobalang)/64.0;
			if ((yp1 >= SCISDIST) || (yp2 >= SCISDIST))
				if ((double)xp1*(double)yp2 < (double)xp2*(double)yp1) //if wall is facing you...
				{
					if (yp1 >= SCISDIST)
						  dxb1[numscans] = (double)xp1*ghalfx/(double)yp1 + ghalfx;
					else dxb1[numscans] = -1e32;

					if (yp2 >= SCISDIST)
						  dxb2[numscans] = (double)xp2*ghalfx/(double)yp2 + ghalfx;
					else dxb2[numscans] = 1e32;

					if (dxb1[numscans] < dxb2[numscans])
						{ thesector[numscans] = sectnum; thewall[numscans] = z; p2[numscans] = numscans+1; numscans++; }
				}

			if ((wall[z].point2 < z) && (scanfirst < numscans))
				{ p2[numscans-1] = scanfirst; scanfirst = numscans; }
		}

		for(z=numscansbefore;z<numscans;z++)
			if ((wall[thewall[z]].point2 != thewall[p2[z]]) || (dxb2[z] > dxb1[p2[z]]))
				{ bunchfirst[numbunches++] = p2[z]; p2[z] = -1; }

		for(z=bunchfrst;z<numbunches;z++)
		{
			for(zz=bunchfirst[z];p2[zz]>=0;zz=p2[zz]);
			bunchlast[z] = zz;
		}
	} while (sectorbordercnt > 0);
}

// Assembly:
testl %edi, %edi
js 0x4b307
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x35a7e3(%rip), %rax    # 0x3a54e0
cmpb $0x0, (%rax)
je 0x4ad20
movl %edi, %eax
andl $0x7, %eax
leaq 0x52a92(%rip), %rcx     # 0x9d7a0
movb (%rcx,%rax), %al
movl %edi, %ecx
shrl $0x3, %ecx
leaq 0x3595c3(%rip), %rdx    # 0x3a42e0
orb %al, (%rdx,%rcx)
leaq 0x401de9(%rip), %rax    # 0x44cb10
movw %di, (%rax)
movw $0x1, %cx
leaq 0x22af7b(%rip), %r8     # 0x275cb0
leaq 0x30bd90(%rip), %r9     # 0x356acc
leaq 0x385a61(%rip), %r11    # 0x3d07a4
leaq 0x3647d6(%rip), %r14    # 0x3af520
leaq 0x385a4b(%rip), %rbp    # 0x3d079c
movapd 0x22046(%rip), %xmm11   # 0x6cda0
movapd 0x246ad(%rip), %xmm12   # 0x6f410
movapd 0x246b4(%rip), %xmm13   # 0x6f420
leaq 0x38da5d(%rip), %r12    # 0x3d87d0
decl %ecx
leaq 0x401f94(%rip), %rax    # 0x44cd10
movw %cx, (%rax)
movzwl %cx, %eax
leaq 0x401d87(%rip), %rcx    # 0x44cb10
movzwl (%rcx,%rax,2), %eax
movw %ax, 0xe(%rsp)
movswl %ax, %r15d
movswq %r15w, %rax
movq %rax, 0x10(%rsp)
leaq (%rax,%rax), %r13
addq 0x41216(%rip), %r13     # 0x8bfc0
movswq (%r13), %r13
testq %r13, %r13
js 0x4aea6
imulq $0x2c, %r13, %rdi
movzwl 0xc(%r8,%rdi), %ecx
testw %cx, %cx
jns 0x4add1
cmpb $0x0, (%r9)
je 0x4ae9b
addq %r8, %rdi
cmpb $0x0, 0x14(%rdi)
je 0x4ae9b
cmpb $0x0, 0x15(%rdi)
setne %dl
movl (%r11), %eax
cmpl $0x800, %eax            # imm = 0x800
setl %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x4ae9b
testb $0x30, %cl
jne 0x4ae40
movl (%rdi), %ecx
movl 0x4(%rdi), %edx
leaq 0x1e8c45(%rip), %rsi    # 0x233a54
subl (%rsi), %edx
leaq 0x1e8c38(%rip), %rsi    # 0x233a50
subl (%rsi), %ecx
cvtsi2sd %ecx, %xmm0
cvtsi2sd %edx, %xmm1
mulsd 0x5a8b96(%rip), %xmm1   # 0x5f39c0
mulsd 0x5a8b7e(%rip), %xmm0   # 0x5f39b0
addsd %xmm1, %xmm0
ucomisd 0x2478a(%rip), %xmm0    # 0x6f5c8
jbe 0x4ae9b
cltq
imulq $0x2c, %rax, %rsi
leaq 0x38f983(%rip), %rbx    # 0x3da7d0
addq %rbx, %rsi
pushq $0x2c
popq %rdx
callq 0x44524
movapd 0x245bf(%rip), %xmm13   # 0x6f420
movapd 0x245a6(%rip), %xmm12   # 0x6f410
movapd 0x21f2d(%rip), %xmm11   # 0x6cda0
leaq 0x38592a(%rip), %r11    # 0x3d07a4
leaq 0x30bc4b(%rip), %r9     # 0x356acc
leaq 0x22ae28(%rip), %r8     # 0x275cb0
movslq (%r11), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r11)
imulq $0x2c, %rax, %rax
movw %r13w, 0x1e(%rbx,%rax)
addq %r13, %r13
addq %r14, %r13
jmp 0x4adaa
movl %r15d, %eax
andl $0x7, %eax
leaq 0x528ed(%rip), %rcx     # 0x9d7a0
movb (%rcx,%rax), %al
sarl $0x3, %r15d
movslq %r15d, %rcx
leaq 0x37de9c(%rip), %rdx    # 0x3c8d60
orb %al, (%rdx,%rcx)
movzwl (%rbp), %esi
movswq %si, %rcx
leaq 0x3858c4(%rip), %rax    # 0x3d079a
movzwl (%rax), %eax
movl %eax, 0x8(%rsp)
movswq %ax, %rdx
movswl %dx, %r10d
imulq $0x28, 0x10(%rsp), %rax
leaq 0x1f1b6e(%rip), %r8     # 0x23ca60
movswq (%r8,%rax), %rdi
movswq 0x2(%r8,%rax), %r9
addq %rdi, %r9
leaq 0x21db69(%rip), %rax    # 0x268a70
movss (%rax), %xmm0
leaq 0x21db6a(%rip), %rax    # 0x268a7c
movss (%rax), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm0
leaq 0x401dec(%rip), %rax    # 0x44cd10
movzwl (%rax), %eax
movq %rax, 0x18(%rsp)
leaq 0x21db45(%rip), %rax    # 0x268a78
movss (%rax), %xmm1
leaq 0x21db36(%rip), %rax    # 0x268a74
movss (%rax), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
cvtdq2pd %xmm2, %xmm1
movsd 0x5a8bdf(%rip), %xmm2   # 0x5f3b30
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
leaq 0x1e8af8(%rip), %rax    # 0x233a54
movd (%rax), %xmm4
leaq 0x1e8ae9(%rip), %rax    # 0x233a50
movd (%rax), %xmm3
punpckldq %xmm4, %xmm3    # xmm3 = xmm3[0],xmm4[0],xmm3[1],xmm4[1]
movq %rdi, %rax
shlq $0x5, %rax
leaq 0x166ad3(%rip), %r8     # 0x1b1a50
leaq (%r8,%rax), %r11
addq $0xe, %r11
pxor %xmm4, %xmm4
xorl %eax, %eax
movq %r9, 0x10(%rsp)
movswq 0x8(%rsp), %r15
cmpq %r9, %rdi
jge 0x4b22f
movswq -0x6(%r11,%rax), %r13
shlq $0x5, %r13
movq -0xe(%r11,%rax), %xmm6
psubd %xmm3, %xmm6
leaq 0x166a95(%rip), %r8     # 0x1b1a50
movq (%r8,%r13), %xmm5
psubd %xmm3, %xmm5
movswl -0x2(%r11,%rax), %r13d
testl %r13d, %r13d
js 0x4b0d7
testb $0x20, (%r11,%rax)
jne 0x4b0d7
movq %rbp, %r9
movq %r14, %r8
movl %r13d, %ebx
shrl $0x3, %ebx
movl %r13d, %r14d
andl $0x7, %r14d
leaq 0x527a7(%rip), %rbp     # 0x9d7a0
movb (%rbp,%r14), %r14b
leaq 0x37dd5b(%rip), %rbp    # 0x3c8d60
testb %r14b, (%rbp,%rbx)
jne 0x4b0cc
pshufd $0x55, %xmm5, %xmm7     # xmm7 = xmm5[1,1,1,1]
movd %xmm5, %ebx
cvtsi2sd %ebx, %xmm8
movd %xmm7, %ebx
movdqa %xmm5, %xmm7
psubd %xmm6, %xmm7
movdqa %xmm6, %xmm9
punpckldq %xmm7, %xmm9    # xmm9 = xmm9[0],xmm7[0],xmm9[1],xmm7[1]
cvtdq2pd %xmm9, %xmm9
pshufd $0x55, %xmm6, %xmm10    # xmm10 = xmm6[1,1,1,1]
pshufd $0x55, %xmm7, %xmm7     # xmm7 = xmm7[1,1,1,1]
punpckldq %xmm7, %xmm10   # xmm10 = xmm10[0],xmm7[0],xmm10[1],xmm7[1]
cvtdq2pd %xmm10, %xmm7
xorpd %xmm11, %xmm8
shufpd $0x2, %xmm7, %xmm8      # xmm8 = xmm8[0],xmm7[1]
mulpd %xmm7, %xmm8
movapd %xmm9, %xmm7
cvtsi2sd %ebx, %xmm7
mulpd %xmm9, %xmm7
addpd %xmm8, %xmm7
movapd %xmm7, %xmm8
movhpd 0x24541(%rip), %xmm8    # xmm8 = xmm8[0],mem[0]
mulpd %xmm7, %xmm8
movapd %xmm8, %xmm7
unpckhpd %xmm8, %xmm7            # xmm7 = xmm7[1],xmm8[1]
ucomisd %xmm8, %xmm7
jb 0x4b0cc
movq 0x18(%rsp), %rbx
movswq %bx, %r14
movq %r14, 0x20(%rsp)
leal 0x1(%rbx), %r14d
leaq 0x401c62(%rip), %rbx    # 0x44cd10
movw %r14w, (%rbx)
leaq 0x401a57(%rip), %rbp    # 0x44cb10
movq 0x20(%rsp), %rbx
movw %r13w, (%rbp,%rbx,2)
movl %r14d, %ebx
movq %rbx, 0x18(%rsp)
movq %r8, %r14
movq %r9, %rbp
movq 0x10(%rsp), %r9
testq %rax, %rax
je 0x4b0e7
movswq -0x26(%r11,%rax), %rbx
cmpq %rbx, %rdi
je 0x4b10e
cvtdq2pd %xmm6, %xmm4
movapd %xmm4, %xmm6
xorpd %xmm11, %xmm6
movapd %xmm4, %xmm7
shufpd $0x1, %xmm6, %xmm7      # xmm7 = xmm7[1],xmm6[0]
mulpd %xmm1, %xmm7
mulpd %xmm0, %xmm4
addpd %xmm7, %xmm4
mulpd %xmm12, %xmm4
cvtdq2pd %xmm5, %xmm5
movapd %xmm5, %xmm6
xorpd %xmm11, %xmm6
movapd %xmm5, %xmm7
shufpd $0x1, %xmm6, %xmm7      # xmm7 = xmm7[1],xmm6[0]
mulpd %xmm1, %xmm7
mulpd %xmm0, %xmm5
addpd %xmm7, %xmm5
mulpd %xmm12, %xmm5
movdqa %xmm4, %xmm7
punpcklqdq %xmm5, %xmm7    # xmm7 = xmm7[0],xmm5[0]
movapd %xmm13, %xmm6
cmplepd %xmm7, %xmm6
movmskpd %xmm6, %ebx
testl %ebx, %ebx
je 0x4b1f8
movapd %xmm5, %xmm8
shufpd $0x1, %xmm5, %xmm8      # xmm8 = xmm8[1],xmm5[0]
mulpd %xmm4, %xmm8
movapd %xmm8, %xmm9
unpckhpd %xmm8, %xmm9            # xmm9 = xmm9[1],xmm8[1]
ucomisd %xmm9, %xmm8
jbe 0x4b1f8
unpckhpd %xmm5, %xmm4            # xmm4 = xmm4[1],xmm5[1]
mulpd %xmm2, %xmm4
divpd %xmm7, %xmm4
addpd %xmm2, %xmm4
andpd %xmm6, %xmm4
andnpd 0x2429c(%rip), %xmm6    # 0x6f430
orpd %xmm4, %xmm6
leaq 0x5aca41(%rip), %r8     # 0x5f7be0
movlpd %xmm6, (%r8,%r15,8)
pshufd $0xee, %xmm6, %xmm4     # xmm4 = xmm6[2,3,2,3]
leaq 0x5b4a2f(%rip), %r8     # 0x5ffbe0
movq %xmm4, (%r8,%r15,8)
ucomisd %xmm6, %xmm4
jbe 0x4b1f8
leaq 0x3fbcac(%rip), %r8     # 0x446e70
movzwl 0xe(%rsp), %r9d
movw %r9w, (%r8,%r15,2)
movq 0x10(%rsp), %r9
leaq 0x1e6875(%rip), %r8     # 0x231a50
movw %di, (%r8,%r15,2)
leal 0x1(%r15), %ebx
movw %bx, (%r12,%r15,2)
leaq 0x3855aa(%rip), %r8     # 0x3d079a
movl %ebx, 0x8(%rsp)
movw %bx, (%r8)
movswq -0x6(%r11,%rax), %rbx
cmpq %rbx, %rdi
jle 0x4b219
movswl 0x8(%rsp), %r15d
cmpl %r15d, %r10d
jge 0x4b219
movslq %r15d, %rbx
movw %r10w, -0x2(%r12,%rbx,2)
jmp 0x4b21c
movl %r10d, %r15d
incq %rdi
addq $0x20, %rax
movl %r15d, %r10d
movdqa %xmm5, %xmm4
jmp 0x4af90
leaq 0x5b49aa(%rip), %rax    # 0x5ffbe0
leaq (%rax,%rdx,8), %rdi
leaq 0x385563(%rip), %r11    # 0x3d07a4
movswq %si, %rax
cmpq %r15, %rdx
jge 0x4b2ac
leaq 0x1e67ff(%rip), %rbx    # 0x231a50
movswq (%rbx,%rdx,2), %r8
shlq $0x5, %r8
leaq 0x1667ef(%rip), %r9     # 0x1b1a50
movzwl 0x8(%r9,%r8), %r10d
movzwl (%r12,%rdx,2), %r8d
movswq %r8w, %r9
cmpw (%rbx,%r9,2), %r10w
jne 0x4b28a
movsd (%rdi), %xmm0
leaq 0x5ac95e(%rip), %r10    # 0x5f7be0
ucomisd (%r10,%r9,8), %xmm0
jbe 0x4b2a3
leal 0x1(%rax), %esi
movw %si, (%rbp)
leaq 0x385528(%rip), %r9     # 0x3d07c0
movw %r8w, (%r9,%rax,2)
orw $-0x1, (%r12,%rdx,2)
incq %rdx
addq $0x8, %rdi
jmp 0x4b241
leaq 0x22a9fd(%rip), %r8     # 0x275cb0
leaq 0x30b812(%rip), %r9     # 0x356acc
leaq 0x3854ff(%rip), %rdi    # 0x3d07c0
leaq 0x3874f8(%rip), %r10    # 0x3d27c0
cmpq %rax, %rcx
jge 0x4b2eb
movzwl (%rdi,%rcx,2), %esi
movl %esi, %edx
movswq %si, %rsi
movzwl (%r12,%rsi,2), %esi
testw %si, %si
jns 0x4b2d1
movw %dx, (%r10,%rcx,2)
incq %rcx
jmp 0x4b2c8
movq 0x18(%rsp), %rcx
testw %cx, %cx
jg 0x4ad73
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq