// File: ATOMIC-LICHESS[P]ATOMKRAFT/tuning.cpp
// Function: VarTuning::VarTuning(int, ...)
VarTuning::VarTuning(int s, ...) {
	
	for (int k = abs(rand() % 10000); k > 0; --k) {
		rkiss.rand<unsigned>();
	}
	
	updateCount = 0;
	size = s;
	
	assert(size >= 0 && size < 100);
	
	va_list vl;
	va_start(vl, s);
	for (int k = 0; k < size; ++k) {
		var[k].valueptr = (tune_t*)va_arg(vl, double*);
		var[k].value = *var[k].valueptr;
		var[k].startvalue = *var[k].valueptr;
		var[k].deltaAxisFactor = DELTA_AXIS_FACTOR;
		var[k].sdevSum = 0.0;
		var[k].varSum = 0.0;
		var[k].applyFactor = APPLY_FACTOR;
		memset(var[k].history, 0, sizeof(tune_t) * TUNE_HISTORY_SIZE);
		var[k].historyIndex = 0;
	}
	va_end(vl);
	
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
testb %al, %al
je 0x51a82
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
movq %r9, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq %rdi, 0x100(%rsp)
movl %esi, 0xfc(%rsp)
movq 0x100(%rsp), %rdi
movq %rdi, 0x18(%rsp)
addq $0x29cc8, %rdi          # imm = 0x29CC8
callq 0xf5f0
callq 0x6140
movl $0x2710, %ecx           # imm = 0x2710
cltd
idivl %ecx
movl %edx, %eax
negl %eax
cmovnsl %eax, %edx
movl %edx, 0xf8(%rsp)
cmpl $0x0, 0xf8(%rsp)
jle 0x51b07
movq 0x18(%rsp), %rdi
addq $0x29cc8, %rdi          # imm = 0x29CC8
callq 0xf600
movl 0xf8(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xf8(%rsp)
jmp 0x51ad9
movq 0x18(%rsp), %rax
movl $0x0, 0x29cc4(%rax)
movl 0xfc(%rsp), %ecx
movl %ecx, 0x29cc0(%rax)
leaq 0xe0(%rsp), %rax
leaq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x110(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
movl $0x0, 0xdc(%rsp)
movq 0x18(%rsp), %rcx
movl 0xdc(%rsp), %eax
cmpl 0x29cc0(%rcx), %eax
jge 0x51d24
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0xe0(%rsp), %eax
movl %eax, 0x14(%rsp)
cmpl $0x28, %eax
ja 0x51ba8
movq 0x8(%rsp), %rcx
movl 0x14(%rsp), %edx
movslq %edx, %rax
addq 0x10(%rcx), %rax
addl $0x8, %edx
movl %edx, (%rcx)
movq %rax, (%rsp)
jmp 0x51bc0
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x8(%rcx)
movq %rax, (%rsp)
movq 0x18(%rsp), %rdi
movq (%rsp), %rax
movq (%rax), %rcx
movslq 0xdc(%rsp), %rax
imulq $0x6b0, %rax, %rdx      # imm = 0x6B0
movq %rdi, %rax
addq %rdx, %rax
movq %rcx, (%rax)
movslq 0xdc(%rsp), %rax
imulq $0x6b0, %rax, %rcx      # imm = 0x6B0
movq %rdi, %rax
addq %rcx, %rax
movq (%rax), %rax
movsd (%rax), %xmm0
movslq 0xdc(%rsp), %rax
imulq $0x6b0, %rax, %rcx      # imm = 0x6B0
movq %rdi, %rax
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movslq 0xdc(%rsp), %rax
imulq $0x6b0, %rax, %rcx      # imm = 0x6B0
movq %rdi, %rax
addq %rcx, %rax
movq (%rax), %rax
movsd (%rax), %xmm0
movslq 0xdc(%rsp), %rax
imulq $0x6b0, %rax, %rcx      # imm = 0x6B0
movq %rdi, %rax
addq %rcx, %rax
movsd %xmm0, 0x10(%rax)
movslq 0xdc(%rsp), %rax
imulq $0x6b0, %rax, %rcx      # imm = 0x6B0
movq %rdi, %rax
addq %rcx, %rax
movsd 0xa143(%rip), %xmm0     # 0x5bdb0
movsd %xmm0, 0x28(%rax)
movslq 0xdc(%rsp), %rax
imulq $0x6b0, %rax, %rcx      # imm = 0x6B0
movq %rdi, %rax
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rax)
movslq 0xdc(%rsp), %rax
imulq $0x6b0, %rax, %rcx      # imm = 0x6B0
movq %rdi, %rax
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rax)
movslq 0xdc(%rsp), %rax
imulq $0x6b0, %rax, %rcx      # imm = 0x6B0
movq %rdi, %rax
addq %rcx, %rax
movsd 0xa0df(%rip), %xmm0     # 0x5bda8
movsd %xmm0, 0x30(%rax)
movslq 0xdc(%rsp), %rax
imulq $0x6b0, %rax, %rax      # imm = 0x6B0
addq %rax, %rdi
addq $0x68, %rdi
xorl %esi, %esi
movl $0x640, %edx            # imm = 0x640
callq 0x6280
movq 0x18(%rsp), %rax
movslq 0xdc(%rsp), %rcx
imulq $0x6b0, %rcx, %rcx      # imm = 0x6B0
addq %rcx, %rax
movl $0x0, 0x60(%rax)
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x51b58
addq $0x108, %rsp            # imm = 0x108
retq
nopl (%rax)