// File: /workspace/github_c_makefile_star2_O3/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 0x35b5ad(%rip), %rax    # 0x398ae0
movl %r8d, %edx
movb (%rax,%rdx), %al
movb %al, 0xb(%rsp)
movl %ecx, %r12d
subl %esi, %r12d
movl %ebx, %r13d
subl %edi, %r13d
movl 0x3f9044(%rip), %r11d   # 0x436594
js 0x3d587
cmpl %ebp, %r11d
jle 0x3d8a4
movl 0x3f902b(%rip), %edi    # 0x43658c
cmpl %ebx, %edi
jg 0x3d8a4
movl %edi, %eax
movl %r13d, %r8d
subl %ebp, %eax
jle 0x3d5be
movslq %eax, %rdx
movslq %r12d, %rax
imulq %rdx, %rax
cqto
idivq %r8
addl %esi, %eax
movl %eax, %esi
jmp 0x3d5c0
cmpl %ebx, %r11d
jle 0x3d8a4
movl 0x3f8ff5(%rip), %r10d   # 0x43658c
cmpl %ebp, %r10d
jg 0x3d8a4
movl %r10d, %eax
movslq %r12d, %r9
movslq %r13d, %r8
subl %ebx, %eax
jle 0x3d5e4
cltq
imulq %r9, %rax
cqto
idivq %r8
addl %ecx, %eax
movl %eax, %ecx
jmp 0x3d5e7
movl %ebp, %edi
movl %r11d, %eax
subl %ebx, %eax
jge 0x3d5df
movslq %eax, %rdx
movslq %r12d, %rax
imulq %rdx, %rax
cqto
idivq %r8
addl %ecx, %eax
movl %r11d, %r10d
movl %eax, %ecx
jmp 0x3d604
movl %ebx, %r10d
jmp 0x3d604
movl %ebx, %r10d
movl %r11d, %eax
subl %ebp, %eax
jge 0x3d602
cltq
imulq %r9, %rax
cqto
idivq %r8
addl %esi, %eax
movl %eax, %esi
movl %r11d, %edi
jmp 0x3d604
movl %ebp, %edi
movl 0x3f8f8d(%rip), %r11d   # 0x436598
testl %r12d, %r12d
js 0x3d646
cmpl %esi, %r11d
jle 0x3d8a4
movl 0x3f8f70(%rip), %r15d   # 0x436590
cmpl %r15d, %ecx
jl 0x3d8a4
movl %r15d, %eax
movl %r12d, %r8d
subl %esi, %eax
jle 0x3d67d
movslq %eax, %rdx
movslq %r13d, %rax
imulq %rdx, %rax
cqto
idivq %r8
addl %eax, %edi
jmp 0x3d680
cmpl %ecx, %r11d
jle 0x3d8a4
movl 0x3f8f3a(%rip), %r14d   # 0x436590
cmpl %r14d, %esi
jl 0x3d8a4
movl %r14d, %eax
subl %ecx, %eax
jle 0x3d6a3
movslq %eax, %rcx
movslq %r13d, %rax
imulq %rcx, %rax
movslq %r12d, %rcx
cqto
idivq %rcx
addl %eax, %r10d
jmp 0x3d6a6
movl %esi, %r15d
movl %r11d, %eax
subl %ecx, %eax
jge 0x3d69e
movslq %eax, %rcx
movslq %r13d, %rax
imulq %rcx, %rax
cqto
idivq %r8
addl %eax, %r10d
movl %r11d, %r14d
jmp 0x3d6c9
movl %ecx, %r14d
jmp 0x3d6c9
movl %ecx, %r14d
movl %r11d, %eax
subl %esi, %eax
jge 0x3d6c6
movslq %eax, %rcx
movslq %r13d, %rax
imulq %rcx, %rax
movslq %r12d, %rcx
cqto
idivq %rcx
addl %eax, %edi
movl %r11d, %r15d
jmp 0x3d6c9
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 0x5e0e1
movl 0xc(%rsp), %r11d
movq %r14, %r10
movq 0x10(%rsp), %r14
testl %eax, %eax
je 0x3d8a4
movl %r13d, %eax
negl %eax
cmovsl %r13d, %eax
movl %r12d, %ecx
negl %ecx
cmovsl %r12d, %ecx
cmpl %ecx, %eax
jae 0x3d7de
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 0x3d8a4
leaq 0x140952(%rip), %rdi    # 0x17e0b0
movslq %edx, %rsi
leaq 0x3d9538(%rip), %r9     # 0x416ca0
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 0x3927d7(%rip), %r8     # 0x3cff70
leaq 0x3945e0(%rip), %r9     # 0x3d1d80
movl %edi, %r10d
sarl $0xc, %r10d
movslq %r10d, %r10
movswl (%r8,%r10,2), %r11d
cmpl %r11d, %edx
jl 0x3d7c7
movswl (%r9,%r10,2), %r11d
cmpl %r11d, %edx
jge 0x3d7c7
movb 0xb(%rsp), %r11b
movb %r11b, (%rsi,%r10)
addl %eax, %edi
movslq 0x3d94d4(%rip), %r10    # 0x416ca4
addq %r10, %rsi
incl %edx
cmpl %edx, %ecx
jne 0x3d7a0
jmp 0x3d8a4
cmpl %ebp, %ebx
je 0x3d8a4
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 0x3d8a4
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 0x392719(%rip), %r8     # 0x3cff70
leaq 0x394522(%rip), %r9     # 0x3d1d80
leaq 0x14084b(%rip), %r10    # 0x17e0b0
leaq 0x3d9434(%rip), %r11    # 0x416ca0
movl %ecx, %ebx
sarl $0xc, %ebx
movswl (%rdi,%r8), %ebp
cmpl %ebp, %ebx
jl 0x3d896
movswl (%rdi,%r9), %ebp
cmpl %ebp, %ebx
jge 0x3d896
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 0x3d86c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq