// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/FitBit.cpp
// Function: FitBit::addL2Penalty(FIT_BIT_VAR, param*, double)
void FitBit::addL2Penalty(enum FIT_BIT_VAR fbv, param* param, NUMBER factor) {
    NPAR i, j, m;
    int matrixOff, rowOff;
    if(param->Cslices==0) return;
    NUMBER C = param->Cw[this->Cslice];
    int nCenters = (param->nS + param->nS*param->nS + param->nS*param->nO); // centers per slice
    switch (fbv) {
        case FBV_PI:
            for(i=0; i<this->nS; i++) {
                // single center of gravity per matrix
//                this->gradPI[i] += factor * L2penalty(C, this->pi[i], param->Ccenters[ this->Cslice * 3 + 0] );
                // center of gravity per parameter of matrix
                this->gradPI[i] += factor * L2penalty(C, this->pi[i], param->Ccenters[ this->Cslice * nCenters + i] );
            }
            break;
        case FBV_A:
            for(i=0; i<this->nS; i++)
                for(j=0; j<this->nS; j++) {
                    // single center of gravity per matrix
//                    this->gradA[i][j] += factor * L2penalty(C, this->A[i][j], param->Ccenters[ this->Cslice * 3 + 1] );
                    // center of gravity per parameter of matrix
                    matrixOff = this->nS;
                    rowOff = i*this->nS;
                    this->gradA[i][j] += factor * L2penalty(C, this->A[i][j], param->Ccenters[ this->Cslice * nCenters + matrixOff + rowOff + j] );
                }
            break;
        case FBV_B:
            for(i=0; i<this->nS; i++)
                for(m=0; m<this->nO; m++) {
                    // single center of gravity per matrix
//                    this->gradB[i][m] += factor * L2penalty(C, this->B[i][m], param->Ccenters[ this->Cslice * 3 + 2] );
                    // center of gravity per parameter of matrix
                    matrixOff = this->nS + this->nS*this->nS;
                    rowOff = i*this->nS;
                    this->gradB[i][m] += factor * L2penalty(C, this->B[i][m], param->Ccenters[ this->Cslice * nCenters + matrixOff + rowOff + m] );
                }
            break;
            
        default:
            fprintf(stderr,"Error, there is no such FitBit variable\n");
            break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movsd %xmm0, 0x10(%rsp)
cmpb $0x0, 0x42(%rdx)
je 0x92d8
movq %rdx, %rbx
movq %rdi, %r14
movq 0x48(%rdx), %rax
movsbq 0xfa(%rdi), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movsbl 0x8b8(%rdx), %eax
movsbl 0x8b9(%rdx), %ecx
leal (%rax,%rcx), %ebp
incl %ebp
imull %eax, %ebp
cmpl $0x1, %esi
je 0x91f6
cmpl $0x2, %esi
je 0x9252
cmpl $0x3, %esi
jne 0x92e7
pushq $0x1
popq %r15
xorl %r12d, %r12d
movsbq 0x1(%r14), %rax
cmpq %rax, %r12
jge 0x92d8
xorl %r13d, %r13d
movsbq (%r14), %rax
cmpq %rax, %r13
jge 0x91eb
movsbl 0x1(%r14), %eax
movq 0x20(%r14), %rcx
movq (%rcx,%r12,8), %rcx
movsd (%rcx,%r13,8), %xmm1
movq 0x50(%rbx), %rcx
movsbl 0xfa(%r14), %edx
imull %ebp, %edx
leal (%r15,%rax), %esi
imull %eax, %esi
addl %r13d, %edx
addl %esi, %edx
movslq %edx, %rax
movsd (%rcx,%rax,8), %xmm2
movsd 0x8(%rsp), %xmm0
callq 0x7d80
movq 0x68(%r14), %rax
movq (%rax,%r12,8), %rax
mulsd 0x10(%rsp), %xmm0
addsd (%rax,%r13,8), %xmm0
movsd %xmm0, (%rax,%r13,8)
incq %r13
jmp 0x9182
incq %r12
incl %r15d
jmp 0x9171
xorl %r15d, %r15d
movslq %ebp, %r12
movsbq 0x1(%r14), %rax
cmpq %rax, %r15
jge 0x92d8
movq 0x10(%r14), %rax
movsd (%rax,%r15,8), %xmm1
movq 0x50(%rbx), %rax
movsbq 0xfa(%r14), %rcx
imulq %r12, %rcx
addq %r15, %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x8(%rsp), %xmm0
callq 0x7d80
movq 0x58(%r14), %rax
mulsd 0x10(%rsp), %xmm0
addsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%rax,%r15,8)
incq %r15
jmp 0x91fc
movb 0x1(%r14), %al
pushq $0x1
popq %r15
xorl %r12d, %r12d
movsbq %al, %rcx
cmpq %rcx, %r12
jge 0x92d8
xorl %r13d, %r13d
movsbq %al, %rcx
cmpq %rcx, %r13
jge 0x92d0
movsbl %al, %eax
movq 0x18(%r14), %rcx
movq (%rcx,%r12,8), %rcx
movsd (%rcx,%r13,8), %xmm1
movq 0x50(%rbx), %rcx
movsbl 0xfa(%r14), %edx
imull %ebp, %edx
imull %r15d, %eax
addl %r13d, %eax
addl %edx, %eax
cltq
movsd (%rcx,%rax,8), %xmm2
movsd 0x8(%rsp), %xmm0
callq 0x7d80
movq 0x60(%r14), %rax
movq (%rax,%r12,8), %rax
mulsd 0x10(%rsp), %xmm0
addsd (%rax,%r13,8), %xmm0
movsd %xmm0, (%rax,%r13,8)
incq %r13
movb 0x1(%r14), %al
jmp 0x9269
incq %r12
incl %r15d
jmp 0x925d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2fcea(%rip), %rax     # 0x38fd8
movq (%rax), %rcx
leaq 0x239c1(%rip), %rdi     # 0x2ccb9
pushq $0x28
popq %rsi
pushq $0x1
popq %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x44b0