// File: /workspace/github_c_makefile_star2_O0/halcy[P]quasi_crystals_bot/Engine/Neuquant.c
// Function: BuildNeuquantIndex
void BuildNeuquantIndex(Neuquant *self)
{
	int i,j,smallpos,smallval;
	int *p,*q;
	int previouscol,startpos;

	previouscol = 0;
	startpos = 0;
	for (i=0; i<NeuquantNetworkSize; i++) {
		p = self->network[i];
		smallpos = i;
		smallval = p[1];			/* index on g */
		/* find smallest in i..NeuquantNetworkSize-1 */
		for (j=i+1; j<NeuquantNetworkSize; j++) {
			q = self->network[j];
			if (q[1] < smallval) {		/* index on g */
				smallpos = j;
				smallval = q[1];	/* index on g */
			}
		}
		q = self->network[smallpos];
		/* swap p (i) and q (smallpos) entries */
		if (i != smallpos) {
			j = q[0];   q[0] = p[0];   p[0] = j;
			j = q[1];   q[1] = p[1];   p[1] = j;
			j = q[2];   q[2] = p[2];   p[2] = j;
			j = q[3];   q[3] = p[3];   p[3] = j;
		}
		/* smallval entry is now in position i */
		if (smallval != previouscol) {
			self->netindex[previouscol] = (startpos+i)>>1;
			for (j=previouscol+1; j<smallval; j++) self->netindex[j] = i;
			previouscol = smallval;
			startpos = i;
		}
	}
	self->netindex[previouscol] = (startpos+maxnetpos)>>1;
	for (j=previouscol+1; j<256; j++) self->netindex[j] = maxnetpos; /* really 256 */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x100, -0xc(%rbp)      # imm = 0x100
jge 0x4197
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
cmpl $0x100, -0x10(%rbp)     # imm = 0x100
jge 0x408b
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x18(%rbp), %eax
jge 0x407e
movl -0x10(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
jmp 0x4080
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x4046
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x412e
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x10(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x10(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x10(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x10(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x18(%rbp), %eax
cmpl -0x2c(%rbp), %eax
je 0x4187
movl -0x30(%rbp), %edx
addl -0xc(%rbp), %edx
sarl %edx
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl %edx, 0x1000(%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x417b
movl -0xc(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl %edx, 0x1000(%rax,%rcx,4)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x4156
movl -0x18(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x4189
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x400d
movl -0x30(%rbp), %edx
addl $0xff, %edx
sarl %edx
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl %edx, 0x1000(%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
cmpl $0x100, -0x10(%rbp)     # imm = 0x100
jge 0x41e1
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl $0xff, 0x1000(%rax,%rcx,4)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x41ba
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)