// File: /workspace/github_cpp_makefile_star2_O1/myudelson[P]hmm-scalable/FitBitSlicedA.cpp
// Function: FitBitSlicedA::addL2Penalty(FIT_BIT_VAR, param*, double)
void FitBitSlicedA::addL2Penalty(enum FIT_BIT_VAR fbv, param* param, NUMBER factor) {
    NPAR i, j, m, z;
    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++) {
                this->gradPI[i] += factor * L2penalty(C, this->pi[i], param->Ccenters[ this->Cslice * nCenters + i] );
            }
            break;
        case FBV_A:
            for(z=0; z<this->nZ; z++) {
                for(i=0; i<this->nS; i++) {
                    for(j=0; j<this->nS; j++) {
                        matrixOff = this->nS;
                        rowOff = i*this->nS;
                        this->gradA[z][i][j] += factor * L2penalty(C, this->A[z][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++) {
                    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 FitBitSlicedA variable\n");
            break;
    }
}

// Assembly:
cmpb $0x0, 0x42(%rdx)
je 0xca47
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r13
movq %rdi, %r14
movq 0x48(%rdx), %rax
movsbq 0xe1(%rdi), %rcx
movsd (%rax,%rcx,8), %xmm3
movsbl 0x8b8(%rdx), %eax
movsbl 0x8b9(%rdx), %ecx
leal (%rax,%rcx), %ebp
incl %ebp
imull %eax, %ebp
cmpl $0x1, %esi
movsd %xmm0, 0x10(%rsp)
movsd %xmm3, 0x8(%rsp)
je 0xc8ee
cmpl $0x2, %esi
je 0xc954
cmpl $0x3, %esi
jne 0xca48
cmpb $0x0, 0x1(%r14)
jle 0xca39
movl $0x1, %r15d
xorl %r12d, %r12d
cmpb $0x0, (%r14)
jle 0xc8d9
xorl %ebx, %ebx
movsbl 0x1(%r14), %eax
movq 0x20(%r14), %rcx
movq (%rcx,%r12,8), %rcx
movsd (%rcx,%rbx,8), %xmm1
movq 0x50(%r13), %rcx
movsbl 0xe1(%r14), %edx
imull %ebp, %edx
leal (%r15,%rax), %esi
imull %eax, %esi
addl %ebx, %edx
addl %esi, %edx
movslq %edx, %rax
movsd (%rcx,%rax,8), %xmm2
movapd %xmm3, %xmm0
callq 0xa57f
movsd 0x8(%rsp), %xmm3
movq 0x68(%r14), %rax
movq (%rax,%r12,8), %rax
mulsd 0x10(%rsp), %xmm0
addsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movsbq (%r14), %rax
cmpq %rax, %rbx
jl 0xc872
incq %r12
movsbq 0x1(%r14), %rax
incl %r15d
cmpq %rax, %r12
jl 0xc86a
jmp 0xca39
cmpb $0x0, 0x1(%r14)
jle 0xca39
xorl %ebx, %ebx
movslq %ebp, %r15
movq 0x10(%r14), %rax
movsd (%rax,%rbx,8), %xmm1
movq 0x50(%r13), %rax
movsbq 0xe1(%r14), %rcx
imulq %r15, %rcx
addq %rbx, %rcx
movsd (%rax,%rcx,8), %xmm2
movapd %xmm3, %xmm0
callq 0xa57f
movsd 0x8(%rsp), %xmm3
movq 0x58(%r14), %rax
mulsd 0x10(%rsp), %xmm0
addsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movsbq 0x1(%r14), %rax
cmpq %rax, %rbx
jl 0xc8fe
jmp 0xca39
cmpb $0x0, 0x2(%r14)
jle 0xca39
xorl %r8d, %r8d
movq %r13, 0x20(%rsp)
movl %ebp, 0x1c(%rsp)
cmpb $0x0, 0x1(%r14)
jle 0xca28
movl $0x1, %ebp
xorl %r12d, %r12d
movb 0x1(%r14), %al
testb %al, %al
movq 0x20(%rsp), %rdx
movl 0x1c(%rsp), %edi
jle 0xca15
xorl %ebx, %ebx
movsbl %al, %eax
movq 0x18(%r14), %rcx
movq (%rcx,%r8,8), %rcx
movq (%rcx,%r12,8), %rcx
movsd (%rcx,%rbx,8), %xmm1
movq 0x50(%rdx), %rcx
movsbl 0xe1(%r14), %edx
imull %edi, %edx
imull %ebp, %eax
addl %ebx, %eax
addl %edx, %eax
cltq
movsd (%rcx,%rax,8), %xmm2
movapd %xmm3, %xmm0
movq %r14, %r15
movl %edi, %r14d
movq %r8, %r13
callq 0xa57f
movq %r13, %r8
movl %r14d, %edi
movq %r15, %r14
movq 0x20(%rsp), %rdx
movsd 0x8(%rsp), %xmm3
movq 0x60(%r15), %rax
movq (%rax,%r13,8), %rax
movq (%rax,%r12,8), %rax
mulsd 0x10(%rsp), %xmm0
addsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movsbq 0x1(%r15), %rax
cmpq %rax, %rbx
jl 0xc995
incq %r12
movsbq 0x1(%r14), %rax
incl %ebp
cmpq %rax, %r12
jl 0xc97e
incq %r8
movsbq 0x2(%r14), %rax
cmpq %rax, %r8
jl 0xc96b
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x481b
jmp 0xca39