// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/build.c
// Function: fillsector
int fillsector(short sectnum, unsigned char fillcolor)
{
	int x1, x2, y1, y2, sy, y, templong;
	int lborder, rborder, uborder, dborder, miny, maxy, dax;
	short z, zz, startwall, endwall, fillcnt;

	lborder = 0; rborder = xdim;
	uborder = 0; dborder = ydim16;

	if (sectnum == -1)
		return(0);
	miny = dborder-1;
	maxy = uborder;
	startwall = sector[sectnum].wallptr;
	endwall = startwall + sector[sectnum].wallnum - 1;
	for(z=startwall;z<=endwall;z++)
	{
		y1 = (((wall[z].y-posy)*zoom)>>14)+midydim16;
		y2 = (((wall[wall[z].point2].y-posy)*zoom)>>14)+midydim16;
		if (y1 < miny) miny = y1;
		if (y2 < miny) miny = y2;
		if (y1 > maxy) maxy = y1;
		if (y2 > maxy) maxy = y2;
	}
	if (miny < uborder) miny = uborder;
	if (maxy >= dborder) maxy = dborder-1;

	for(sy=miny+((totalclock>>2)&3);sy<=maxy;sy+=3)	// JBF 20040116: numframes%3 -> (totalclock>>2)&3
	{
		y = posy+(((sy-midydim16)<<14)/zoom);

		fillist[0] = lborder; fillcnt = 1;
		for(z=startwall;z<=endwall;z++)
		{
			x1 = wall[z].x; x2 = wall[wall[z].point2].x;
			y1 = wall[z].y; y2 = wall[wall[z].point2].y;
			if (y1 > y2)
			{
				templong = x1; x1 = x2; x2 = templong;
				templong = y1; y1 = y2; y2 = templong;
			}
			if ((y1 <= y) && (y2 > y))
				//if (x1*(y-y2) + x2*(y1-y) <= 0)
				{
					dax = x1+scale(y-y1,x2-x1,y2-y1);
					dax = (((dax-posx)*zoom)>>14)+halfxdim16;
					if (dax >= lborder)
						fillist[fillcnt++] = dax;
				}
		}
		if (fillcnt > 0)
		{
			for(z=1;z<fillcnt;z++)
				for (zz=0;zz<z;zz++)
					if (fillist[z] < fillist[zz])
					{
						templong = fillist[z]; fillist[z] = fillist[zz]; fillist[zz] = templong;
					}

			for (z=(fillcnt&1);z<fillcnt-1;z+=2)
			{
				if (fillist[z] > rborder) break;
				if (fillist[z+1] > rborder)
					fillist[z+1] = rborder;
				drawline16(fillist[z],sy,fillist[z+1],sy,fillcolor);
			}
		}
	}
	return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %sil, %al
movw %di, %cx
movw %cx, -0x6(%rbp)
movb %al, -0x7(%rbp)
movl $0x0, -0x28(%rbp)
leaq 0x41b4e9(%rip), %rax    # 0x442d4c
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl 0x142c53(%rip), %eax    # 0x16a4c8
movl %eax, -0x34(%rbp)
movswl -0x6(%rbp), %eax
cmpl $-0x1, %eax
jne 0x2788d
movl $0x0, -0x4(%rbp)
jmp 0x27cfb
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x3c(%rbp)
movswq -0x6(%rbp), %rcx
leaq 0x258d18(%rip), %rax    # 0x2805c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movw (%rax), %ax
movw %ax, -0x46(%rbp)
movswl -0x46(%rbp), %eax
movswq -0x6(%rbp), %rdx
leaq 0x258cfa(%rip), %rcx    # 0x2805c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movswl 0x2(%rcx), %ecx
addl %ecx, %eax
subl $0x1, %eax
movw %ax, -0x48(%rbp)
movw -0x46(%rbp), %ax
movw %ax, -0x42(%rbp)
movswl -0x42(%rbp), %eax
movswl -0x48(%rbp), %ecx
cmpl %ecx, %eax
jg 0x279ae
movswq -0x42(%rbp), %rcx
leaq 0x1cdcb2(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
subl 0x142ba6(%rip), %eax    # 0x16a4b4
imull 0xb868f(%rip), %eax     # 0xdffa4
sarl $0xe, %eax
addl 0x18f00a(%rip), %eax    # 0x1b6928
movl %eax, -0x14(%rbp)
movswq -0x42(%rbp), %rcx
leaq 0x1cdc83(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswq 0x8(%rax), %rcx
leaq 0x1cdc70(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
subl 0x142b64(%rip), %eax    # 0x16a4b4
imull 0xb864d(%rip), %eax     # 0xdffa4
sarl $0xe, %eax
addl 0x18efc8(%rip), %eax    # 0x1b6928
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x27971
movl -0x14(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x2797f
movl -0x18(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x2798d
movl -0x14(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x2799b
movl -0x18(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x2799d
movw -0x42(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x42(%rbp)
jmp 0x278e2
movl -0x38(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x279bc
movl -0x30(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jl 0x279cd
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
leaq 0x3c1671(%rip), %rcx    # 0x3e9048
movl (%rcx), %ecx
sarl $0x2, %ecx
andl $0x3, %ecx
addl %ecx, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jg 0x27cf4
movl 0x142abe(%rip), %eax    # 0x16a4b4
movl %eax, -0x50(%rbp)
movl -0x1c(%rbp), %eax
subl 0x18ef26(%rip), %eax    # 0x1b6928
shll $0xe, %eax
cltd
idivl 0xb8598(%rip)           # 0xdffa4
movl %eax, %ecx
movl -0x50(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x20(%rbp)
movl -0x28(%rbp), %eax
movl %eax, 0x18f341(%rip)    # 0x1b6d60
movw $0x1, -0x4a(%rbp)
movw -0x46(%rbp), %ax
movw %ax, -0x42(%rbp)
movswl -0x42(%rbp), %eax
movswl -0x48(%rbp), %ecx
cmpl %ecx, %eax
jg 0x27b81
movswq -0x42(%rbp), %rcx
leaq 0x1cdb67(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0xc(%rbp)
movswq -0x42(%rbp), %rcx
leaq 0x1cdb4f(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswq 0x8(%rax), %rcx
leaq 0x1cdb3c(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x10(%rbp)
movswq -0x42(%rbp), %rcx
leaq 0x1cdb24(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x14(%rbp)
movswq -0x42(%rbp), %rcx
leaq 0x1cdb0b(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswq 0x8(%rax), %rcx
leaq 0x1cdaf8(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0x27af1
movl -0xc(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0x27b6e
movl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0x27b6e
movl -0xc(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x20(%rbp), %edi
subl -0x14(%rbp), %edi
movl -0x10(%rbp), %esi
subl -0xc(%rbp), %esi
movl -0x18(%rbp), %edx
subl -0x14(%rbp), %edx
callq 0x248a0
movl %eax, %ecx
movl -0x54(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
subl 0x14297f(%rip), %eax    # 0x16a4b0
imull 0xb846c(%rip), %eax     # 0xdffa4
sarl $0xe, %eax
addl 0x18ede3(%rip), %eax    # 0x1b6924
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x28(%rbp), %eax
jl 0x27b6c
movl -0x40(%rbp), %edx
movw -0x4a(%rbp), %ax
movw %ax, %cx
addw $0x1, %cx
movw %cx, -0x4a(%rbp)
movswq %ax, %rcx
leaq 0x18f1f7(%rip), %rax    # 0x1b6d60
movl %edx, (%rax,%rcx,4)
jmp 0x27b6e
jmp 0x27b70
movw -0x42(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x42(%rbp)
jmp 0x27a2d
movswl -0x4a(%rbp), %eax
cmpl $0x0, %eax
jle 0x27ce4
movw $0x1, -0x42(%rbp)
movswl -0x42(%rbp), %eax
movswl -0x4a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x27c3b
movw $0x0, -0x44(%rbp)
movswl -0x44(%rbp), %eax
movswl -0x42(%rbp), %ecx
cmpl %ecx, %eax
jge 0x27c28
movswq -0x42(%rbp), %rcx
leaq 0x18f19e(%rip), %rax    # 0x1b6d60
movl (%rax,%rcx,4), %eax
movswq -0x44(%rbp), %rdx
leaq 0x18f18f(%rip), %rcx    # 0x1b6d60
cmpl (%rcx,%rdx,4), %eax
jge 0x27c18
movswq -0x42(%rbp), %rcx
leaq 0x18f17e(%rip), %rax    # 0x1b6d60
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
movswq -0x44(%rbp), %rcx
leaq 0x18f16c(%rip), %rax    # 0x1b6d60
movl (%rax,%rcx,4), %edx
movswq -0x42(%rbp), %rcx
leaq 0x18f15d(%rip), %rax    # 0x1b6d60
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %edx
movswq -0x44(%rbp), %rcx
leaq 0x18f14b(%rip), %rax    # 0x1b6d60
movl %edx, (%rax,%rcx,4)
jmp 0x27c1a
movw -0x44(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x44(%rbp)
jmp 0x27baa
jmp 0x27c2a
movw -0x42(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x42(%rbp)
jmp 0x27b94
movswl -0x4a(%rbp), %eax
andl $0x1, %eax
movw %ax, -0x42(%rbp)
movswl -0x42(%rbp), %eax
movswl -0x4a(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x27ce2
movswq -0x42(%rbp), %rcx
leaq 0x18f0fb(%rip), %rax    # 0x1b6d60
movl (%rax,%rcx,4), %eax
cmpl -0x2c(%rbp), %eax
jle 0x27c6f
jmp 0x27ce2
movswl -0x42(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x18f0e0(%rip), %rax    # 0x1b6d60
movl (%rax,%rcx,4), %eax
cmpl -0x2c(%rbp), %eax
jle 0x27c9f
movl -0x2c(%rbp), %edx
movswl -0x42(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x18f0c4(%rip), %rax    # 0x1b6d60
movl %edx, (%rax,%rcx,4)
movswq -0x42(%rbp), %rcx
leaq 0x18f0b5(%rip), %rax    # 0x1b6d60
movl (%rax,%rcx,4), %edi
movl -0x1c(%rbp), %esi
movswl -0x42(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x18f09e(%rip), %rax    # 0x1b6d60
movl (%rax,%rcx,4), %edx
movl -0x1c(%rbp), %ecx
movzbl -0x7(%rbp), %r8d
callq 0x250b0
movswl -0x42(%rbp), %eax
addl $0x2, %eax
movw %ax, -0x42(%rbp)
jmp 0x27c46
jmp 0x27ce4
jmp 0x27ce6
movl -0x1c(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x1c(%rbp)
jmp 0x279e4
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)