// File: /workspace/github_c_makefile_star2_O1/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 0x52bb3
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x358fb6(%rip), %rax    # 0x3ab4e0
cmpb $0x0, (%rax)
je 0x5254d
movl %edi, %eax
andl $0x7, %eax
leaq 0x51265(%rip), %rcx     # 0xa37a0
movb (%rcx,%rax), %al
movl %edi, %ecx
shrl $0x3, %ecx
leaq 0x357d96(%rip), %rdx    # 0x3aa2e0
orb %al, (%rdx,%rcx)
leaq 0x4005bc(%rip), %rax    # 0x452b10
movw %di, (%rax)
leaq 0x4007b2(%rip), %rcx    # 0x452d10
movw $0x1, (%rcx)
leaq 0x229746(%rip), %r8     # 0x27bcb0
leaq 0x30a55b(%rip), %r9     # 0x35cacc
leaq 0x38422c(%rip), %r10    # 0x3d67a4
leaq 0x362fa1(%rip), %r11    # 0x3b5520
movsd 0x26dd0(%rip), %xmm13   # 0x79358
movsd 0x22547(%rip), %xmm14   # 0x74ad8
leaq 0x38c238(%rip), %r14    # 0x3de7d0
movzwl (%rcx), %eax
decl %eax
movw %ax, (%rcx)
movswq %ax, %rax
leaq 0x400565(%rip), %rcx    # 0x452b10
movzwl (%rcx,%rax,2), %eax
movw %ax, 0x1a(%rsp)
movswq %ax, %rbp
leaq 0x358f51(%rip), %rax    # 0x3ab510
movzwl (%rax,%rbp,2), %ebx
testw %bx, %bx
js 0x526c3
movzwl %bx, %r13d
imulq $0x2c, %r13, %rdi
movzwl 0xc(%r8,%rdi), %ecx
testw %cx, %cx
jns 0x525e9
cmpb $0x0, (%r9)
je 0x526b9
addq %r8, %rdi
cmpb $0x0, 0x14(%rdi)
je 0x526b9
cmpb $0x0, 0x15(%rdi)
setne %dl
movl (%r10), %eax
cmpl $0x800, %eax            # imm = 0x800
setl %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x526b9
testb $0x30, %cl
jne 0x5265e
movl (%rdi), %ecx
movl 0x4(%rdi), %edx
leaq 0x1e742d(%rip), %rsi    # 0x239a54
subl (%rsi), %edx
leaq 0x1e7420(%rip), %rsi    # 0x239a50
subl (%rsi), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
mulsd 0x5a7378(%rip), %xmm1   # 0x5f99c0
mulsd 0x5a7360(%rip), %xmm0   # 0x5f99b0
addsd %xmm1, %xmm0
ucomisd 0x26d14(%rip), %xmm0    # 0x79370
jbe 0x526b9
cltq
imulq $0x2c, %rax, %rsi
leaq 0x38e165(%rip), %r15    # 0x3e07d0
addq %r15, %rsi
movl $0x2c, %edx
callq 0x4ac52
movsd 0x22457(%rip), %xmm14   # 0x74ad8
movsd 0x26cce(%rip), %xmm13   # 0x79358
leaq 0x362e8f(%rip), %r11    # 0x3b5520
leaq 0x38410c(%rip), %r10    # 0x3d67a4
leaq 0x30a42d(%rip), %r9     # 0x35cacc
leaq 0x22960a(%rip), %r8     # 0x27bcb0
movslq (%r10), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r10)
imulq $0x2c, %rax, %rax
movw %bx, 0x1e(%r15,%rax)
movzwl (%r11,%r13,2), %ebx
jmp 0x525c3
movswl %bp, %eax
movl %eax, %ecx
andl $0x7, %ecx
leaq 0x510ce(%rip), %rdx     # 0xa37a0
movb (%rdx,%rcx), %cl
sarl $0x3, %eax
cltq
leaq 0x37c67f(%rip), %rdx    # 0x3ced60
orb %cl, (%rdx,%rax)
leaq 0x3840b1(%rip), %rax    # 0x3d679c
movswq (%rax), %rax
leaq 0x3840a4(%rip), %rcx    # 0x3d679a
movswl (%rcx), %ecx
movl %ecx, 0x1c(%rsp)
leaq (,%rbp,4), %rcx
addq %rbp, %rcx
leaq 0x1f0351(%rip), %rdx    # 0x242a60
movswq 0x2(%rdx,%rcx,8), %r10
testq %r10, %r10
jle 0x52a91
leaq 0x1f033b(%rip), %rdx    # 0x242a60
leaq (%rdx,%rcx,8), %rcx
movswq (%rcx), %rsi
addq %rsi, %r10
leaq 0x384063(%rip), %rcx    # 0x3d679a
movzwl (%rcx), %ecx
movl %ecx, 0x14(%rsp)
leaq 0x4005cb(%rip), %rcx    # 0x452d10
movzwl (%rcx), %ecx
movq %rcx, 0x20(%rsp)
leaq 0x1e72fc(%rip), %rcx    # 0x239a50
movl (%rcx), %r8d
leaq 0x1e72f6(%rip), %rcx    # 0x239a54
movl (%rcx), %edi
leaq 0x21c309(%rip), %rcx    # 0x26ea70
xorps %xmm0, %xmm0
cvtsi2sdl (%rcx), %xmm0
leaq 0x21c303(%rip), %rcx    # 0x26ea78
xorps %xmm1, %xmm1
cvtsi2sdl (%rcx), %xmm1
leaq 0x21c2f9(%rip), %rcx    # 0x26ea7c
cvtsi2sdl (%rcx), %xmm2
leaq 0x21c2e6(%rip), %rcx    # 0x26ea74
cvtsi2sdl (%rcx), %xmm3
movsd 0x5a7396(%rip), %xmm4   # 0x5f9b30
movq %rsi, %rcx
shlq $0x5, %rcx
leaq 0x1652a8(%rip), %rdx    # 0x1b7a50
leaq (%rdx,%rcx), %r11
addq $0xe, %r11
xorpd %xmm5, %xmm5
xorl %ecx, %ecx
xorpd %xmm6, %xmm6
movl 0x1c(%rsp), %r9d
movl %edi, 0xc(%rsp)
movl %r8d, 0x10(%rsp)
movswq -0x6(%r11,%rcx), %r12
shlq $0x5, %r12
movl -0xe(%r11,%rcx), %ebp
movl -0xa(%r11,%rcx), %ebx
subl %r8d, %ebp
subl %edi, %ebx
leaq 0x165268(%rip), %rdx    # 0x1b7a50
movl (%rdx,%r12), %r15d
movl 0x4(%rdx,%r12), %r12d
subl %r8d, %r15d
subl %edi, %r12d
xorps %xmm7, %xmm7
cvtsi2sd %r12d, %xmm7
movswl -0x2(%r11,%rcx), %r13d
xorps %xmm8, %xmm8
cvtsi2sd %r15d, %xmm8
testl %r13d, %r13d
js 0x528db
testb $0x20, (%r11,%rcx)
jne 0x528db
movq %r10, %r8
movl %r13d, %edx
shrl $0x3, %edx
movl %r13d, %r10d
andl $0x7, %r10d
leaq 0x50f67(%rip), %rdi     # 0xa37a0
movb (%rdi,%r10), %r10b
leaq 0x37c51c(%rip), %rdi    # 0x3ced60
testb %r10b, (%rdi,%rdx)
jne 0x528cf
xorps %xmm9, %xmm9
cvtsi2sd %ebp, %xmm9
xorps %xmm10, %xmm10
cvtsi2sd %ebx, %xmm10
mulsd %xmm8, %xmm10
subl %ebp, %r15d
cvtsi2sd %r15d, %xmm11
mulsd %xmm7, %xmm9
subl %ebx, %r12d
cvtsi2sd %r12d, %xmm12
subsd %xmm10, %xmm9
mulsd %xmm9, %xmm9
mulsd %xmm12, %xmm12
mulsd %xmm11, %xmm11
addsd %xmm12, %xmm11
mulsd 0x26ab4(%rip), %xmm11   # 0x79350
ucomisd %xmm9, %xmm11
jb 0x528cf
movq 0x20(%rsp), %rdi
movswq %di, %rdx
leal 0x1(%rdi), %r10d
leaq 0x400459(%rip), %r15    # 0x452d10
movw %r10w, (%r15)
leaq 0x40024e(%rip), %r15    # 0x452b10
movw %r13w, (%r15,%rdx,2)
movl %r10d, %edx
movq %rdx, 0x20(%rsp)
movq %r8, %r10
movl 0x10(%rsp), %r8d
movl 0xc(%rsp), %edi
testq %rcx, %rcx
je 0x528f5
movswq -0x26(%r11,%rcx), %rdx
movapd %xmm6, %xmm10
movapd %xmm5, %xmm9
cmpq %rdx, %rsi
je 0x52935
xorps %xmm5, %xmm5
cvtsi2sd %ebx, %xmm5
xorps %xmm10, %xmm10
cvtsi2sd %ebp, %xmm10
movapd %xmm10, %xmm6
mulsd %xmm1, %xmm6
movapd %xmm5, %xmm9
mulsd %xmm0, %xmm9
subsd %xmm6, %xmm9
mulsd %xmm13, %xmm9
mulsd %xmm3, %xmm5
mulsd %xmm2, %xmm10
addsd %xmm5, %xmm10
mulsd %xmm13, %xmm10
movapd %xmm8, %xmm6
mulsd %xmm1, %xmm6
movapd %xmm7, %xmm5
mulsd %xmm0, %xmm5
subsd %xmm6, %xmm5
mulsd %xmm13, %xmm5
mulsd %xmm3, %xmm7
mulsd %xmm2, %xmm8
addsd %xmm7, %xmm8
movapd %xmm8, %xmm6
mulsd %xmm13, %xmm6
ucomisd %xmm14, %xmm10
jae 0x52979
ucomisd %xmm14, %xmm6
jb 0x52a5b
movapd %xmm9, %xmm7
mulsd %xmm6, %xmm7
movapd %xmm10, %xmm8
mulsd %xmm5, %xmm8
ucomisd %xmm7, %xmm8
jbe 0x52a5b
mulsd %xmm4, %xmm9
divsd %xmm10, %xmm9
addsd %xmm4, %xmm9
movapd %xmm14, %xmm7
cmplesd %xmm10, %xmm7
andpd %xmm7, %xmm9
movsd 0x269a1(%rip), %xmm8    # 0x79360
andnpd %xmm8, %xmm7
orpd %xmm9, %xmm7
movswq 0x14(%rsp), %rbx
leaq 0x5ab20a(%rip), %rdx    # 0x5fdbe0
movlpd %xmm7, (%rdx,%rbx,8)
movapd %xmm5, %xmm8
mulsd %xmm4, %xmm8
divsd %xmm6, %xmm8
addsd %xmm4, %xmm8
movapd %xmm14, %xmm9
cmplesd %xmm6, %xmm9
andpd %xmm9, %xmm8
movsd 0x26960(%rip), %xmm10   # 0x79368
andnpd %xmm10, %xmm9
orpd %xmm8, %xmm9
leaq 0x5b31c7(%rip), %rdx    # 0x605be0
movlpd %xmm9, (%rdx,%rbx,8)
ucomisd %xmm7, %xmm9
jbe 0x52a5b
leaq 0x3fa443(%rip), %rdx    # 0x44ce70
movzwl 0x1a(%rsp), %edi
movw %di, (%rdx,%rbx,2)
movl 0xc(%rsp), %edi
leaq 0x1e500f(%rip), %rdx    # 0x237a50
movw %si, (%rdx,%rbx,2)
leal 0x1(%rbx), %ebp
movw %bp, (%r14,%rbx,2)
leaq 0x383d46(%rip), %rdx    # 0x3d679a
movl %ebp, 0x14(%rsp)
movw %bp, (%rdx)
movswq -0x6(%r11,%rcx), %rdx
cmpq %rdx, %rsi
jle 0x52a7b
movswl 0x14(%rsp), %ebx
cmpl %ebx, %r9d
jge 0x52a7b
movslq %ebx, %rdx
movw %r9w, -0x2(%r14,%rdx,2)
jmp 0x52a7e
movl %r9d, %ebx
incq %rsi
addq $0x20, %rcx
movl %ebx, %r9d
cmpq %r10, %rsi
jl 0x527c8
leaq 0x383d02(%rip), %rcx    # 0x3d679a
movswq (%rcx), %rcx
movl 0x1c(%rsp), %edx
cmpw %cx, %dx
leaq 0x383cf2(%rip), %r15    # 0x3d679c
leaq 0x383d0f(%rip), %r13    # 0x3d67c0
jge 0x52b46
movzwl (%r15), %r8d
movslq %edx, %rdx
leaq (%rdx,%rdx), %rsi
leaq 0x1e4f87(%rip), %rdi    # 0x237a50
addq %rsi, %rdi
addq %r14, %rsi
subq %rdx, %rcx
shlq $0x3, %rdx
xorl %r9d, %r9d
movswq (%rdi,%r9,2), %r10
shlq $0x5, %r10
leaq 0x164f67(%rip), %r11    # 0x1b7a50
movzwl 0x8(%r11,%r10), %ebx
movzwl (%rsi,%r9,2), %r10d
movswq %r10w, %r11
leaq 0x1e4f51(%rip), %r12    # 0x237a50
cmpw (%r12,%r11,2), %bx
jne 0x52b26
leaq (%rdx,%r9,8), %rbx
leaq 0x5b30cf(%rip), %r12    # 0x605be0
movsd (%r12,%rbx), %xmm0
leaq 0x5ab0c2(%rip), %rbx    # 0x5fdbe0
ucomisd (%rbx,%r11,8), %xmm0
jbe 0x52b3e
movswq %r8w, %r11
incl %r8d
movw %r8w, (%r15)
movw %r10w, (%r13,%r11,2)
movw $0xffff, (%rsi,%r9,2)   # imm = 0xFFFF
incq %r9
cmpq %r9, %rcx
jne 0x52ad9
movswq (%r15), %rcx
cmpw %cx, %ax
leaq 0x22915c(%rip), %r8     # 0x27bcb0
leaq 0x309f71(%rip), %r9     # 0x35cacc
leaq 0x383c42(%rip), %r10    # 0x3d67a4
leaq 0x3629b7(%rip), %r11    # 0x3b5520
leaq 0x385c50(%rip), %rdi    # 0x3d87c0
jge 0x52b94
movzwl (%r13,%rax,2), %esi
movl %esi, %edx
movswq %si, %rsi
movzwl (%r14,%rsi,2), %esi
testw %si, %si
jns 0x52b78
movw %dx, (%rdi,%rax,2)
incq %rax
cmpq %rcx, %rax
jne 0x52b72
leaq 0x400175(%rip), %rcx    # 0x452d10
cmpw $0x0, (%rcx)
jg 0x52598
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq