// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movl %edx, %r13d
movl %edi, %r15d
movq 0x35838a(%rip), %rax    # 0x391ae0
movl %r8d, %edx
movb (%rax,%rdx), %al
movb %al, 0xf(%rsp)
movl %ecx, %ebx
subl %esi, %ebx
movl %r13d, %ebp
subl %edi, %ebp
movl 0x3f5e24(%rip), %r14d   # 0x42f594
movslq %ebp, %r9
movslq %ebx, %r11
js 0x397ab
cmpl %r15d, %r14d
jle 0x399e8
movl 0x3f5e05(%rip), %edi    # 0x42f58c
cmpl %r13d, %edi
jg 0x399e8
movl %edi, %eax
movl %ebp, %r8d
subl %r15d, %eax
jle 0x397dd
cltq
imulq %r11, %rax
cqto
idivq %r8
addl %esi, %eax
movl %eax, %esi
jmp 0x397e0
cmpl %r13d, %r14d
jle 0x399e8
movl 0x3f5dd1(%rip), %r10d   # 0x42f58c
cmpl %r15d, %r10d
jg 0x399e8
movl %r10d, %eax
subl %r13d, %eax
jle 0x39801
cltq
imulq %r11, %rax
cqto
idivq %r9
addl %ecx, %eax
movl %eax, %ecx
jmp 0x39804
movl %r15d, %edi
movl %r14d, %eax
subl %r13d, %eax
jge 0x397fc
cltq
imulq %r11, %rax
cqto
idivq %r8
addl %ecx, %eax
movl %r14d, %r10d
movl %eax, %ecx
jmp 0x39823
movl %r13d, %r10d
jmp 0x39823
movl %r13d, %r10d
movl %r14d, %eax
subl %r15d, %eax
jge 0x39820
cltq
imulq %r11, %rax
cqto
idivq %r9
addl %esi, %eax
movl %eax, %esi
movl %r14d, %edi
jmp 0x39823
movl %r15d, %edi
movl 0x3f5d6e(%rip), %r12d   # 0x42f598
testl %ebx, %ebx
js 0x39860
cmpl %esi, %r12d
jle 0x399e8
movl 0x3f5d52(%rip), %r14d   # 0x42f590
cmpl %r14d, %ecx
jl 0x399e8
movl %r14d, %eax
movl %ebx, %r8d
subl %esi, %eax
jle 0x39891
cltq
imulq %r9, %rax
cqto
idivq %r8
addl %eax, %edi
jmp 0x39894
cmpl %ecx, %r12d
jle 0x399e8
movl 0x3f5d21(%rip), %eax    # 0x42f590
cmpl %eax, %esi
jl 0x399e8
movq %rax, %r8
subl %ecx, %eax
jle 0x398ba
cltq
imulq %r9, %rax
cqto
idivq %r11
addl %eax, %r10d
movq %r8, %rcx
jmp 0x398ba
movl %esi, %r14d
movl %r12d, %eax
subl %ecx, %eax
movq %r9, 0x20(%rsp)
movq %r11, 0x18(%rsp)
jge 0x398b8
cltq
imulq %r9, %rax
cqto
idivq %r8
addl %eax, %r10d
movl %r12d, %ecx
jmp 0x398e0
jmp 0x398e0
movl %r12d, %eax
subl %esi, %eax
movq %r9, 0x20(%rsp)
movq %r11, 0x18(%rsp)
jge 0x398dd
cltq
imulq %r9, %rax
cqto
idivq %r11
addl %eax, %edi
movl %r12d, %r14d
jmp 0x398e0
movl %esi, %r14d
movl %r14d, 0x10(%rsp)
movl %edi, 0x14(%rsp)
movzbl 0xf(%rsp), %r8d
movl %r14d, %esi
movl %r10d, %edx
movq %rcx, %r12
movq %r10, %r14
callq 0x53cfd
movl 0x10(%rsp), %r10d
movl 0x14(%rsp), %r11d
testl %eax, %eax
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r9
je 0x399e8
movl %ebp, %eax
negl %eax
cmovsl %ebp, %eax
movl %ebx, %ecx
negl %ecx
cmovsl %ebx, %ecx
cmpl %ecx, %eax
jae 0x399e3
movl $0x1000, %ecx           # imm = 0x1000
leal (%r12,%rcx), %esi
addl %r10d, %ecx
testl %ebx, %ebx
cmovnsl %r12d, %ecx
cmovnsl %r10d, %esi
cmovsl %r14d, %r11d
shlq $0xc, %r8
movq %r8, %rax
cqto
idivq %r9
movl $0x7ff, %edi            # imm = 0x7FF
subl %esi, %edi
andl $0xfff, %edi            # imm = 0xFFF
movslq %eax, %rdx
imulq %rdi, %rdx
shrq $0xc, %rdx
addl %r11d, %edx
movl $0x800, %edi            # imm = 0x800
addl %edi, %esi
sarl $0xc, %esi
addl %edi, %ecx
sarl $0xc, %ecx
movslq %esi, %rdi
leaq 0x3d6314(%rip), %r8     # 0x40fca0
movslq (%r8,%rdi,4), %rdi
leaq 0x13d719(%rip), %r8     # 0x1770b0
addq (%r8), %rdi
leaq 0x38f5cf(%rip), %r8     # 0x3c8f70
leaq 0x3913d8(%rip), %r9     # 0x3cad80
cmpl %ecx, %esi
jge 0x399e8
movl %edx, %r10d
sarl $0xc, %r10d
movslq %r10d, %r10
movswl (%r8,%r10,2), %r11d
cmpl %r11d, %esi
jl 0x399d3
movswl (%r9,%r10,2), %r11d
cmpl %r11d, %esi
jge 0x399d3
movb 0xf(%rsp), %r11b
movb %r11b, (%rdi,%r10)
addl %eax, %edx
movslq 0x3d62c8(%rip), %r10    # 0x40fca4
addq %r10, %rdi
incl %esi
jmp 0x399a8
cmpl %r15d, %r13d
jne 0x399f7
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1000, %esi           # imm = 0x1000
leal (%r14,%rsi), %edi
addl %r11d, %esi
testl %ebp, %ebp
cmovnsl %r14d, %esi
cmovsl %r12d, %r10d
cmovnsl %r11d, %edi
shlq $0xc, %r9
movq %r9, %rax
cqto
idivq %r8
movl $0x7ff, %edx            # imm = 0x7FF
subl %edi, %edx
andl $0xfff, %edx            # imm = 0xFFF
movslq %eax, %rcx
imulq %rdx, %rcx
shrq $0xc, %rcx
addl %r10d, %ecx
movl $0x800, %edx            # imm = 0x800
addl %edx, %edi
sarl $0xc, %edi
addl %edx, %esi
sarl $0xc, %esi
movslq %edi, %rdx
movslq %esi, %rsi
leaq (%rdx,%rdx), %rdi
leaq 0x38f518(%rip), %r8     # 0x3c8f70
leaq 0x391321(%rip), %r9     # 0x3cad80
leaq 0x13d64a(%rip), %r10    # 0x1770b0
leaq 0x3d6233(%rip), %r11    # 0x40fca0
cmpq %rsi, %rdx
jge 0x399e8
movl %ecx, %ebx
sarl $0xc, %ebx
movswl (%rdi,%r8), %ebp
cmpl %ebp, %ebx
jl 0x39aa0
movswl (%rdi,%r9), %ebp
cmpl %ebp, %ebx
jge 0x39aa0
movslq %ebx, %rbx
movslq (%r11,%rbx,4), %rbx
addq (%r10), %rbx
movb 0xf(%rsp), %bpl
movb %bpl, (%rdx,%rbx)
addl %eax, %ecx
incq %rdx
addq $0x2, %rdi
jmp 0x39a6d