// File: /workspace/github_c_makefile_star2_O3/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 -0x78(%rsp), %rsp
movl %ecx, %eax
movq %rdx, 0x68(%rsp)
movl %ecx, 0xc(%rsp)
movq %rdi, %r12
pmovsxbd 0xb007(%rip), %xmm0     # 0xe37a
pmovsxbw 0xb006(%rip), %xmm1     # 0xe382
movdqa 0xafbc(%rip), %xmm2     # 0xe340
pmovsxbd 0xaff1(%rip), %xmm3     # 0xe37e
cltd
idivl %r8d
movq %rsi, 0x60(%rsp)
movl %eax, 0x10(%rsp)
leal -0x1(%r8), %eax
cltq
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x20, %rcx
shrq $0x3f, %rax
addl %eax, %ecx
movq $-0x20, %rax
movq %rcx, 0x28(%rsp)
movdqa %xmm0, %xmm4
movdqa %xmm1, %xmm5
pmulld %xmm0, %xmm4
paddd %xmm3, %xmm0
pslld $0x8, %xmm4
psubd %xmm4, %xmm5
pand %xmm2, %xmm5
movdqu %xmm5, 0x1c80(%r12,%rax,4)
addq $0x4, %rax
jne 0x33c0
cmpl $0x1, %r8d
movl $0x1, 0x8(%rsp)
je 0x3458
imull $0xbed87f3b, 0xc(%rsp), %eax # imm = 0xBED87F3B
movl $0x1f3, 0x8(%rsp)       # imm = 0x1F3
addl $0x41aad6, %eax         # imm = 0x41AAD6
cmpl $0x8355ac, %eax         # imm = 0x8355AC
ja 0x3458
imull $0xe90f1ec3, 0xc(%rsp), %eax # imm = 0xE90F1EC3
movl $0x1eb, 0x8(%rsp)       # imm = 0x1EB
addl $0x42bcbd, %eax         # imm = 0x42BCBD
cmpl $0x85797a, %eax         # imm = 0x85797A
ja 0x3458
imull $0xb98f81d7, 0xc(%rsp), %eax # imm = 0xB98F81D7
xorl %ecx, %ecx
addl $0x434911, %eax         # imm = 0x434911
cmpl $0x869223, %eax         # imm = 0x869223
setb %cl
shll $0x4, %ecx
orl $0x1e7, %ecx            # imm = 0x1E7
movl %ecx, 0x8(%rsp)
cmpl $0x0, 0x10(%rsp)
jle 0x3990
movslq 0x10(%rsp), %rax
movq 0x28(%rsp), %rcx
xorl %r9d, %r9d
movl $0x400, %r10d           # imm = 0x400
xorl %r11d, %r11d
imulq $0x51eb851f, %rax, %rdx # imm = 0x51EB851F
addl $0x1e, %ecx
movq %rcx, 0x28(%rsp)
leaq 0x1c04(%r12), %rcx
movq %rcx, 0x50(%rsp)
movq %rdx, %rax
sarq $0x25, %rdx
shrq $0x3f, %rax
addl %eax, %edx
movl $0x800, %eax            # imm = 0x800
movq %rax, 0x48(%rsp)
movl $0x20, %eax
movq %rdx, 0x58(%rsp)
movq %rax, 0x20(%rsp)
movq 0x60(%rsp), %rdi
movl %r11d, %esi
leaq 0x44(%rsp), %rdx
leaq 0x40(%rsp), %rcx
leaq 0x3c(%rsp), %r8
movq 0x68(%rsp), %rax
movl %r10d, 0x14(%rsp)
movq %r9, 0x70(%rsp)
movl %r11d, 0x34(%rsp)
callq *%rax
movl 0x3c(%rsp), %eax
movl 0x40(%rsp), %ecx
movl 0x44(%rsp), %edx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq $-0x1000, %r8           # imm = 0xF000
xorl %r9d, %r9d
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
shll $0x4, %eax
shll $0x4, %ecx
shll $0x4, %edx
movl 0x1000(%r12,%r8), %ebx
movl 0x1004(%r12,%r8), %r13d
movl 0x1008(%r12,%r8), %ebp
subl %eax, %ebx
movl %ebx, %r15d
negl %r15d
cmovsl %ebx, %r15d
subl %ecx, %r13d
movl %r13d, %ebx
negl %ebx
cmovsl %r13d, %ebx
subl %edx, %ebp
addl %r15d, %ebx
movl %ebp, %r13d
negl %r13d
cmovsl %ebp, %r13d
addl %ebx, %r13d
movl 0x1400(%r12,%r9,4), %ebx
cmpl %r10d, %r13d
movl %ebx, %ebp
cmovll %r9d, %r11d
cmovll %r13d, %r10d
sarl $0xc, %ebp
subl %ebp, %r13d
movl 0x1800(%r12,%r9,4), %ebp
cmpl %edi, %r13d
movl %ebp, %r14d
cmovll %r13d, %edi
cmovll %r9d, %esi
movl %ebp, %r13d
andl $0xfffffc00, %ebp       # imm = 0xFFFFFC00
sarl $0xa, %r14d
subl %r14d, %r13d
addl %ebx, %ebp
movl %r13d, 0x1800(%r12,%r9,4)
movl %ebp, 0x1400(%r12,%r9,4)
incq %r9
addq $0x10, %r8
jne 0x351d
movslq %esi, %rdi
movslq %r11d, %r8
movl 0x14(%rsp), %ebp
movl $0x3ff, %r14d           # imm = 0x3FF
movdqa 0xad39(%rip), %xmm4     # 0xe310
pcmpeqd %xmm5, %xmm5
pmovsxbq 0xad90(%rip), %xmm6     # 0xe374
movl %eax, 0x1c(%rsp)
addl $0x40, 0x1800(%r12,%r8,4)
addl $0xffff0000, 0x1400(%r12,%r8,4) # imm = 0xFFFF0000
shlq $0x4, %rdi
movl (%r12,%rdi), %r8d
movl 0x4(%r12,%rdi), %r10d
movl %r8d, %r9d
movl %r10d, %ebx
subl %eax, %r9d
imull %ebp, %r9d
leal (%r9,%r14), %r11d
testl %r9d, %r9d
cmovnsl %r9d, %r11d
subl %ecx, %ebx
imull %ebp, %ebx
sarl $0xa, %r11d
subl %r11d, %r8d
movl %r8d, (%r12,%rdi)
leal (%rbx,%r14), %r9d
testl %ebx, %ebx
cmovnsl %ebx, %r9d
sarl $0xa, %r9d
subl %r9d, %r10d
movl %r10d, 0x4(%r12,%rdi)
movl 0x8(%r12,%rdi), %r8d
movl %r8d, %r9d
subl %edx, %r9d
imull %ebp, %r9d
leal (%r9,%r14), %r10d
testl %r9d, %r9d
cmovnsl %r9d, %r10d
sarl $0xa, %r10d
subl %r10d, %r8d
cmpl $0x0, 0x20(%rsp)
movl %r8d, 0x8(%r12,%rdi)
je 0x37f7
movl %esi, %r8d
movq 0x20(%rsp), %rax
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x100, %r10d           # imm = 0x100
leal 0x1(%rsi), %r15d
subl %eax, %r8d
leal (%rsi,%rax), %eax
cmovsl %edi, %r8d
cmpl %r10d, %eax
cmovgel %r10d, %eax
decl %esi
cmpl %r8d, %esi
movl %eax, 0x38(%rsp)
setg %r13b
cmpl %eax, %r15d
setl %r9b
jl 0x36c0
cmpl %r8d, %esi
jle 0x37f7
movq 0x50(%rsp), %r10
movl %r8d, 0x18(%rsp)
testb $0x1, %r9b
movl (%r10), %r11d
je 0x3751
movslq %r15d, %r15
movl $0x3ffff, %eax          # imm = 0x3FFFF
movq %r15, %r9
shlq $0x4, %r9
movl (%r12,%r9), %ebx
movl 0x4(%r12,%r9), %r14d
movl %ebx, %ebp
movl %r14d, %edi
subl 0x1c(%rsp), %ebp
imull %r11d, %ebp
leal (%rbp,%rax), %r8d
testl %ebp, %ebp
cmovnsl %ebp, %r8d
subl %ecx, %edi
imull %r11d, %edi
sarl $0x12, %r8d
subl %r8d, %ebx
movl %ebx, (%r12,%r9)
leal (%rdi,%rax), %r8d
testl %edi, %edi
cmovnsl %edi, %r8d
sarl $0x12, %r8d
subl %r8d, %r14d
movl %r14d, 0x4(%r12,%r9)
movl 0x8(%r12,%r9), %edi
movl %edi, %r8d
subl %edx, %r8d
imull %r11d, %r8d
leal (%r8,%rax), %ebx
testl %r8d, %r8d
cmovnsl %r8d, %ebx
incl %r15d
sarl $0x12, %ebx
subl %ebx, %edi
movl %edi, 0x8(%r12,%r9)
testb $0x1, %r13b
je 0x37d2
movslq %esi, %rsi
movl $0x3ffff, %eax          # imm = 0x3FFFF
movq %rsi, %r9
shlq $0x4, %r9
movl (%r12,%r9), %ebx
movl 0x4(%r12,%r9), %r8d
movl %ebx, %edi
movl %r8d, %r14d
subl 0x1c(%rsp), %edi
imull %r11d, %edi
leal (%rdi,%rax), %ebp
testl %edi, %edi
cmovnsl %edi, %ebp
subl %ecx, %r14d
imull %r11d, %r14d
sarl $0x12, %ebp
subl %ebp, %ebx
movl %ebx, (%r12,%r9)
leal (%r14,%rax), %edi
testl %r14d, %r14d
cmovnsl %r14d, %edi
sarl $0x12, %edi
subl %edi, %r8d
movl %r8d, 0x4(%r12,%r9)
movl 0x8(%r12,%r9), %edi
movl %edi, %r8d
subl %edx, %r8d
imull %r11d, %r8d
leal (%r8,%rax), %r11d
testl %r8d, %r8d
cmovnsl %r8d, %r11d
decl %esi
sarl $0x12, %r11d
subl %r11d, %edi
movl %edi, 0x8(%r12,%r9)
movl 0x18(%rsp), %eax
cmpl %eax, %esi
setg %r13b
addq $0x4, %r10
cmpl 0x38(%rsp), %r15d
setl %r9b
jl 0x36ca
cmpl %eax, %esi
jg 0x36ca
movl 0x34(%rsp), %eax
addl 0x8(%rsp), %eax
cltd
idivl 0xc(%rsp)
movq 0x70(%rsp), %r9
incl %r9d
movl %r9d, %eax
movl %edx, %r11d
xorl %edx, %edx
divl 0x58(%rsp)
testl %edx, %edx
je 0x3826
movl 0x14(%rsp), %r10d
jmp 0x3985
movl 0x14(%rsp), %r10d
movl %r10d, %eax
cltd
idivl 0x28(%rsp)
movslq 0x48(%rsp), %rcx
movq $0x0, 0x20(%rsp)
imulq $0x77777777, %rcx, %rsi # imm = 0x77777777
shrq $0x20, %rsi
subl %ecx, %esi
movl %esi, %edx
sarl $0x4, %esi
shrl $0x1f, %edx
addl %edx, %esi
addl %ecx, %esi
movl %esi, %ecx
movq %rsi, 0x48(%rsp)
movl $0x0, %esi
sarl $0x6, %ecx
subl %eax, %r10d
cmpl $0x2, %ecx
cmovgel %ecx, %esi
jl 0x3985
movl %ecx, %edi
movl %ecx, %eax
xorl %r8d, %r8d
pmovsxbq 0xaaee(%rip), %xmm1     # 0xe376
pmovsxbq 0xaae7(%rip), %xmm2     # 0xe378
imull %ecx, %edi
decq %rax
addl $0x3, %ecx
movq %rax, %xmm0
andl $-0x4, %ecx
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
pxor %xmm4, %xmm0
movdqa %xmm1, %xmm3
pxor %xmm4, %xmm3
pcmpgtq %xmm0, %xmm3
movd %xmm3, %eax
notl %eax
testb $0x1, %al
je 0x38df
movl %r8d, %edx
movl %edi, %eax
imull %r8d, %edx
subl %edx, %eax
shll $0x8, %eax
cltd
idivl %edi
imull %r10d, %eax
movl %eax, 0x1c00(%r12,%r8,4)
pxor %xmm5, %xmm3
pextrb $0x8, %xmm3, %eax
testb $0x1, %al
je 0x390a
leal 0x1(%r8), %edx
movl %edi, %eax
imull %edx, %edx
subl %edx, %eax
shll $0x8, %eax
cltd
idivl %edi
imull %r10d, %eax
movl %eax, 0x1c04(%r12,%r8,4)
movdqa %xmm2, %xmm3
pxor %xmm4, %xmm3
pcmpgtq %xmm0, %xmm3
pxor %xmm5, %xmm3
pextrb $0x0, %xmm3, %eax
testb $0x1, %al
je 0x3942
leal 0x2(%r8), %edx
movl %edi, %eax
imull %edx, %edx
subl %edx, %eax
shll $0x8, %eax
cltd
idivl %edi
imull %r10d, %eax
movl %eax, 0x1c08(%r12,%r8,4)
pextrb $0x8, %xmm3, %eax
testb $0x1, %al
je 0x3969
leal 0x3(%r8), %edx
movl %edi, %eax
imull %edx, %edx
subl %edx, %eax
shll $0x8, %eax
cltd
idivl %edi
imull %r10d, %eax
movl %eax, 0x1c0c(%r12,%r8,4)
addq $0x4, %r8
paddq %xmm6, %xmm1
paddq %xmm6, %xmm2
cmpq %r8, %rcx
jne 0x38ab
movl %esi, %eax
movq %rax, 0x20(%rsp)
cmpl 0x10(%rsp), %r9d
jne 0x34bb
leaq 0x78(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq