// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: fillpolygon
static void fillpolygon(int npoints)
{
	int z, zz, x1, y1, x2, y2, miny, maxy, y, xinc, cnt;
	int ox, oy, bx, by, day1, day2;
	intptr_t p;
	short *ptr, *ptr2;

#if USE_POLYMOST && USE_OPENGL
	if (rendmode == 3) { polymost_fillpolygon(npoints); return; }
#endif

	miny = 0x7fffffff; maxy = 0x80000000;
	for(z=npoints-1;z>=0;z--)
		{ y = ry1[z]; miny = min(miny,y); maxy = max(maxy,y); }
	miny = (miny>>12); maxy = (maxy>>12);
	if (miny < 0) miny = 0;
	if (maxy >= ydim) maxy = ydim-1;
	ptr = smost;    //They're pointers! - watch how you optimize this thing
	for(y=miny;y<=maxy;y++)
	{
		dotp1[y] = ptr; dotp2[y] = ptr+(MAXNODESPERLINE>>1);
		ptr += MAXNODESPERLINE;
	}

	for(z=npoints-1;z>=0;z--)
	{
		zz = xb1[z];
		y1 = ry1[z]; day1 = (y1>>12);
		y2 = ry1[zz]; day2 = (y2>>12);
		if (day1 != day2)
		{
			x1 = rx1[z]; x2 = rx1[zz];
			xinc = divscale12(x2-x1,y2-y1);
			if (day2 > day1)
			{
				x1 += mulscale12((day1<<12)+4095-y1,xinc);
				for(y=day1;y<day2;y++) { *dotp2[y]++ = (x1>>12); x1 += xinc; }
			}
			else
			{
				x2 += mulscale12((day2<<12)+4095-y2,xinc);
				for(y=day2;y<day1;y++) { *dotp1[y]++ = (x2>>12); x2 += xinc; }
			}
		}
	}

	globalx1 = mulscale16(globalx1,xyaspect);
	globaly2 = mulscale16(globaly2,xyaspect);

	oy = miny+1-(ydim>>1);
	globalposx += oy*globalx1;
	globalposy += oy*globaly2;

	setuphlineasm4(asm1,asm2);

	ptr = smost;
	for(y=miny;y<=maxy;y++)
	{
		cnt = (int)(dotp1[y]-ptr); ptr2 = ptr+(MAXNODESPERLINE>>1);
		for(z=cnt-1;z>=0;z--)
		{
			day1 = 0; day2 = 0;
			for(zz=z;zz>0;zz--)
			{
				if (ptr[zz] < ptr[day1]) day1 = zz;
				if (ptr2[zz] < ptr2[day2]) day2 = zz;
			}
			x1 = ptr[day1]; ptr[day1] = ptr[z];
			x2 = ptr2[day2]-1; ptr2[day2] = ptr2[z];
			if (x1 > x2) continue;

			if (globalpolytype < 1)
			{
					//maphline
				ox = x2+1-(xdim>>1);
				bx = ox*asm1 + globalposx;
				by = ox*asm2 - globalposy;

				p = ylookup[y]+x2+frameplace;
				hlineasm4(x2-x1,-1L,globalshade<<8,by,bx,(void *)p);
			}
			else
			{
					//maphline
				ox = x1+1-(xdim>>1);
				bx = ox*asm1 + globalposx;
				by = ox*asm2 - globalposy;

				p = ylookup[y]+x1+frameplace;
				if (globalpolytype == 1)
					mhline((void *)globalbufplc,bx,(x2-x1)<<16,0L,by,(void *)p);
				else
				{
					thline((void *)globalbufplc,bx,(x2-x1)<<16,0L,by,(void *)p);
				}
			}
		}
		globalposx += globalx1;
		globalposy += globaly2;
		ptr += MAXNODESPERLINE;
	}
	faketimerhandler();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0x4(%rbp)
leaq 0x5a883e(%rip), %rax    # 0x5ed920
cmpl $0x3, (%rax)
jne 0x450f4
movl -0x4(%rbp), %edi
callq 0x88990
jmp 0x456b8
movl $0x7fffffff, -0x20(%rbp) # imm = 0x7FFFFFFF
movl $0x80000000, -0x24(%rbp) # imm = 0x80000000
movl -0x4(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x8(%rbp)
cmpl $0x0, -0x8(%rbp)
jl 0x45165
movslq -0x8(%rbp), %rcx
leaq 0x401c44(%rip), %rax    # 0x446d60
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x45132
movl -0x20(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x45138
movl -0x28(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jle 0x4514e
movl -0x24(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x45154
movl -0x28(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x4510b
movl -0x20(%rbp), %eax
sarl $0xc, %eax
movl %eax, -0x20(%rbp)
movl -0x24(%rbp), %eax
sarl $0xc, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x45184
movl $0x0, -0x20(%rbp)
movl -0x24(%rbp), %eax
cmpl 0x3fdbc3(%rip), %eax    # 0x442d50
jl 0x4519b
movl 0x3fdbbb(%rip), %eax    # 0x442d50
subl $0x1, %eax
movl %eax, -0x24(%rbp)
leaq 0x4a0f3e(%rip), %rax    # 0x4e60e0
movq %rax, -0x58(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jg 0x451f5
movq -0x58(%rbp), %rdx
movslq -0x28(%rbp), %rcx
leaq 0x55c87d(%rip), %rax    # 0x5a1a40
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rdx
addq $0x2a, %rdx
movslq -0x28(%rbp), %rcx
leaq 0x5600a6(%rip), %rax    # 0x5a5280
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rax
addq $0x54, %rax
movq %rax, -0x58(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x451ac
movl -0x4(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x8(%rbp)
cmpl $0x0, -0x8(%rbp)
jl 0x45385
movslq -0x8(%rbp), %rcx
leaq 0x2633bd(%rip), %rax    # 0x2a85d0
movl (%rax,%rcx,4), %eax
movl %eax, -0xc(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x401b3c(%rip), %rax    # 0x446d60
movl (%rax,%rcx,4), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
sarl $0xc, %eax
movl %eax, -0x44(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0x401b22(%rip), %rax    # 0x446d60
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
sarl $0xc, %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
je 0x45375
movslq -0x8(%rbp), %rcx
leaq 0x3fdafc(%rip), %rax    # 0x442d60
movl (%rax,%rcx,4), %eax
movl %eax, -0x10(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0x3fdaeb(%rip), %rax    # 0x442d60
movl (%rax,%rcx,4), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %edi
subl -0x10(%rbp), %edi
movl -0x1c(%rbp), %esi
subl -0x14(%rbp), %esi
callq 0x59a10
movl %eax, -0x2c(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jle 0x45305
movl -0x44(%rbp), %edi
shll $0xc, %edi
addl $0xfff, %edi            # imm = 0xFFF
subl -0x14(%rbp), %edi
movl -0x2c(%rbp), %esi
callq 0x450b0
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x45303
movl -0x10(%rbp), %eax
sarl $0xc, %eax
movw %ax, %cx
movslq -0x28(%rbp), %rsi
leaq 0x55ffaa(%rip), %rax    # 0x5a5280
movq (%rax,%rsi,8), %rax
movq %rax, %rdi
addq $0x2, %rdi
leaq 0x55ff98(%rip), %rdx    # 0x5a5280
movq %rdi, (%rdx,%rsi,8)
movw %cx, (%rax)
movl -0x2c(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x452ba
jmp 0x45373
movl -0x48(%rbp), %edi
shll $0xc, %edi
addl $0xfff, %edi            # imm = 0xFFF
subl -0x1c(%rbp), %edi
movl -0x2c(%rbp), %esi
callq 0x450b0
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x45371
movl -0x18(%rbp), %eax
sarl $0xc, %eax
movw %ax, %cx
movslq -0x28(%rbp), %rsi
leaq 0x55c6fc(%rip), %rax    # 0x5a1a40
movq (%rax,%rsi,8), %rax
movq %rax, %rdi
addq $0x2, %rdi
leaq 0x55c6ea(%rip), %rdx    # 0x5a1a40
movq %rdi, (%rdx,%rsi,8)
movw %cx, (%rax)
movl -0x2c(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x45328
jmp 0x45373
jmp 0x45375
jmp 0x45377
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x451fe
movl 0x40a20d(%rip), %edi    # 0x44f598
movl 0x355087(%rip), %esi    # 0x39a418
callq 0x39010
movl %eax, 0x40a1fc(%rip)    # 0x44f598
movl 0x40a202(%rip), %edi    # 0x44f5a4
movl 0x355070(%rip), %esi    # 0x39a418
callq 0x39010
movl %eax, 0x40a1f1(%rip)    # 0x44f5a4
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl 0x3fd991(%rip), %ecx    # 0x442d50
sarl %ecx
subl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
imull 0x40a1c8(%rip), %eax    # 0x44f598
addl 0x2321da(%rip), %eax    # 0x2775b0
movl %eax, 0x2321d4(%rip)    # 0x2775b0
movl -0x38(%rbp), %eax
imull 0x40a1be(%rip), %eax    # 0x44f5a4
addl 0x2321c8(%rip), %eax    # 0x2775b4
movl %eax, 0x2321c2(%rip)    # 0x2775b4
movl 0x40c5bc(%rip), %edi    # 0x4519b4
movl 0x40c5ba(%rip), %esi    # 0x4519b8
callq 0xa7600
leaq 0x4a0cd6(%rip), %rax    # 0x4e60e0
movq %rax, -0x58(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jg 0x456b3
movslq -0x28(%rbp), %rcx
leaq 0x55c615(%rip), %rax    # 0x5a1a40
movq (%rax,%rcx,8), %rax
movq -0x58(%rbp), %rcx
subq %rcx, %rax
sarq %rax
movl %eax, -0x30(%rbp)
movq -0x58(%rbp), %rax
addq $0x2a, %rax
movq %rax, -0x60(%rbp)
movl -0x30(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x8(%rbp)
cmpl $0x0, -0x8(%rbp)
jl 0x45675
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jle 0x454c6
movq -0x58(%rbp), %rax
movslq -0xc(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movq -0x58(%rbp), %rcx
movslq -0x44(%rbp), %rdx
movswl (%rcx,%rdx,2), %ecx
cmpl %ecx, %eax
jge 0x45497
movl -0xc(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x60(%rbp), %rax
movslq -0xc(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movq -0x60(%rbp), %rcx
movslq -0x48(%rbp), %rdx
movswl (%rcx,%rdx,2), %ecx
cmpl %ecx, %eax
jge 0x454b9
movl -0xc(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x454bb
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x4546f
movq -0x58(%rbp), %rax
movslq -0x44(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movl %eax, -0x10(%rbp)
movq -0x58(%rbp), %rax
movslq -0x8(%rbp), %rcx
movw (%rax,%rcx,2), %dx
movq -0x58(%rbp), %rax
movslq -0x44(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movq -0x60(%rbp), %rax
movslq -0x48(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
subl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x60(%rbp), %rax
movslq -0x8(%rbp), %rcx
movw (%rax,%rcx,2), %dx
movq -0x60(%rbp), %rax
movslq -0x48(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movl -0x10(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0x45524
jmp 0x45667
movzbl 0x40a069(%rip), %eax    # 0x44f594
cmpl $0x1, %eax
jge 0x455b7
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl 0x3fd80c(%rip), %ecx    # 0x442d4c
sarl %ecx
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
imull 0x40c463(%rip), %eax    # 0x4519b4
addl 0x232059(%rip), %eax    # 0x2775b0
movl %eax, -0x3c(%rbp)
movl -0x34(%rbp), %eax
imull 0x40c454(%rip), %eax    # 0x4519b8
subl 0x23204a(%rip), %eax    # 0x2775b4
movl %eax, -0x40(%rbp)
movslq -0x28(%rbp), %rcx
leaq 0x40c508(%rip), %rax    # 0x451a80
movl (%rax,%rcx,4), %eax
addl -0x18(%rbp), %eax
cltq
leaq 0x175689(%rip), %rcx    # 0x1bac10
addq (%rcx), %rax
movq %rax, -0x50(%rbp)
movl -0x18(%rbp), %edi
subl -0x10(%rbp), %edi
movl 0x409ff2(%rip), %edx    # 0x44f58c
shll $0x8, %edx
movl -0x40(%rbp), %ecx
movl -0x3c(%rbp), %r8d
movq -0x50(%rbp), %r9
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xa7620
jmp 0x45665
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl 0x3fd789(%rip), %ecx    # 0x442d4c
sarl %ecx
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
imull 0x40c3e0(%rip), %eax    # 0x4519b4
addl 0x231fd6(%rip), %eax    # 0x2775b0
movl %eax, -0x3c(%rbp)
movl -0x34(%rbp), %eax
imull 0x40c3d1(%rip), %eax    # 0x4519b8
subl 0x231fc7(%rip), %eax    # 0x2775b4
movl %eax, -0x40(%rbp)
movslq -0x28(%rbp), %rcx
leaq 0x40c485(%rip), %rax    # 0x451a80
movl (%rax,%rcx,4), %eax
addl -0x10(%rbp), %eax
cltq
leaq 0x175606(%rip), %rcx    # 0x1bac10
addq (%rcx), %rax
movq %rax, -0x50(%rbp)
movzbl 0x409f7c(%rip), %eax    # 0x44f594
cmpl $0x1, %eax
jne 0x45641
movq 0x409f5c(%rip), %rdi    # 0x44f580
movl -0x3c(%rbp), %esi
movl -0x18(%rbp), %edx
subl -0x10(%rbp), %edx
shll $0x10, %edx
movl -0x40(%rbp), %r8d
movq -0x50(%rbp), %r9
xorl %ecx, %ecx
callq 0xa7bb0
jmp 0x45663
movq 0x409f38(%rip), %rdi    # 0x44f580
movl -0x3c(%rbp), %esi
movl -0x18(%rbp), %edx
subl -0x10(%rbp), %edx
shll $0x10, %edx
movl -0x40(%rbp), %r8d
movq -0x50(%rbp), %r9
xorl %ecx, %ecx
callq 0xa7cc0
jmp 0x45665
jmp 0x45667
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x45451
movl 0x409f1d(%rip), %eax    # 0x44f598
addl 0x231f2f(%rip), %eax    # 0x2775b0
movl %eax, 0x231f29(%rip)    # 0x2775b0
movl 0x409f17(%rip), %eax    # 0x44f5a4
addl 0x231f21(%rip), %eax    # 0x2775b4
movl %eax, 0x231f1b(%rip)    # 0x2775b4
movq -0x58(%rbp), %rax
addq $0x54, %rax
movq %rax, -0x58(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x45414
callq 0xc220
addq $0x70, %rsp
popq %rbp
retq
nop