// File: /workspace/github_cpp_makefile_star2_O3/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 0xc8f1
cmpl $0x2, %esi
je 0xc957
cmpl $0x3, %esi
jne 0xca48
movb 0x1(%r14), %cl
testb %cl, %cl
jle 0xca39
movb (%r14), %al
movl $0x1, %r15d
xorl %r12d, %r12d
testb %al, %al
jle 0xc8dd
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 0xa57c
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
movb 0x1(%r14), %cl
incq %r12
movsbq %cl, %rdx
incl %r15d
cmpq %rdx, %r12
jl 0xc86c
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 0xa57c
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 0xc901
jmp 0xca39
movb 0x2(%r14), %cl
testb %cl, %cl
jle 0xca39
movb 0x1(%r14), %al
xorl %edi, %edi
movq %r13, 0x20(%rsp)
movl %ebp, 0x1c(%rsp)
movl 0x1c(%rsp), %r12d
testb %al, %al
jle 0xca29
movl $0x1, %r15d
xorl %r13d, %r13d
testb %al, %al
jle 0xca12
xorl %ebx, %ebx
movsbl %al, %eax
movq 0x18(%r14), %rcx
movq (%rcx,%rdi,8), %rcx
movq (%rcx,%r13,8), %rcx
movsd (%rcx,%rbx,8), %xmm1
movq 0x20(%rsp), %rcx
movq 0x50(%rcx), %rcx
movsbl 0xe1(%r14), %edx
imull %r12d, %edx
imull %r15d, %eax
addl %ebx, %eax
addl %edx, %eax
cltq
movsd (%rcx,%rax,8), %xmm2
movapd %xmm3, %xmm0
movq %r14, %rbp
movq %rdi, %r14
callq 0xa57c
movq %r14, %rdi
movq %rbp, %r14
movsd 0x8(%rsp), %xmm3
movq 0x60(%rbp), %rax
movq (%rax,%rdi,8), %rax
movq (%rax,%r13,8), %rax
mulsd 0x10(%rsp), %xmm0
addsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movb 0x1(%rbp), %al
movsbq %al, %rcx
cmpq %rcx, %rbx
jl 0xc992
jmp 0xca16
movsbq %al, %rcx
incq %r13
incl %r15d
cmpq %rcx, %r13
jl 0xc988
movb 0x2(%r14), %cl
incq %rdi
movsbq %cl, %rdx
cmpq %rdx, %rdi
jl 0xc977
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x483b
jmp 0xca39