// File: /workspace/github_c_makefile_star2_O0/halcy[P]quasi_crystals_bot/Engine/Neuquant.c
// Function: contest
static int contest(Neuquant *self,int b,int g,int r)
{
	/* finds closest neuron (min dist) and updates freq */
	/* finds best neuron (min dist-bias) and returns position */
	/* for frequently chosen neurons, freq[i] is high and bias[i] is negative */
	/* bias[i] = gamma*((1/NeuquantNetworkSize)-freq[i]) */

	int i,dist,a,biasdist,betafreq;
	int bestpos,bestbiaspos,bestd,bestbiasd;
	int *p,*f,*n;

	bestd = ~(((int) 1)<<31);
	bestbiasd = bestd;
	bestpos = -1;
	bestbiaspos = bestpos;
	p = self->bias;
	f = self->freq;

	for (i=0; i<NeuquantNetworkSize; i++) {
		n = self->network[i];
		dist = n[0] - b;   if (dist<0) dist = -dist;
		a = n[1] - g;   if (a<0) a = -a;
		dist += a;
		a = n[2] - r;   if (a<0) a = -a;
		dist += a;
		if (dist<bestd) {bestd=dist; bestpos=i;}
		biasdist = dist - ((*p)>>(intbiasshift-netbiasshift));
		if (biasdist<bestbiasd) {bestbiasd=biasdist; bestbiaspos=i;}
		betafreq = (*f >> betashift);
		*f++ -= betafreq;
		*p++ += (betafreq<<gammashift);
	}
	self->freq[bestpos] += beta;
	self->bias[bestpos] -= betagamma;
	return bestbiaspos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl $0x7fffffff, -0x34(%rbp) # imm = 0x7FFFFFFF
movl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
addq $0x1400, %rax           # imm = 0x1400
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
addq $0x1800, %rax           # imm = 0x1800
movq %rax, -0x48(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x100, -0x18(%rbp)     # imm = 0x100
jge 0x47c4
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
subl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x46f8
xorl %eax, %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
subl -0x10(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x4713
xorl %eax, %eax
subl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x4737
xorl %eax, %eax
subl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x4754
movl -0x1c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x40(%rbp), %rcx
movl (%rcx), %ecx
sarl $0xc, %ecx
subl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x4779
movl -0x24(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x48(%rbp), %rax
movl (%rax), %eax
sarl $0xa, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %edx
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x48(%rbp)
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
shll $0xa, %ecx
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x4, %rdx
movq %rdx, -0x40(%rbp)
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x46be
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl 0x1800(%rax,%rcx,4), %edx
addl $0x40, %edx
movl %edx, 0x1800(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl 0x1400(%rax,%rcx,4), %edx
subl $0x10000, %edx          # imm = 0x10000
movl %edx, 0x1400(%rax,%rcx,4)
movl -0x30(%rbp), %eax
popq %rbp
retq
nop