// File: /workspace/github_c_makefile_star2_O3/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:
cmpw $-0x1, %di
je 0x1ac64
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x11339b(%rip), %eax    # 0x12dd68
leal -0x1(%rax), %r8d
movswq %di, %rcx
leaq (%rcx,%rcx,4), %rcx
leaq 0x229080(%rip), %rdx    # 0x243a60
movzwl (%rdx,%rcx,8), %edi
movzwl 0x2(%rdx,%rcx,8), %r12d
addw %di, %r12w
decl %r12d
xorl %ecx, %ecx
movl %r8d, %r15d
movl %r8d, %edx
movl $0x0, %r11d
movw %di, 0xa(%rsp)
cmpw %r12w, %di
jg 0x1aa94
movl 0x113340(%rip), %edi    # 0x12dd54
movl 0x895e9(%rip), %r8d     # 0xa4004
xorl %ebp, %ebp
movl 0x15f7a4(%rip), %r9d    # 0x17a1c8
leaq 0x19e025(%rip), %r10    # 0x1b8a50
movzwl 0xa(%rsp), %edx
movl %edx, %ebx
movl %r15d, %edx
movswq %bx, %r14
shlq $0x5, %r14
movl 0x4(%r10,%r14), %r11d
subl %edi, %r11d
imull %r8d, %r11d
sarl $0xe, %r11d
addl %r9d, %r11d
movswq 0x8(%r10,%r14), %r14
shlq $0x5, %r14
movl 0x4(%r10,%r14), %r14d
subl %edi, %r14d
imull %r8d, %r14d
sarl $0xe, %r14d
addl %r9d, %r14d
cmpl %edx, %r11d
cmovll %r11d, %edx
cmpl %edx, %r14d
cmovll %r14d, %edx
cmpl %ebp, %r11d
cmovlel %ebp, %r11d
cmpl %r11d, %r14d
cmovgl %r14d, %r11d
incl %ebx
movl %r11d, %ebp
cmpw %r12w, %bx
jle 0x1aa35
movl %r12d, 0xc(%rsp)
testl %edx, %edx
cmovgl %edx, %ecx
cmpl %eax, %r11d
cmovll %r11d, %r15d
leaq 0x391a3c(%rip), %rax    # 0x3ac4e8
movl (%rax), %ebx
shrl $0x2, %ebx
andl $0x3, %ebx
addl %ecx, %ebx
movl %r15d, 0x10(%rsp)
cmpl %r15d, %ebx
jg 0x1ac56
leaq 0x3ed521(%rip), %rax    # 0x407fec
movl (%rax), %r13d
leaq 0x15fb2b(%rip), %r14    # 0x17a600
movzbl %sil, %eax
movl %eax, 0x14(%rsp)
leaq 0x19df6c(%rip), %r15    # 0x1b8a50
movl %ebx, %eax
subl 0x15f6dc(%rip), %eax    # 0x17a1c8
shll $0xe, %eax
movl 0x8950f(%rip), %edi     # 0xa4004
cltd
idivl %edi
movl %eax, %ecx
addl 0x113254(%rip), %ecx    # 0x12dd54
movl $0x0, 0x15faf6(%rip)    # 0x17a600
movw $0x1, %bp
movl 0xc(%rsp), %eax
cmpw %ax, 0xa(%rsp)
jg 0x1ac04
movl 0x11322c(%rip), %r8d    # 0x12dd50
movw $0x1, %si
movl 0x15f695(%rip), %r9d    # 0x17a1c4
movzwl 0xa(%rsp), %eax
movl %eax, %r10d
movswq %r10w, %rax
shlq $0x5, %rax
movl (%r15,%rax), %r12d
movl 0x4(%r15,%rax), %ebp
movswq 0x8(%r15,%rax), %rax
shlq $0x5, %rax
movl (%r15,%rax), %r11d
movl 0x4(%r15,%rax), %eax
cmpl %eax, %ebp
jle 0x1ab66
movl %ebp, %edx
movl %r12d, %ebp
jmp 0x1ab70
movl %eax, %edx
movl %ebp, %eax
movl %r11d, %ebp
movl %r12d, %r11d
cmpl %ecx, %edx
jle 0x1abae
movl %ecx, %r12d
subl %eax, %r12d
jl 0x1abae
subl %r11d, %ebp
subl %eax, %edx
movslq %r12d, %r12
movslq %ebp, %rax
imulq %r12, %rax
movslq %edx, %r12
cqto
idivq %r12
addl %r11d, %eax
subl %r8d, %eax
imull %edi, %eax
sarl $0xe, %eax
addl %r9d, %eax
js 0x1abae
movswq %si, %rdx
incl %esi
movl %eax, (%r14,%rdx,4)
incl %r10d
cmpw 0xc(%rsp), %r10w
jle 0x1ab37
testw %si, %si
jle 0x1ac49
movw $0x1, %bp
cmpw $0x1, %si
je 0x1ac04
movzwl %si, %eax
movl $0x1, %ecx
movq %rcx, %rdx
movq %r14, %rdi
movl (%r14,%rcx,4), %r8d
movl (%rdi), %r9d
cmpl %r9d, %r8d
jge 0x1abf1
movl %r9d, (%r14,%rcx,4)
movl %r8d, (%rdi)
addq $0x4, %rdi
decq %rdx
jne 0x1abde
incq %rcx
cmpq %rax, %rcx
jne 0x1abd8
movl %esi, %ebp
movl %ebp, %eax
andl $0x1, %eax
leal -0x1(%rbp), %r12d
cmpw %r12w, %ax
jge 0x1ac49
andl $0x1, %ebp
movl (%r14,%rbp,4), %edi
cmpl %r13d, %edi
jg 0x1ac49
movl 0x4(%r14,%rbp,4), %edx
cmpl %r13d, %edx
jle 0x1ac31
movl %r13d, 0x4(%r14,%rbp,4)
movl %r13d, %edx
movl %ebx, %esi
movl %ebx, %ecx
movl 0x14(%rsp), %r8d
callq 0x18ded
addq $0x2, %rbp
cmpw %bp, %r12w
jg 0x1ac16
addl $0x3, %ebx
cmpl 0x10(%rsp), %ebx
jle 0x1aae4
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq