// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/build.c
// Function: draw2dgrid
void draw2dgrid(int posxe, int posye, short ange, int zoome, short gride)
{
	int i, xp1, yp1, xp2=0, yp2, tempy;

	(void)ange;

	if (gride > 0)
	{
		yp1 = midydim16-mulscale14(posye+editorgridextent,zoome);
		if (yp1 < 0) yp1 = 0;
		yp2 = midydim16-mulscale14(posye-editorgridextent,zoome);
		if (yp2 >= ydim16) yp2 = ydim16-1;

		if ((yp1 < ydim16) && (yp2 >= 0) && (yp2 >= yp1))
		{
			xp1 = halfxdim16-mulscale14(posxe+editorgridextent,zoome);

			for(i=-editorgridextent;i<=editorgridextent;i+=(2048>>gride))
			{
				xp2 = xp1;
				xp1 = halfxdim16-mulscale14(posxe-i,zoome);

				if (xp1 >= xdim) break;
				if (xp1 >= 0)
				{
					if (xp1 != xp2)
					{
						drawline16(xp1,yp1,xp1,yp2,8);
					}
				}
			}
			if ((i >= editorgridextent) && (xp1 < xdim))
				xp2 = xp1;
			if ((xp2 >= 0) && (xp2 < xdim))
			{
				drawline16(xp2,yp1,xp2,yp2,8);
			}
		}

		xp1 = mulscale14(posxe+editorgridextent,zoome);
		xp2 = mulscale14(posxe-editorgridextent,zoome);
		tempy = 0x80000000l;
		for(i=-editorgridextent;i<=editorgridextent;i+=(2048>>gride))
		{
			yp1 = (((posye-i)*zoome)>>14);
			if (yp1 != tempy)
			{
				if ((yp1 > midydim16-ydim16) && (yp1 <= midydim16))
				{
					drawline16(halfxdim16-xp1,midydim16-yp1,halfxdim16-xp2,midydim16-yp1,8);
					tempy = yp1;
				}
			}
		}
	}
}

// Assembly:
testw %r8w, %r8w
jle 0x17d82
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebx
movl %edi, %r15d
movl 0x15b67a(%rip), %edx    # 0x1731c8
leaq 0x85c47(%rip), %rax     # 0x9d79c
movl (%rax), %eax
leal (%rax,%rbx), %esi
movslq %esi, %rsi
movslq %ecx, %rdi
imulq %rdi, %rsi
shrq $0xe, %rsi
movl %edx, %ecx
subl %esi, %ecx
xorl %r9d, %r9d
testl %ecx, %ecx
cmovgl %ecx, %r9d
movl %ebx, %esi
subl %eax, %esi
movslq %esi, %rsi
imulq %rdi, %rsi
shrq $0xe, %rsi
subl %esi, %edx
movl 0x10f1dc(%rip), %esi    # 0x126d68
leal -0x1(%rsi), %r10d
cmpl %esi, %edx
cmovll %edx, %r10d
movl %r9d, 0x4(%rsp)
cmpl %esi, %r9d
jge 0x17c85
testl %r10d, %r10d
js 0x17c85
cmpl %r10d, %ecx
jg 0x17c85
movl 0x15b607(%rip), %r12d   # 0x1731c4
leal (%rax,%r15), %ecx
movslq %ecx, %rcx
imulq %rdi, %rcx
shrq $0xe, %rcx
subl %ecx, %r12d
movl $0x800, %r14d           # imm = 0x800
movl %r8d, %ecx
shrl %cl, %r14d
movl %eax, %ecx
negl %ecx
movslq %ecx, %r8
movq %r15, 0x18(%rsp)
movslq %r15d, %r15
leaq 0x3e93fb(%rip), %rcx    # 0x400fec
movl (%rcx), %ecx
subq %r8, %r15
imulq %rdi, %r15
movq %rdi, %rbp
imulq %r14, %rbp
xorl %edx, %edx
movq %rdi, 0x10(%rsp)
movq %r14, 0x20(%rsp)
movl %r12d, %r13d
movslq %eax, %rsi
cmpq %rsi, %r8
jg 0x17c93
movl 0x15b5a5(%rip), %r12d   # 0x1731c4
movq %r15, %rdx
shrq $0xe, %rdx
subl %edx, %r12d
cmpl %ecx, %r12d
jge 0x17c98
testl %r12d, %r12d
js 0x17c7a
cmpl %r13d, %r12d
je 0x17c7a
movl %r12d, %edi
movl 0x4(%rsp), %esi
movl %r12d, %edx
movl %r10d, %ecx
movq %r8, 0x8(%rsp)
pushq $0x8
popq %r8
movl %r10d, %r14d
callq 0x1737f
movq 0x8(%rsp), %r8
movl %r14d, %r10d
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %rdi
leaq 0x85b2d(%rip), %rax     # 0x9d79c
movl (%rax), %eax
leaq 0x3e9374(%rip), %rcx    # 0x400fec
movl (%rcx), %ecx
addq %r14, %r8
subq %rbp, %r15
movl %r13d, %edx
jmp 0x17c0d
movl $0x800, %r14d           # imm = 0x800
movl %r8d, %ecx
shrl %cl, %r14d
jmp 0x17ce5
movl %r13d, %r12d
jmp 0x17c9b
movl %r13d, %edx
cmpl %ecx, %r12d
cmovgel %edx, %r12d
cmpl %r8d, %eax
cmovgl %edx, %r12d
testl %r12d, %r12d
setns %dl
cmpl %ecx, %r12d
setl %cl
andb %dl, %cl
cmpb $0x1, %cl
movq 0x18(%rsp), %r15
jne 0x17ce5
pushq $0x8
popq %r8
movl %r12d, %edi
movl 0x4(%rsp), %esi
movl %r12d, %edx
movl %r10d, %ecx
callq 0x1737f
movq 0x10(%rsp), %rdi
leaq 0x85ab9(%rip), %rax     # 0x9d79c
movl (%rax), %eax
leal (%rax,%r15), %ecx
movslq %ecx, %rcx
imulq %rdi, %rcx
shrq $0xe, %rcx
movq %rcx, 0x8(%rsp)
subl %eax, %r15d
movslq %r15d, %r12
imulq %rdi, %r12
shrq $0xe, %r12
movl %eax, %ebp
negl %ebp
addl %eax, %ebx
imull %edi, %ebx
imull %r14d, %edi
movl $0x80000000, %edx       # imm = 0x80000000
cmpl %eax, %ebp
jg 0x17d74
movl %ebx, %r13d
sarl $0xe, %r13d
cmpl %edx, %r13d
je 0x17d6d
movl 0x15b499(%rip), %esi    # 0x1731c8
movl %esi, %ecx
subl %r13d, %ecx
jl 0x17d6d
subl 0x10f02c(%rip), %esi    # 0x126d68
cmpl %esi, %r13d
jle 0x17d6d
movl 0x15b47d(%rip), %edx    # 0x1731c4
movq %rdi, %r15
movl %edx, %edi
subl 0x8(%rsp), %edi
subl %r12d, %edx
movl %ecx, %esi
pushq $0x8
popq %r8
callq 0x1737f
movq %r15, %rdi
leaq 0x85a34(%rip), %rax     # 0x9d79c
movl (%rax), %eax
movl %r13d, %edx
addl %r14d, %ebp
subl %edi, %ebx
jmp 0x17d19
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq