// File: /workspace/github_cpp_makefile_star2_O1/myudelson[P]hmm-scalable/FitBit.cpp
// Function: FitBit::doLog10ScaleGentle(FIT_BIT_SLOT)
void FitBit::doLog10ScaleGentle(enum FIT_BIT_SLOT fbs) {
	//    // fbs - gradient or direction
	NUMBER *a_PI = NULL;
	NUMBER **a_A = NULL;
	NUMBER **a_B = NULL;
	get(fbs, a_PI, a_A, a_B);
	
	
	NPAR nS = this->nS, nO = this->nO;
	NDAT n = (  (this->pi != NULL)*1 + (this->A != NULL)*nS + (this->B != NULL)*nO  ) * nS;
	NUMBER* grad = Calloc(NUMBER, n);
	NUMBER* par = Calloc(NUMBER, n);
	NDAT cpar = 0, cgrad = 0;
	for(NPAR i=0; i<nS; i++) {
		if(this->pi != NULL) { par[cpar++] = this->pi[i]; grad[cgrad++] = a_PI[i]; }
		if(this->A  != NULL) for(NPAR j=0; j<nS; j++) { par[cpar++] = this->A[i][j]; grad[cgrad++] = a_A[i][j]; }
		if(this->B  != NULL) for(NPAR m=0; m<nO; m++) { par[cpar++] = this->B[i][m]; grad[cgrad++] = a_B[i][m]; }
	}
	
	NUMBER scale = doLog10Scale1DGentle(grad, par, (NPAR)n);
	
	for(NPAR i=0; i<nS; i++) {
		if(this->pi != NULL) { a_PI[i] *= scale; }
		if(this->A  != NULL) for(NPAR j=0; j<nS; j++) { a_A[i][j] *= scale; }
		if(this->B  != NULL) for(NPAR m=0; m<nO; m++) { a_B[i][m] *= scale; }
	}
	free(grad);
	free(par);
	
	//	if(this->pi != NULL) doLog10Scale1DGentle(a_PI, this->pi, this->nS);
	//	if(this->A  != NULL) doLog10Scale2DGentle(a_A,  this->A,  this->nS, this->nS);
	//	if(this->B  != NULL) doLog10Scale2DGentle(a_B,  this->B,  this->nS, this->nO);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r14
xorl %ebp, %ebp
leaq 0x40(%rsp), %rdx
movq %rbp, (%rdx)
leaq 0x38(%rsp), %rcx
movq %rbp, (%rcx)
leaq 0x30(%rsp), %r8
movq %rbp, (%r8)
callq 0xaff2
movsbl 0x1(%r14), %r12d
movsbl (%r14), %r13d
movq 0x10(%r14), %r15
movq 0x18(%r14), %rbx
testq %rbx, %rbx
movl %r12d, %eax
cmovel %ebp, %eax
cmpq $0x1, %r15
sbbl $-0x1, %eax
movq %r14, 0x48(%rsp)
movq 0x20(%r14), %rcx
movq %rcx, 0x28(%rsp)
testq %rcx, %rcx
movl %r13d, %ecx
cmovel %ebp, %ecx
addl %eax, %ecx
imull %r12d, %ecx
movl %ecx, 0x24(%rsp)
movslq %ecx, %r14
movl $0x8, %esi
movq %r14, %rdi
callq 0x4130
movq %rax, 0x18(%rsp)
movl $0x8, %esi
movq %r14, %rdi
callq 0x4130
movq %rax, 0x10(%rsp)
movl %r12d, %eax
movslq %r12d, %r12
movzbl %r13b, %r13d
testl %eax, %eax
jle 0xb692
cmpq $0x0, 0x28(%rsp)
sete %al
movq 0x40(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movq 0x38(%rsp), %rcx
movq %rcx, 0x58(%rsp)
testb %r13b, %r13b
setle %cl
movq 0x30(%rsp), %rdx
movq %rdx, 0x50(%rsp)
orb %al, %cl
movb %cl, 0xf(%rsp)
leaq (,%r12,8), %rdi
leal (,%r13,8), %r8d
xorl %r9d, %r9d
xorl %r10d, %r10d
testq %r15, %r15
je 0xb5d1
movsd (%r15,%r9,8), %xmm0
movslq %ebp, %rax
incl %ebp
movq 0x10(%rsp), %rcx
movsd %xmm0, (%rcx,%rax,8)
movq 0x60(%rsp), %rax
movsd (%rax,%r9,8), %xmm0
movslq %r10d, %rax
incl %r10d
movq 0x18(%rsp), %rcx
movsd %xmm0, (%rcx,%rax,8)
testq %rbx, %rbx
je 0xb628
movq (%rbx,%r9,8), %r11
movq 0x58(%rsp), %rax
movq (%rax,%r9,8), %rsi
movslq %ebp, %rax
movslq %r10d, %rcx
movq 0x18(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
movq 0x10(%rsp), %rdx
leaq (%rdx,%rax,8), %rdx
xorl %eax, %eax
xorl %r14d, %r14d
movsd (%r11,%r14), %xmm0
movsd %xmm0, (%rdx,%r14)
movsd (%rsi,%r14), %xmm0
movsd %xmm0, (%rcx,%r14)
addq $0x8, %r14
decl %eax
cmpq %r14, %rdi
jne 0xb600
subl %eax, %r10d
subl %eax, %ebp
cmpb $0x0, 0xf(%rsp)
jne 0xb686
movq 0x28(%rsp), %rax
movq (%rax,%r9,8), %r11
movq 0x50(%rsp), %rax
movq (%rax,%r9,8), %rsi
movslq %ebp, %rax
movslq %r10d, %rcx
movq 0x18(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
movq 0x10(%rsp), %rdx
leaq (%rdx,%rax,8), %rdx
xorl %eax, %eax
xorl %r14d, %r14d
movsd (%r11,%r14), %xmm0
movsd %xmm0, (%rdx,%r14)
movsd (%rsi,%r14), %xmm0
movsd %xmm0, (%rcx,%r14)
addq $0x8, %r14
decl %eax
cmpq %r14, %r8
jne 0xb65e
subl %eax, %r10d
subl %eax, %ebp
incq %r9
cmpq %r12, %r9
jne 0xb59c
movsbl 0x24(%rsp), %edx
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x93b6
testb %r12b, %r12b
jle 0xb746
movq 0x48(%rsp), %rdi
movq 0x10(%rdi), %rax
movq 0x18(%rdi), %rcx
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rsi
cmpq $0x0, 0x20(%rdi)
sete %r9b
testb %r13b, %r13b
setle %dil
movq 0x30(%rsp), %r8
orb %r9b, %dil
xorl %r9d, %r9d
testq %rax, %rax
je 0xb6f6
movsd (%rdx,%r9,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%r9,8)
testq %rcx, %rcx
je 0xb71a
movq (%rsi,%r9,8), %r10
xorl %r11d, %r11d
movsd (%r10,%r11,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%r10,%r11,8)
incq %r11
cmpq %r11, %r12
jne 0xb702
testb %dil, %dil
jne 0xb73e
movq (%r8,%r9,8), %r10
xorl %r11d, %r11d
movsd (%r10,%r11,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%r10,%r11,8)
incq %r11
cmpq %r11, %r13
jne 0xb726
incq %r9
cmpq %r12, %r9
jne 0xb6e1
movq 0x18(%rsp), %rdi
callq 0x42a0
movq 0x10(%rsp), %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42a0