// File: /workspace/github_c_makefile_star2_O2/halcy[P]quasi_crystals_bot/Engine/Neuquant.c
// Function: NeuquantLearn
void NeuquantLearn(Neuquant *self,const void *data,NeuquantLookupFunction *func,int numpixels,int samplefac)
{
	int alphadec=30+((samplefac-1)/3);
	int samplepixels=numpixels/samplefac;
	int delta=samplepixels/ncycles;
	int alpha=initalpha;
	int radius=initradius;
	
	int rad=radius>>radiusbiasshift;
	if(rad<=1) rad=0;
	for(int i=0;i<rad;i++) self->radpower[i]=alpha*(((rad*rad-i*i)*radbias)/(rad*rad));

	int step;
	if(samplefac==1) step=1;
	else if(numpixels%prime1!=0) step=prime1;
	else if(numpixels%prime2!=0) step=prime2;
	else if(numpixels%prime3!=0) step=prime3;
	else step=prime4;

	int pixel=0;
	for(int i=0;i<samplepixels;i++)
	{
		int r,g,b;
		func(data,pixel,&r,&g,&b);
		b<<=netbiasshift;
		g<<=netbiasshift;
		r<<=netbiasshift;
		int j=contest(self,b,g,r);

		altersingle(self,alpha,j,b,g,r);
		if(rad) alterneigh(self,rad,j,b,g,r);

		pixel=(pixel+step)%numpixels;
	
		if((i+1)%delta==0)
		{	
			alpha-=alpha/alphadec;
			radius-=radius/radiusdec;
			rad=radius>>radiusbiasshift;
			if(rad<=1) rad=0;
	
			for(int j=0;j<rad;j++) self->radpower[j]=alpha*(((rad*rad-j*j)*radbias)/(rad*rad));
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leaq -0x68(%rsp), %rsp
leal -0x1(%r8), %eax
movq %rdx, 0x60(%rsp)
pushq $0x3
popq %r9
cltd
movq %rdi, %r13
leaq 0x1c00(%rdi), %r10
idivl %r9d
movl %ecx, 0x10(%rsp)
movl %eax, 0x1c(%rsp)
movl %ecx, %eax
xorl %ecx, %ecx
cltd
idivl %r8d
movq %rsi, 0x58(%rsp)
movl %eax, %r9d
xorl %eax, %eax
cmpq $0x20, %rcx
je 0x2ed3
movl %eax, %edx
movl $0x40000, %esi          # imm = 0x40000
addq $0x100, %rax            # imm = 0x100
imull %ecx, %edx
subl %edx, %esi
andl $0x7fc00, %esi          # imm = 0x7FC00
movl %esi, (%r10,%rcx,4)
incq %rcx
jmp 0x2eac
pushq $0x64
popq %rcx
movl %r9d, %eax
cltd
idivl %ecx
cmpl $0x1, %r8d
movl %eax, 0x34(%rsp)
jne 0x2eef
pushq $0x1
popq %rax
movl %eax, 0xc(%rsp)
jmp 0x2f23
movl 0x10(%rsp), %eax
movl $0x1f3, %ecx            # imm = 0x1F3
movl $0x1f3, 0xc(%rsp)       # imm = 0x1F3
cltd
idivl %ecx
testl %edx, %edx
jne 0x2f23
movl 0x10(%rsp), %eax
movl $0x1eb, %ecx            # imm = 0x1EB
movl $0x1eb, 0xc(%rsp)       # imm = 0x1EB
cltd
idivl %ecx
testl %edx, %edx
je 0x32b5
addl $0x1e, 0x1c(%rsp)
xorl %eax, %eax
movl $0x400, %r8d            # imm = 0x400
testl %r9d, %r9d
cmovlel %eax, %r9d
movl %r9d, 0x38(%rsp)
pushq $0x20
popq %rax
xorl %r11d, %r11d
xorl %r9d, %r9d
movq %rax, 0x28(%rsp)
movl $0x800, 0x20(%rsp)      # imm = 0x800
movq %r10, 0x50(%rsp)
cmpl 0x38(%rsp), %r9d
je 0x32a5
movl %r8d, 0x14(%rsp)
movq 0x58(%rsp), %rdi
movl %r11d, %esi
leaq 0x4c(%rsp), %rdx
leaq 0x48(%rsp), %rcx
leaq 0x44(%rsp), %r8
movl %r9d, 0x40(%rsp)
movl %r11d, 0x3c(%rsp)
callq *0x60(%rsp)
movl 0x44(%rsp), %edi
movl 0x48(%rsp), %r8d
movl 0x4c(%rsp), %ebx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq $-0x1000, %rcx          # imm = 0xF000
xorl %r10d, %r10d
shll $0x4, %edi
shll $0x4, %r8d
shll $0x4, %ebx
pushq $-0x1
popq %rsi
movl %esi, %edx
movl %esi, %r9d
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
testq %rcx, %rcx
je 0x306f
movl 0x1000(%r13,%rcx), %ebp
movl 0x1004(%r13,%rcx), %r15d
movl 0x1008(%r13,%rcx), %r12d
subl %edi, %ebp
movl %ebp, %r14d
negl %r14d
cmovsl %ebp, %r14d
subl %r8d, %r15d
movl %r15d, %ebp
negl %ebp
cmovsl %r15d, %ebp
subl %ebx, %r12d
addl %r14d, %ebp
movl %r12d, %r14d
negl %r14d
cmovsl %r12d, %r14d
addl %ebp, %r14d
movl 0x1400(%r13,%r10,4), %ebp
cmpl %eax, %r14d
movl %ebp, %r15d
cmovll %r10d, %edx
cmovll %r14d, %eax
sarl $0xc, %r15d
subl %r15d, %r14d
movl 0x1800(%r13,%r10,4), %r15d
cmpl %r11d, %r14d
movl %r15d, %r12d
movl %r15d, %esi
cmovll %r10d, %r9d
cmovll %r14d, %r11d
andl $0xfffffc00, %r15d      # imm = 0xFFFFFC00
sarl $0xa, %r12d
addq $0x10, %rcx
subl %r12d, %esi
addl %ebp, %r15d
movl %esi, 0x1800(%r13,%r10,4)
movl %r15d, 0x1400(%r13,%r10,4)
incq %r10
jmp 0x2fc0
movslq %r9d, %r10
movslq %edx, %rax
movl 0x14(%rsp), %esi
movl %ebx, 0x18(%rsp)
movl $0xfffffc00, %ebx       # imm = 0xFFFFFC00
addl $0x40, 0x1800(%r13,%rax,4)
addl $0xffff0000, 0x1400(%r13,%rax,4) # imm = 0xFFFF0000
shlq $0x4, %r10
movl (%r13,%r10), %r11d
movl 0x4(%r13,%r10), %ebp
movl %r11d, %eax
movl %ebp, %ecx
subl %edi, %eax
subl %r8d, %ecx
imull %esi, %eax
imull %esi, %ecx
cltd
idivl %ebx
movl %r8d, 0x24(%rsp)
addl %r11d, %eax
movl %eax, (%r13,%r10)
movl %ecx, %eax
cltd
idivl %ebx
addl %ebp, %eax
movl %eax, 0x4(%r13,%r10)
movl 0x8(%r13,%r10), %ecx
movl %ecx, %eax
subl 0x18(%rsp), %eax
imull %esi, %eax
cltd
idivl %ebx
addl %ecx, %eax
cmpl $0x0, 0x28(%rsp)
movl %eax, 0x8(%r13,%r10)
je 0x3203
movq 0x28(%rsp), %rax
movl %r9d, %r10d
subl %eax, %r10d
leal (%r9,%rax), %r11d
pushq $-0x1
popq %rax
movl $0x100, %ecx            # imm = 0x100
cmovsl %eax, %r10d
leal 0x1(%r9), %ebp
movq 0x50(%rsp), %r15
cmpl %ecx, %r11d
cmovgel %ecx, %r11d
decl %r9d
cmpl %r11d, %ebp
jl 0x3130
cmpl %r10d, %r9d
jle 0x3203
cmpl %r11d, %ebp
movl 0x4(%r15), %r14d
jge 0x3198
movslq %ebp, %r12
movl %edi, %r8d
incl %ebp
shlq $0x4, %r12
movl (%r13,%r12), %ebx
movl 0x4(%r13,%r12), %esi
movl %ebx, %eax
movl %esi, %ecx
subl %edi, %eax
movl $0xfffc0000, %edi       # imm = 0xFFFC0000
imull %r14d, %eax
cltd
idivl %edi
subl 0x24(%rsp), %ecx
imull %r14d, %ecx
addl %ebx, %eax
movl %eax, (%r13,%r12)
movl %ecx, %eax
cltd
idivl %edi
addl %esi, %eax
movl %eax, 0x4(%r13,%r12)
movl 0x8(%r13,%r12), %ecx
movl %ecx, %eax
subl 0x18(%rsp), %eax
imull %r14d, %eax
cltd
idivl %edi
movl %r8d, %edi
addl %ecx, %eax
movl %eax, 0x8(%r13,%r12)
addq $0x4, %r15
cmpl %r10d, %r9d
jle 0x3122
movslq %r9d, %r12
movl %edi, %r8d
shlq $0x4, %r12
movl (%r13,%r12), %esi
movl 0x4(%r13,%r12), %ebx
movl %esi, %eax
movl %ebx, %ecx
subl %edi, %eax
movl $0xfffc0000, %edi       # imm = 0xFFFC0000
imull %r14d, %eax
cltd
idivl %edi
subl 0x24(%rsp), %ecx
imull %r14d, %ecx
addl %esi, %eax
movl %eax, (%r13,%r12)
movl %ecx, %eax
cltd
idivl %edi
addl %ebx, %eax
movl %eax, 0x4(%r13,%r12)
movl 0x8(%r13,%r12), %ecx
movl %ecx, %eax
subl 0x18(%rsp), %eax
imull %r14d, %eax
cltd
idivl %edi
movl %r8d, %edi
addl %ecx, %eax
movl %eax, 0x8(%r13,%r12)
jmp 0x311f
movl 0x3c(%rsp), %eax
addl 0xc(%rsp), %eax
cltd
idivl 0x10(%rsp)
movl 0x40(%rsp), %r9d
incl %r9d
movl %r9d, %eax
movl %edx, %r11d
cltd
idivl 0x34(%rsp)
testl %edx, %edx
je 0x3231
movl 0x14(%rsp), %r8d
jmp 0x2f57
movl 0x14(%rsp), %r8d
movl %r8d, %eax
cltd
idivl 0x1c(%rsp)
movl 0x20(%rsp), %esi
movl %eax, %ecx
movl %esi, %eax
cltd
pushq $-0x1e
popq %rdi
idivl %edi
subl %ecx, %r8d
movq 0x50(%rsp), %r10
addl %eax, %esi
movl $0x0, %eax
movl %esi, %edx
movl %esi, 0x20(%rsp)
movl $0x0, %esi
sarl $0x6, %edx
cmpl $0x2, %edx
cmovll %eax, %edx
movl %edx, %ecx
movq %rdx, 0x28(%rsp)
imull %edx, %ecx
testl %edx, %edx
cmovgl %edx, %esi
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x2f57
movl %edi, %edx
movl %ecx, %eax
imull %edi, %edx
subl %edx, %eax
shll $0x8, %eax
cltd
idivl %ecx
imull %r8d, %eax
movl %eax, (%r10,%rdi,4)
incq %rdi
jmp 0x3280
leaq 0x68(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x10(%rsp), %eax
movl $0x1e7, %ecx            # imm = 0x1E7
cltd
idivl %ecx
xorl %eax, %eax
testl %edx, %edx
sete %al
shll $0x4, %eax
orl %ecx, %eax
jmp 0x2ee9
nop