// File: /workspace/github_c_makefile_star2_O1/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 0x1ab71
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x112496(%rip), %eax    # 0x12cd68
leal -0x1(%rax), %r8d
movswq %di, %rcx
leaq (%rcx,%rcx,4), %rcx
leaq 0x22817b(%rip), %rdx    # 0x242a60
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 0x1a999
movl 0x11243b(%rip), %edi    # 0x12cd54
movl 0x886e4(%rip), %r8d     # 0xa3004
xorl %ebp, %ebp
movl 0x15e89f(%rip), %r9d    # 0x1791c8
leaq 0x19d120(%rip), %r10    # 0x1b7a50
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 0x1a93a
testl %edx, %edx
cmovgl %edx, %ecx
cmpl %eax, %r11d
cmovll %r11d, %r15d
leaq 0x390b3c(%rip), %rax    # 0x3ab4e8
movl (%rax), %ebx
shrl $0x2, %ebx
andl $0x3, %ebx
addl %ecx, %ebx
movl %r15d, 0x10(%rsp)
cmpl %r15d, %ebx
jg 0x1ab63
leaq 0x3ec621(%rip), %rax    # 0x406fec
movl (%rax), %r9d
leaq 0x15ec2b(%rip), %r14    # 0x179600
movzbl %sil, %eax
movl %eax, 0x14(%rsp)
leaq 0x19d06c(%rip), %r15    # 0x1b7a50
movl %r9d, 0xc(%rsp)
movl %ebx, %eax
subl 0x15e7d7(%rip), %eax    # 0x1791c8
shll $0xe, %eax
movl 0x8860a(%rip), %esi     # 0xa3004
cltd
idivl %esi
movl %eax, %ecx
addl 0x11234f(%rip), %ecx    # 0x12cd54
movl $0x0, 0x15ebf1(%rip)    # 0x179600
movw $0x1, %bp
cmpw %r12w, 0xa(%rsp)
jg 0x1aac3
movl 0x11232b(%rip), %edi    # 0x12cd50
movw $0x1, %bp
movl 0x15e794(%rip), %r8d    # 0x1791c4
movzwl 0xa(%rsp), %eax
movl %eax, %r9d
movswq %r9w, %rax
shlq $0x5, %rax
movl (%r15,%rax), %r13d
movl 0x4(%r15,%rax), %r11d
movswq 0x8(%r15,%rax), %rax
shlq $0x5, %rax
movl (%r15,%rax), %r10d
movl 0x4(%r15,%rax), %eax
cmpl %eax, %r11d
jle 0x1aa69
movl %r11d, %edx
movl %r13d, %r11d
jmp 0x1aa74
movl %eax, %edx
movl %r11d, %eax
movl %r10d, %r11d
movl %r13d, %r10d
cmpl %ecx, %edx
jle 0x1aab6
movl %ecx, %r13d
subl %eax, %r13d
jl 0x1aab6
subl %r10d, %r11d
subl %eax, %edx
movslq %r13d, %r13
movslq %r11d, %rax
imulq %r13, %rax
movslq %edx, %r11
cqto
idivq %r11
addl %r10d, %eax
subl %edi, %eax
imull %esi, %eax
sarl $0xe, %eax
addl %r8d, %eax
js 0x1aab6
movswq %bp, %rdx
leal 0x1(%rbp), %r10d
movl %eax, (%r14,%rdx,4)
movl %r10d, %ebp
incl %r9d
cmpw %r12w, %r9w
jle 0x1aa38
testw %bp, %bp
movl 0xc(%rsp), %r9d
jle 0x1ab56
cmpw $0x1, %bp
je 0x1ab08
movzwl %bp, %eax
movl $0x1, %ecx
movq %rcx, %rdx
movq %r14, %rsi
movl (%r14,%rcx,4), %edi
movl (%rsi), %r8d
cmpl %r8d, %edi
jge 0x1aaf7
movl %r8d, (%r14,%rcx,4)
movl %edi, (%rsi)
addq $0x4, %rsi
decq %rdx
jne 0x1aae5
incq %rcx
cmpq %rax, %rcx
jne 0x1aadf
movl %ebp, %eax
andl $0x1, %eax
decl %ebp
cmpw %bp, %ax
jge 0x1ab56
movzwl %ax, %ecx
movswq %ax, %r13
cmpl %r9d, (%r14,%r13,4)
jg 0x1ab56
cmpl %r9d, 0x4(%r14,%rcx,4)
jle 0x1ab2d
movl %r9d, 0x4(%r14,%rcx,4)
movl (%r14,%r13,4), %edi
movl 0x4(%r14,%rcx,4), %edx
movl %ebx, %esi
movl %ebx, %ecx
movl 0x14(%rsp), %r8d
callq 0x18db3
movl 0xc(%rsp), %r9d
leal 0x2(%r13), %eax
movswq %ax, %rcx
cmpw %bp, %ax
jl 0x1ab17
addl $0x3, %ebx
cmpl 0x10(%rsp), %ebx
jle 0x1a9e9
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq