// File: /workspace/github_c_makefile_star2_O3/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 0x54ff2
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x357b2b(%rip), %rax    # 0x3ac4e0
cmpb $0x0, (%rax)
je 0x549d8
movl %edi, %eax
andl $0x7, %eax
leaq 0x4fdda(%rip), %rcx     # 0xa47a0
movb (%rcx,%rax), %al
movl %edi, %ecx
shrl $0x3, %ecx
leaq 0x35690b(%rip), %rdx    # 0x3ab2e0
orb %al, (%rdx,%rcx)
leaq 0x3ff131(%rip), %rax    # 0x453b10
movw %di, (%rax)
movw $0x1, %ax
leaq 0x3ff323(%rip), %rcx    # 0x453d10
leaq 0x2282bc(%rip), %r13    # 0x27ccb0
leaq 0x382da9(%rip), %r9     # 0x3d77a4
leaq 0x361b1e(%rip), %r10    # 0x3b6520
movapd 0x23625(%rip), %xmm11   # 0x78030
movapd 0x25c8c(%rip), %xmm12   # 0x7a6a0
movapd 0x25c93(%rip), %xmm13   # 0x7a6b0
leaq 0x16402c(%rip), %r12    # 0x1b8a50
leaq 0x38ada5(%rip), %r15    # 0x3df7d0
decl %eax
movw %ax, (%rcx)
movzwl %ax, %eax
leaq 0x3ff0d6(%rip), %rcx    # 0x453b10
movzwl (%rcx,%rax,2), %eax
movw %ax, 0xe(%rsp)
movswq %ax, %rcx
leaq 0x357ac2(%rip), %rax    # 0x3ac510
movq %rcx, 0x10(%rsp)
movzwl (%rax,%rcx,2), %r14d
testw %r14w, %r14w
js 0x54b71
leaq 0x309063(%rip), %rax    # 0x35dacc
movb (%rax), %al
movzwl %r14w, %ebx
imulq $0x2c, %rbx, %rdi
movzwl 0xc(%r13,%rdi), %edx
testw %dx, %dx
jns 0x54a89
testb %al, %al
jne 0x54a89
xorl %eax, %eax
jmp 0x54b62
addq %r13, %rdi
cmpb $0x0, 0x14(%rdi)
je 0x54b62
cmpb $0x0, 0x15(%rdi)
setne %sil
movl (%r9), %ecx
cmpl $0x800, %ecx            # imm = 0x800
setl %r8b
andb %sil, %r8b
cmpb $0x1, %r8b
jne 0x54b62
testb $0x30, %dl
jne 0x54b02
movl (%rdi), %edx
movl 0x4(%rdi), %esi
leaq 0x1e5f8b(%rip), %r8     # 0x23aa54
subl (%r8), %esi
leaq 0x1e5f7d(%rip), %r8     # 0x23aa50
subl (%r8), %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
mulsd 0x5a5ed4(%rip), %xmm1   # 0x5fa9c0
mulsd 0x5a5ebc(%rip), %xmm0   # 0x5fa9b0
addsd %xmm1, %xmm0
ucomisd 0x25d88(%rip), %xmm0    # 0x7a888
jbe 0x54b62
movslq %ecx, %rax
imulq $0x2c, %rax, %rsi
leaq 0x38ccc0(%rip), %rbp    # 0x3e17d0
addq %rbp, %rsi
movl $0x2c, %edx
callq 0x4d437
movapd 0x25b8a(%rip), %xmm13   # 0x7a6b0
movapd 0x25b71(%rip), %xmm12   # 0x7a6a0
movapd 0x234f8(%rip), %xmm11   # 0x78030
leaq 0x3619e1(%rip), %r10    # 0x3b6520
leaq 0x382c5e(%rip), %r9     # 0x3d77a4
movslq (%r9), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r9)
imulq $0x2c, %rax, %rax
movw %r14w, 0x1e(%rbp,%rax)
leaq 0x308f6c(%rip), %rax    # 0x35dacc
movb (%rax), %al
movzwl (%r10,%rbx,2), %r14d
testw %r14w, %r14w
jns 0x54a6b
movq 0x10(%rsp), %rsi
movswl %si, %eax
movl %eax, %ecx
andl $0x7, %ecx
leaq 0x4fc1b(%rip), %rdx     # 0xa47a0
movb (%rdx,%rcx), %cl
sarl $0x3, %eax
cltq
leaq 0x37b1cc(%rip), %rdx    # 0x3cfd60
orb %cl, (%rdx,%rax)
leaq (%rsi,%rsi,4), %rcx
leaq 0x1eeebe(%rip), %rax    # 0x243a60
movswq 0x2(%rax,%rcx,8), %rsi
testq %rsi, %rsi
jle 0x54fd1
leaq 0x382be4(%rip), %rax    # 0x3d779c
movzwl (%rax), %eax
movw %ax, 0xa(%rsp)
movswq %ax, %rax
leaq 0x382bcf(%rip), %rdx    # 0x3d779a
movzwl (%rdx), %r10d
movswq %r10w, %rdx
movswl %dx, %r9d
leaq 0x1eee82(%rip), %rdi    # 0x243a60
leaq (%rdi,%rcx,8), %rcx
movswq (%rcx), %r8
addq %r8, %rsi
leaq 0x21ae80(%rip), %rcx    # 0x26fa70
movss (%rcx), %xmm0
leaq 0x21ae81(%rip), %rcx    # 0x26fa7c
movss (%rcx), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm0
leaq 0x21ae6b(%rip), %rcx    # 0x26fa78
movss (%rcx), %xmm1
leaq 0x21ae5c(%rip), %rcx    # 0x26fa74
movss (%rcx), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
cvtdq2pd %xmm2, %xmm1
leaq 0x3ff0e6(%rip), %rcx    # 0x453d10
movzwl (%rcx), %ecx
movq %rcx, 0x10(%rsp)
movsd 0x5a5ef6(%rip), %xmm2   # 0x5fab30
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
leaq 0x1e5e0f(%rip), %rcx    # 0x23aa54
movd (%rcx), %xmm4
leaq 0x1e5e00(%rip), %rcx    # 0x23aa50
movd (%rcx), %xmm3
punpckldq %xmm4, %xmm3    # xmm3 = xmm3[0],xmm4[0],xmm3[1],xmm4[1]
movq %r8, %rcx
shlq $0x5, %rcx
leaq (%r12,%rcx), %r11
addq $0xe, %r11
pxor %xmm4, %xmm4
xorl %ecx, %ecx
movw %r10w, 0xc(%rsp)
movl %r10d, %edi
movswq -0x6(%r11,%rcx), %rbx
shlq $0x5, %rbx
movq -0xe(%r11,%rcx), %xmm6
psubd %xmm3, %xmm6
movq (%r12,%rbx), %xmm5
psubd %xmm3, %xmm5
movswl -0x2(%r11,%rcx), %ebx
testl %ebx, %ebx
js 0x54d89
testb $0x20, (%r11,%rcx)
jne 0x54d89
movl %ebx, %r14d
shrl $0x3, %r14d
movl %ebx, %ebp
andl $0x7, %ebp
leaq 0x4fadf(%rip), %r10     # 0xa47a0
movb (%r10,%rbp), %bpl
leaq 0x37b094(%rip), %r10    # 0x3cfd60
testb %bpl, (%r10,%r14)
jne 0x54d89
pshufd $0x55, %xmm5, %xmm7     # xmm7 = xmm5[1,1,1,1]
movd %xmm5, %ebp
xorps %xmm8, %xmm8
cvtsi2sd %ebp, %xmm8
movd %xmm7, %ebp
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 %ebp, %xmm7
mulpd %xmm9, %xmm7
addpd %xmm8, %xmm7
movapd %xmm7, %xmm8
movhpd 0x25b37(%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 0x54d89
movq 0x10(%rsp), %r10
movswq %r10w, %r14
incl %r10d
leaq 0x3fef9e(%rip), %rbp    # 0x453d10
movw %r10w, (%rbp)
leaq 0x3fed92(%rip), %rbp    # 0x453b10
movw %bx, (%rbp,%r14,2)
movq %r10, 0x10(%rsp)
testq %rcx, %rcx
je 0x54d99
movswq -0x26(%r11,%rcx), %rbx
cmpq %rbx, %r8
je 0x54dc0
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 0x54ea0
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 0x54ea0
unpckhpd %xmm5, %xmm4            # xmm4 = xmm4[1],xmm5[1]
mulpd %xmm2, %xmm4
movswq %di, %rbx
divpd %xmm7, %xmm4
addpd %xmm2, %xmm4
andpd %xmm6, %xmm4
andnpd 0x2587a(%rip), %xmm6    # 0x7a6c0
orpd %xmm4, %xmm6
leaq 0x5a9d8f(%rip), %r10    # 0x5febe0
movlpd %xmm6, (%r10,%rbx,8)
pshufd $0xee, %xmm6, %xmm4     # xmm4 = xmm6[2,3,2,3]
leaq 0x5b1d7d(%rip), %r10    # 0x606be0
movq %xmm4, (%r10,%rbx,8)
ucomisd %xmm6, %xmm4
jbe 0x54ea0
leaq 0x3f8ffa(%rip), %rdi    # 0x44de70
movzwl 0xe(%rsp), %r10d
movw %r10w, (%rdi,%rbx,2)
leaq 0x1e3bc8(%rip), %rdi    # 0x238a50
movw %r8w, (%rdi,%rbx,2)
leal 0x1(%rbx), %edi
movw %di, (%r15,%rbx,2)
leaq 0x3828fe(%rip), %r10    # 0x3d779a
movw %di, (%r10)
movswq -0x6(%r11,%rcx), %rbx
cmpq %rbx, %r8
jle 0x54ebe
movswl %di, %ebx
cmpl %ebx, %r9d
jge 0x54ebe
movslq %ebx, %r14
movw %r9w, -0x2(%r15,%r14,2)
jmp 0x54ec1
movl %r9d, %ebx
incq %r8
addq $0x20, %rcx
movl %ebx, %r9d
movapd %xmm5, %xmm4
cmpq %rsi, %r8
jl 0x54c76
cmpw %di, 0xc(%rsp)
leaq 0x3828c0(%rip), %r9     # 0x3d77a4
leaq 0x361635(%rip), %r10    # 0x3b6520
jge 0x54fd1
movswq %di, %rcx
leaq (%rdx,%rdx), %rsi
leaq 0x1e3b50(%rip), %rdi    # 0x238a50
addq %rsi, %rdi
addq %r15, %rsi
subq %rdx, %rcx
shlq $0x3, %rdx
xorl %r9d, %r9d
movzwl 0xa(%rsp), %r8d
movswq (%rdi,%r9,2), %r10
shlq $0x5, %r10
movzwl 0x8(%r12,%r10), %ebx
movzwl (%rsi,%r9,2), %r10d
movswq %r10w, %r11
leaq 0x1e3b1b(%rip), %r14    # 0x238a50
cmpw (%r14,%r11,2), %bx
jne 0x54f5c
leaq (%rdx,%r9,8), %rbx
leaq 0x5b1c99(%rip), %r14    # 0x606be0
movsd (%r14,%rbx), %xmm0
leaq 0x5a9c8c(%rip), %rbx    # 0x5febe0
ucomisd (%rbx,%r11,8), %xmm0
jbe 0x54f81
movswq %r8w, %r11
incl %r8d
leaq 0x382832(%rip), %rbx    # 0x3d779c
movw %r8w, (%rbx)
leaq 0x38284b(%rip), %rbx    # 0x3d77c0
movw %r10w, (%rbx,%r11,2)
movw $0xffff, (%rsi,%r9,2)   # imm = 0xFFFF
incq %r9
cmpq %r9, %rcx
jne 0x54f16
cmpw %r8w, 0xa(%rsp)
leaq 0x38280e(%rip), %r9     # 0x3d77a4
leaq 0x361583(%rip), %r10    # 0x3b6520
leaq 0x38481c(%rip), %rdi    # 0x3d97c0
jge 0x54fd1
movswq %r8w, %rcx
leaq 0x38280f(%rip), %rdx    # 0x3d77c0
movzwl (%rdx,%rax,2), %esi
movl %esi, %edx
movswq %si, %rsi
movzwl (%r15,%rsi,2), %esi
testw %si, %si
jns 0x54fb5
movw %dx, (%rdi,%rax,2)
incq %rax
cmpq %rcx, %rax
jne 0x54faa
leaq 0x3fed38(%rip), %rcx    # 0x453d10
movzwl (%rcx), %eax
testw %ax, %ax
jg 0x54a2b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq