// File: /workspace/github_c_makefile_star2_O1/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, 0x70(%rsp)
movl %ecx, 0x14(%rsp)
cltd
idivl %r8d
movl %eax, 0x18(%rsp)
leal -0x1(%r8), %eax
cltq
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rsi, 0x68(%rsp)
movq %rdi, %r12
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
addl %eax, %ecx
movq %rcx, 0x30(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %edx
imull %eax, %edx
movl $0x40000, %esi          # imm = 0x40000
subl %edx, %esi
andl $0x7fc00, %esi          # imm = 0x7FC00
movl %esi, 0x1c00(%r12,%rcx,4)
incq %rcx
addl $0x100, %eax            # imm = 0x100
cmpq $0x20, %rcx
jne 0x321e
cmpl $0x1, %r8d
movl $0x1, 0x10(%rsp)
je 0x32b0
imull $0xbed87f3b, 0x14(%rsp), %eax # imm = 0xBED87F3B
addl $0x41aad6, %eax         # imm = 0x41AAD6
cmpl $0x8355ac, %eax         # imm = 0x8355AC
movl $0x1f3, 0x10(%rsp)      # imm = 0x1F3
ja 0x32b0
imull $0xe90f1ec3, 0x14(%rsp), %eax # imm = 0xE90F1EC3
addl $0x42bcbd, %eax         # imm = 0x42BCBD
cmpl $0x85797a, %eax         # imm = 0x85797A
movl $0x1eb, 0x10(%rsp)      # imm = 0x1EB
ja 0x32b0
imull $0xb98f81d7, 0x14(%rsp), %eax # imm = 0xB98F81D7
addl $0x434911, %eax         # imm = 0x434911
xorl %ecx, %ecx
cmpl $0x869223, %eax         # imm = 0x869223
setb %cl
shll $0x4, %ecx
orl $0x1e7, %ecx            # imm = 0x1E7
movl %ecx, 0x10(%rsp)
cmpl $0x0, 0x18(%rsp)
jle 0x3723
movslq 0x18(%rsp), %rax
imulq $0x51eb851f, %rax, %rdx # imm = 0x51EB851F
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x25, %rdx
movq 0x30(%rsp), %rcx
addl $0x1e, %ecx
movq %rcx, 0x30(%rsp)
addl %eax, %edx
movq %rdx, 0x60(%rsp)
leaq 0x1c04(%r12), %rax
movq %rax, 0x58(%rsp)
movl $0x800, %eax            # imm = 0x800
movq %rax, 0x50(%rsp)
movl $0x20, %r11d
movl $0x400, %r8d            # imm = 0x400
xorl %r9d, %r9d
xorl %r10d, %r10d
movq %r11, 0x38(%rsp)
movl %r9d, 0x48(%rsp)
movl %r8d, 0x1c(%rsp)
movq 0x68(%rsp), %rdi
movl %r10d, 0x44(%rsp)
movl %r10d, %esi
leaq 0x2c(%rsp), %rdx
leaq 0x28(%rsp), %rcx
leaq 0x24(%rsp), %r8
movq 0x70(%rsp), %rax
callq *%rax
movl 0x24(%rsp), %eax
shll $0x4, %eax
movl %eax, 0x24(%rsp)
movl 0x28(%rsp), %ecx
movl 0x2c(%rsp), %edx
shll $0x4, %ecx
shll $0x4, %edx
movl %ecx, 0x28(%rsp)
movl %edx, 0x2c(%rsp)
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
movl 0x1000(%r12,%r8), %ebx
subl %eax, %ebx
movl %ebx, %r14d
movl 0x1004(%r12,%r8), %r15d
negl %r14d
cmovsl %ebx, %r14d
subl %ecx, %r15d
movl %r15d, %ebx
negl %ebx
movl 0x1008(%r12,%r8), %r13d
cmovsl %r15d, %ebx
subl %edx, %r13d
addl %r14d, %ebx
movl %r13d, %r14d
negl %r14d
cmovsl %r13d, %r14d
addl %ebx, %r14d
cmpl %r10d, %r14d
movl 0x1400(%r12,%r9,4), %ebx
cmovll %r9d, %r11d
movl %ebx, %r15d
cmovll %r14d, %r10d
sarl $0xc, %r15d
subl %r15d, %r14d
cmpl %edi, %r14d
cmovll %r9d, %esi
movl 0x1800(%r12,%r9,4), %r15d
cmovll %r14d, %edi
movl %r15d, %r14d
sarl $0xa, %r14d
movl %r15d, %r13d
subl %r14d, %r13d
andl $0xfffffc00, %r15d      # imm = 0xFFFFFC00
movl %r13d, 0x1800(%r12,%r9,4)
addl %ebx, %r15d
movl %r15d, 0x1400(%r12,%r9,4)
incq %r9
addq $0x10, %r8
jne 0x3382
movslq %r11d, %r8
addl $0x40, 0x1800(%r12,%r8,4)
movslq %esi, %rdi
addl $0xffff0000, 0x1400(%r12,%r8,4) # imm = 0xFFFF0000
shlq $0x4, %rdi
movl (%r12,%rdi), %r8d
movl %r8d, %r9d
movl %eax, 0x20(%rsp)
subl %eax, %r9d
movl 0x1c(%rsp), %ebp
imull %ebp, %r9d
movl 0x4(%r12,%rdi), %r10d
movl $0x3ff, %r14d           # imm = 0x3FF
leal (%r9,%r14), %r11d
testl %r9d, %r9d
movl %r10d, %ebx
cmovnsl %r9d, %r11d
subl %ecx, %ebx
imull %ebp, %ebx
sarl $0xa, %r11d
subl %r11d, %r8d
leal (%rbx,%r14), %r9d
testl %ebx, %ebx
cmovnsl %ebx, %r9d
sarl $0xa, %r9d
subl %r9d, %r10d
movl %r8d, (%r12,%rdi)
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, 0x38(%rsp)
movl %r8d, 0x8(%r12,%rdi)
je 0x3662
movl %esi, %r13d
movq 0x38(%rsp), %rax
subl %eax, %r13d
leal (%rsi,%rax), %eax
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmovsl %edi, %r13d
movl $0x100, %edi            # imm = 0x100
cmpl %edi, %eax
cmovgel %edi, %eax
leal 0x1(%rsi), %r14d
decl %esi
cmpl %r13d, %esi
setg %dil
movl %eax, 0x4c(%rsp)
cmpl %eax, %r14d
setl %r9b
jl 0x3512
cmpl %r13d, %esi
jle 0x3662
movq 0x58(%rsp), %r10
testb $0x1, %r9b
movl (%r10), %r11d
je 0x35be
movslq %r14d, %r14
movq %r14, %r9
shlq $0x4, %r9
movl (%r12,%r9), %ebx
movl %edx, %r15d
movl %ecx, %edx
movl %r13d, %ecx
movl %ebx, %r13d
subl 0x20(%rsp), %r13d
imull %r11d, %r13d
movl 0x4(%r12,%r9), %ebp
movl $0x3ffff, %eax          # imm = 0x3FFFF
leal (%r13,%rax), %r8d
testl %r13d, %r13d
movb %dil, 0xf(%rsp)
movl %ebp, %edi
cmovnsl %r13d, %r8d
movl %ecx, %r13d
movl %edx, %ecx
movl %r15d, %edx
subl %ecx, %edi
imull %r11d, %edi
sarl $0x12, %r8d
subl %r8d, %ebx
leal (%rdi,%rax), %r8d
testl %edi, %edi
cmovnsl %edi, %r8d
sarl $0x12, %r8d
subl %r8d, %ebp
movl %ebx, (%r12,%r9)
movl %ebp, 0x4(%r12,%r9)
movl 0x8(%r12,%r9), %edi
movl %edi, %r8d
subl %r15d, %r8d
imull %r11d, %r8d
leal (%r8,%rax), %ebx
testl %r8d, %r8d
cmovnsl %r8d, %ebx
sarl $0x12, %ebx
subl %ebx, %edi
movl %edi, 0x8(%r12,%r9)
movb 0xf(%rsp), %dil
incl %r14d
testb $0x1, %dil
je 0x363f
movslq %esi, %rsi
movq %rsi, %r9
shlq $0x4, %r9
movl (%r12,%r9), %ebx
movl %ebx, %edi
subl 0x20(%rsp), %edi
imull %r11d, %edi
movl 0x4(%r12,%r9), %r8d
movl $0x3ffff, %eax          # imm = 0x3FFFF
leal (%rdi,%rax), %ebp
testl %edi, %edi
movl %r8d, %r15d
cmovnsl %edi, %ebp
subl %ecx, %r15d
imull %r11d, %r15d
sarl $0x12, %ebp
subl %ebp, %ebx
leal (%r15,%rax), %edi
testl %r15d, %r15d
cmovnsl %r15d, %edi
sarl $0x12, %edi
subl %edi, %r8d
movl %ebx, (%r12,%r9)
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
sarl $0x12, %r11d
subl %r11d, %edi
movl %edi, 0x8(%r12,%r9)
decl %esi
cmpl %r13d, %esi
setg %dil
addq $0x4, %r10
cmpl 0x4c(%rsp), %r14d
setl %r9b
jl 0x3517
cmpl %r13d, %esi
jg 0x3517
movl 0x44(%rsp), %eax
addl 0x10(%rsp), %eax
cltd
idivl 0x14(%rsp)
movl 0x48(%rsp), %r9d
incl %r9d
movl %edx, %r10d
movl %r9d, %eax
xorl %edx, %edx
divl 0x60(%rsp)
testl %edx, %edx
je 0x3696
movl 0x1c(%rsp), %r8d
movq 0x38(%rsp), %r11
jmp 0x3718
movl 0x1c(%rsp), %r8d
movl %r8d, %eax
cltd
idivl 0x30(%rsp)
movslq 0x50(%rsp), %rcx
imulq $0x77777777, %rcx, %rsi # imm = 0x77777777
shrq $0x20, %rsi
subl %ecx, %esi
movl %esi, %edx
shrl $0x1f, %edx
sarl $0x4, %esi
addl %edx, %esi
addl %ecx, %esi
movq %rsi, 0x50(%rsp)
movl %esi, %r11d
subl %eax, %r8d
sarl $0x6, %r11d
cmpl $0x2, %r11d
movl $0x0, %eax
cmovll %eax, %r11d
jl 0x3718
movl %r11d, %ecx
imull %r11d, %ecx
cmpl $0x2, %r11d
movl $0x1, %esi
cmovgel %r11d, %esi
xorl %edi, %edi
movl %edi, %edx
imull %edi, %edx
movl %ecx, %eax
subl %edx, %eax
shll $0x8, %eax
cltd
idivl %ecx
imull %r8d, %eax
movl %eax, 0x1c00(%r12,%rdi,4)
incq %rdi
cmpq %rdi, %rsi
jne 0x36f5
cmpl 0x18(%rsp), %r9d
jne 0x330f
leaq 0x78(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop