// File: /workspace/github_c_makefile_star2_O2/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 0x18ed2
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x3e837e(%rip), %rax    # 0x400fec
movl (%rax), %eax
movl %eax, 0x10(%rsp)
movl 0x10e0ee(%rip), %eax    # 0x126d68
leal -0x1(%rax), %r10d
movswq %di, %rcx
imulq $0x28, %rcx, %rcx
leaq 0x223dd3(%rip), %rdx    # 0x23ca60
movzwl (%rdx,%rcx), %r11d
movzwl 0x2(%rdx,%rcx), %r13d
addw %r11w, %r13w
decl %r13d
movl 0x10e0af(%rip), %edx    # 0x126d54
movl 0x84359(%rip), %edi     # 0x9d004
xorl %r8d, %r8d
movl 0x15a513(%rip), %r9d    # 0x1731c8
leaq 0x198d94(%rip), %r12    # 0x1b1a50
movl %r10d, 0x8(%rsp)
movl %r10d, %ecx
movw %r11w, 0xe(%rsp)
movl %r11d, %r10d
cmpw %r13w, %r10w
jg 0x18d2a
movswq %r10w, %rbx
shlq $0x5, %rbx
movl 0x4(%r12,%rbx), %r11d
subl %edx, %r11d
imull %edi, %r11d
sarl $0xe, %r11d
addl %r9d, %r11d
movswq 0x8(%r12,%rbx), %rbx
shlq $0x5, %rbx
movl 0x4(%r12,%rbx), %ebx
subl %edx, %ebx
imull %edi, %ebx
sarl $0xe, %ebx
addl %r9d, %ebx
cmpl %ecx, %r11d
cmovll %r11d, %ecx
cmpl %ecx, %ebx
cmovll %ebx, %ecx
cmpl %r8d, %r11d
cmovlel %r8d, %r11d
cmpl %r11d, %ebx
cmovgl %ebx, %r11d
incl %r10d
movl %r11d, %r8d
jmp 0x18ccd
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
cmpl %eax, %r8d
movl 0x8(%rsp), %eax
cmovll %r8d, %eax
movl %eax, 0x8(%rsp)
leaq 0x38c7a1(%rip), %rax    # 0x3a54e8
movl (%rax), %ebx
shrl $0x2, %ebx
andl $0x3, %ebx
addl %ecx, %ebx
leaq 0x15a8a8(%rip), %r15    # 0x173600
movzbl %sil, %eax
movl %eax, 0x14(%rsp)
cmpl 0x8(%rsp), %ebx
jg 0x18ec4
movl %ebx, %eax
subl 0x15a456(%rip), %eax    # 0x1731c8
shll $0xe, %eax
movl 0x84289(%rip), %esi     # 0x9d004
cltd
idivl %esi
movl %eax, %ecx
addl 0x10dfce(%rip), %ecx    # 0x126d54
andl $0x0, 0x15a873(%rip)    # 0x173600
movl 0x10dfbd(%rip), %edi    # 0x126d50
movw $0x1, %bp
movl 0x15a426(%rip), %r8d    # 0x1731c4
movzwl 0xe(%rsp), %eax
movl %eax, %r9d
cmpw %r13w, %r9w
jg 0x18e36
movswq %r9w, %rax
shlq $0x5, %rax
movl (%r12,%rax), %r14d
movl 0x4(%r12,%rax), %r11d
movswq 0x8(%r12,%rax), %rax
shlq $0x5, %rax
movl (%r12,%rax), %r10d
movl 0x4(%r12,%rax), %eax
cmpl %eax, %r11d
jle 0x18de1
movl %r11d, %edx
movl %r14d, %r11d
jmp 0x18dec
movl %eax, %edx
movl %r11d, %eax
movl %r10d, %r11d
movl %r14d, %r10d
cmpl %ecx, %edx
jle 0x18e2e
movl %ecx, %r14d
subl %eax, %r14d
jl 0x18e2e
subl %r10d, %r11d
subl %eax, %edx
movslq %r14d, %r14
movslq %r11d, %rax
imulq %r14, %rax
movslq %edx, %r11
cqto
idivq %r11
addl %r10d, %eax
subl %edi, %eax
imull %esi, %eax
sarl $0xe, %eax
addl %r8d, %eax
js 0x18e2e
movswq %bp, %rdx
leal 0x1(%rbp), %r10d
movl %eax, (%r15,%rdx,4)
movl %r10d, %ebp
incl %r9d
jmp 0x18da6
testw %bp, %bp
movl 0x10(%rsp), %r9d
jle 0x18ebc
movzwl %bp, %eax
pushq $0x4
popq %rcx
pushq $0x1
popq %rdx
cmpq %rax, %rdx
je 0x18e79
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x18e70
movl (%r15,%rdx,4), %edi
movl (%rsi,%r15), %r8d
cmpl %r8d, %edi
jge 0x18e6a
movl %r8d, (%r15,%rdx,4)
movl %edi, (%rsi,%r15)
addq $0x4, %rsi
jmp 0x18e50
incq %rdx
addq $0x4, %rcx
jmp 0x18e49
leal -0x1(%rbp), %eax
andl $0x1, %ebp
movswq %ax, %r14
cmpq %r14, %rbp
jge 0x18ebc
movl (%r15,%rbp,4), %edi
cmpl %r9d, %edi
jg 0x18ebc
movl 0x4(%r15,%rbp,4), %edx
cmpl %r9d, %edx
jle 0x18ea3
movl %r9d, 0x4(%r15,%rbp,4)
movl %r9d, %edx
movl %ebx, %esi
movl %ebx, %ecx
movl 0x14(%rsp), %r8d
callq 0x1737f
movl 0x10(%rsp), %r9d
addq $0x2, %rbp
jmp 0x18e83
addl $0x3, %ebx
jmp 0x18d60
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq