// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: drawline256
void drawline256(int x1, int y1, int x2, int y2, unsigned char col)
{
	int dx, dy, i, j, inc, daend, plc;
	intptr_t p;

	col = palookup[0][col];

	dx = x2-x1; dy = y2-y1;
	if (dx >= 0)
	{
		if ((x1 >= wx2) || (x2 < wx1)) return;
		if (x1 < wx1) y1 += scale(wx1-x1,dy,dx), x1 = wx1;
		if (x2 > wx2) y2 += scale(wx2-x2,dy,dx), x2 = wx2;
	}
	else
	{
		if ((x2 >= wx2) || (x1 < wx1)) return;
		if (x2 < wx1) y2 += scale(wx1-x2,dy,dx), x2 = wx1;
		if (x1 > wx2) y1 += scale(wx2-x1,dy,dx), x1 = wx2;
	}
	if (dy >= 0)
	{
		if ((y1 >= wy2) || (y2 < wy1)) return;
		if (y1 < wy1) x1 += scale(wy1-y1,dx,dy), y1 = wy1;
		if (y2 > wy2) x2 += scale(wy2-y2,dx,dy), y2 = wy2;
	}
	else
	{
		if ((y2 >= wy2) || (y1 < wy1)) return;
		if (y2 < wy1) x2 += scale(wy1-y2,dx,dy), y2 = wy1;
		if (y1 > wy2) x1 += scale(wy2-y1,dx,dy), y1 = wy2;
	}

#if USE_POLYMOST && USE_OPENGL
	if (!polymost_drawline256(x1,y1,x2,y2,col)) return;
#endif

	if (klabs(dx) >= klabs(dy))
	{
		if (dx == 0) return;
		if (dx < 0)
		{
			i = x1; x1 = x2; x2 = i;
			i = y1; y1 = y2; y2 = i;
			x1+=4096; x2+=4096;
		}

		inc = divscale12(dy,dx);
		plc = y1+mulscale12((2047-x1)&4095,inc);
		i = ((x1+2048)>>12); daend = ((x2+2048)>>12);

		for(;i<daend;i++)
		{
			j = (plc>>12);
			if ((j >= startumost[i]) && (j < startdmost[i]))
				drawpixel((void*)(frameplace+ylookup[j]+i),col);
			plc += inc;
		}
	}
	else
	{
		if (dy < 0)
		{
			i = x1; x1 = x2; x2 = i;
			i = y1; y1 = y2; y2 = i;
			y1+=4096; y2+=4096;
		}

		inc = divscale12(dx,dy);
		plc = x1+mulscale12((2047-y1)&4095,inc);
		i = ((y1+2048)>>12); daend = ((y2+2048)>>12);

		p = ylookup[i]+frameplace;
		for(;i<daend;i++)
		{
			j = (plc>>12);
			if ((i >= startumost[j]) && (i < startdmost[j]))
				drawpixel((void*)(j+p),col);
			plc += inc; p += ylookup[1];
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebx
movl %edi, %ebp
movq 0x35ba2d(%rip), %rax    # 0x397ae0
movl %r8d, %edx
movb (%rax,%rdx), %al
movb %al, 0xb(%rsp)
movl %ecx, %r12d
subl %esi, %r12d
movl %ebx, %r13d
subl %edi, %r13d
movl 0x3f94c4(%rip), %r11d   # 0x435594
js 0x3c107
cmpl %ebp, %r11d
jle 0x3c424
movl 0x3f94ab(%rip), %edi    # 0x43558c
cmpl %ebx, %edi
jg 0x3c424
movl %edi, %eax
movl %r13d, %r8d
subl %ebp, %eax
jle 0x3c13e
movslq %eax, %rdx
movslq %r12d, %rax
imulq %rdx, %rax
cqto
idivq %r8
addl %esi, %eax
movl %eax, %esi
jmp 0x3c140
cmpl %ebx, %r11d
jle 0x3c424
movl 0x3f9475(%rip), %r10d   # 0x43558c
cmpl %ebp, %r10d
jg 0x3c424
movl %r10d, %eax
movslq %r12d, %r9
movslq %r13d, %r8
subl %ebx, %eax
jle 0x3c164
cltq
imulq %r9, %rax
cqto
idivq %r8
addl %ecx, %eax
movl %eax, %ecx
jmp 0x3c167
movl %ebp, %edi
movl %r11d, %eax
subl %ebx, %eax
jge 0x3c15f
movslq %eax, %rdx
movslq %r12d, %rax
imulq %rdx, %rax
cqto
idivq %r8
addl %ecx, %eax
movl %r11d, %r10d
movl %eax, %ecx
jmp 0x3c184
movl %ebx, %r10d
jmp 0x3c184
movl %ebx, %r10d
movl %r11d, %eax
subl %ebp, %eax
jge 0x3c182
cltq
imulq %r9, %rax
cqto
idivq %r8
addl %esi, %eax
movl %eax, %esi
movl %r11d, %edi
jmp 0x3c184
movl %ebp, %edi
movl 0x3f940d(%rip), %r11d   # 0x435598
testl %r12d, %r12d
js 0x3c1c6
cmpl %esi, %r11d
jle 0x3c424
movl 0x3f93f0(%rip), %r15d   # 0x435590
cmpl %r15d, %ecx
jl 0x3c424
movl %r15d, %eax
movl %r12d, %r8d
subl %esi, %eax
jle 0x3c1fd
movslq %eax, %rdx
movslq %r13d, %rax
imulq %rdx, %rax
cqto
idivq %r8
addl %eax, %edi
jmp 0x3c200
cmpl %ecx, %r11d
jle 0x3c424
movl 0x3f93ba(%rip), %r14d   # 0x435590
cmpl %r14d, %esi
jl 0x3c424
movl %r14d, %eax
subl %ecx, %eax
jle 0x3c223
movslq %eax, %rcx
movslq %r13d, %rax
imulq %rcx, %rax
movslq %r12d, %rcx
cqto
idivq %rcx
addl %eax, %r10d
jmp 0x3c226
movl %esi, %r15d
movl %r11d, %eax
subl %ecx, %eax
jge 0x3c21e
movslq %eax, %rcx
movslq %r13d, %rax
imulq %rcx, %rax
cqto
idivq %r8
addl %eax, %r10d
movl %r11d, %r14d
jmp 0x3c249
movl %ecx, %r14d
jmp 0x3c249
movl %ecx, %r14d
movl %r11d, %eax
subl %esi, %eax
jge 0x3c246
movslq %eax, %rcx
movslq %r13d, %rax
imulq %rcx, %rax
movslq %r12d, %rcx
cqto
idivq %rcx
addl %eax, %edi
movl %r11d, %r15d
jmp 0x3c249
movl %esi, %r15d
movq %r14, 0x10(%rsp)
movl %edi, 0xc(%rsp)
movzbl 0xb(%rsp), %r8d
movl %r15d, %esi
movl %r10d, %edx
movl %r14d, %ecx
movq %r10, %r14
callq 0x5bf7f
movl 0xc(%rsp), %r11d
movq %r14, %r10
movq 0x10(%rsp), %r14
testl %eax, %eax
je 0x3c424
movl %r13d, %eax
negl %eax
cmovsl %r13d, %eax
movl %r12d, %ecx
negl %ecx
cmovsl %r12d, %ecx
cmpl %ecx, %eax
jae 0x3c35e
movl $0x1000, %ecx           # imm = 0x1000
leal (%r14,%rcx), %r8d
addl %r15d, %ecx
testl %r12d, %r12d
cmovnsl %r14d, %ecx
cmovnsl %r15d, %r8d
movslq %r13d, %rax
shlq $0xc, %rax
movslq %r12d, %rsi
cqto
idivq %rsi
movl $0x800, %esi            # imm = 0x800
leal (%r8,%rsi), %edx
sarl $0xc, %edx
addl %esi, %ecx
sarl $0xc, %ecx
cmpl %ecx, %edx
jge 0x3c424
leaq 0x140dd2(%rip), %rdi    # 0x17d0b0
movslq %edx, %rsi
leaq 0x3d99b8(%rip), %r9     # 0x415ca0
movslq (%r9,%rsi,4), %rsi
addq (%rdi), %rsi
testl %r12d, %r12d
cmovsl %r10d, %r11d
movslq %eax, %r9
movl $0x7ff, %edi            # imm = 0x7FF
subl %r8d, %edi
andl $0xfff, %edi            # imm = 0xFFF
imulq %r9, %rdi
shrq $0xc, %rdi
addl %r11d, %edi
leaq 0x392c57(%rip), %r8     # 0x3cef70
leaq 0x394a60(%rip), %r9     # 0x3d0d80
movl %edi, %r10d
sarl $0xc, %r10d
movslq %r10d, %r10
movswl (%r8,%r10,2), %r11d
cmpl %r11d, %edx
jl 0x3c347
movswl (%r9,%r10,2), %r11d
cmpl %r11d, %edx
jge 0x3c347
movb 0xb(%rsp), %r11b
movb %r11b, (%rsi,%r10)
addl %eax, %edi
movslq 0x3d9954(%rip), %r10    # 0x415ca4
addq %r10, %rsi
incl %edx
cmpl %edx, %ecx
jne 0x3c320
jmp 0x3c424
cmpl %ebp, %ebx
je 0x3c424
movl $0x1000, %esi           # imm = 0x1000
leal (%r10,%rsi), %edi
addl %r11d, %esi
testl %r13d, %r13d
cmovnsl %r10d, %esi
cmovnsl %r11d, %edi
movslq %r12d, %rax
shlq $0xc, %rax
movslq %r13d, %rcx
cqto
idivq %rcx
movl $0x800, %ecx            # imm = 0x800
leal (%rdi,%rcx), %edx
sarl $0xc, %edx
addl %ecx, %esi
sarl $0xc, %esi
cmpl %esi, %edx
jge 0x3c424
testl %r13d, %r13d
cmovsl %r14d, %r15d
movslq %eax, %r8
movl $0x7ff, %ecx            # imm = 0x7FF
subl %edi, %ecx
andl $0xfff, %ecx            # imm = 0xFFF
imulq %r8, %rcx
shrq $0xc, %rcx
addl %r15d, %ecx
movslq %edx, %rdx
movslq %esi, %rsi
leaq (%rdx,%rdx), %rdi
leaq 0x392b99(%rip), %r8     # 0x3cef70
leaq 0x3949a2(%rip), %r9     # 0x3d0d80
leaq 0x140ccb(%rip), %r10    # 0x17d0b0
leaq 0x3d98b4(%rip), %r11    # 0x415ca0
movl %ecx, %ebx
sarl $0xc, %ebx
movswl (%rdi,%r8), %ebp
cmpl %ebp, %ebx
jl 0x3c416
movswl (%rdi,%r9), %ebp
cmpl %ebp, %ebx
jge 0x3c416
movslq %ebx, %rbx
movslq (%r11,%rbx,4), %rbx
addq (%r10), %rbx
movb 0xb(%rsp), %bpl
movb %bpl, (%rdx,%rbx)
addl %eax, %ecx
incq %rdx
addq $0x2, %rdi
cmpq %rdx, %rsi
jne 0x3c3ec
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq