// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movsd %xmm0, 0x10(%rsp)
movq %rdx, (%rsp)
cmpb $0x0, 0x42(%rdx)
je 0xa02b
movq %rdi, %r14
movq (%rsp), %rdx
movq 0x48(%rdx), %rax
movsbq 0xe1(%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 0x9f26
cmpl $0x2, %esi
je 0x9f82
cmpl $0x3, %esi
jne 0xa03a
pushq $0x1
popq %r15
xorl %r12d, %r12d
movsbq 0x1(%r14), %rax
cmpq %rax, %r12
jge 0xa02b
xorl %ebx, %ebx
movsbq (%r14), %rax
cmpq %rax, %rbx
jge 0x9f1b
movsbl 0x1(%r14), %eax
movq 0x20(%r14), %rcx
movq (%rcx,%r12,8), %rcx
movsd (%rcx,%rbx,8), %xmm1
movq (%rsp), %rcx
movq 0x50(%rcx), %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
movsd 0x8(%rsp), %xmm0
callq 0x7d80
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
jmp 0x9eb2
incq %r12
incl %r15d
jmp 0x9ea2
xorl %ebx, %ebx
movslq %ebp, %r15
movsbq 0x1(%r14), %rax
cmpq %rax, %rbx
jge 0xa02b
movq 0x10(%r14), %rax
movsd (%rax,%rbx,8), %xmm1
movq (%rsp), %rax
movq 0x50(%rax), %rax
movsbq 0xe1(%r14), %rcx
imulq %r15, %rcx
addq %rbx, %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x8(%rsp), %xmm0
callq 0x7d80
movq 0x58(%r14), %rax
mulsd 0x10(%rsp), %xmm0
addsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
jmp 0x9f2b
xorl %r15d, %r15d
movsbq 0x2(%r14), %rax
cmpq %rax, %r15
jge 0xa02b
movb 0x1(%r14), %al
pushq $0x1
popq %r13
xorl %r12d, %r12d
movsbq %al, %rcx
cmpq %rcx, %r12
jge 0xa023
xorl %ebx, %ebx
movsbq %al, %rcx
cmpq %rcx, %rbx
jge 0xa018
movsbl %al, %eax
movq 0x18(%r14), %rcx
movq (%rcx,%r15,8), %rcx
movq (%rcx,%r12,8), %rcx
movsd (%rcx,%rbx,8), %xmm1
movq (%rsp), %rcx
movq 0x50(%rcx), %rcx
movsbl 0xe1(%r14), %edx
imull %ebp, %edx
imull %r13d, %eax
addl %ebx, %eax
addl %edx, %eax
cltq
movsd (%rcx,%rax,8), %xmm2
movsd 0x8(%rsp), %xmm0
callq 0x7d80
movq 0x60(%r14), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r12,8), %rax
mulsd 0x10(%rsp), %xmm0
addsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movb 0x1(%r14), %al
jmp 0x9fa9
incq %r12
incl %r13d
jmp 0x9f9e
incq %r15
jmp 0x9f85
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2ef97(%rip), %rax     # 0x38fd8
movq (%rax), %rcx
leaq 0x22d75(%rip), %rdi     # 0x2cdc0
pushq $0x2f
popq %rsi
pushq $0x1
popq %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x44b0