// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movsbl 0x42(%rax), %eax
cmpl $0x0, %eax
jne 0x10f52
jmp 0x11285
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movsbq 0xe1(%rcx), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x18(%rbp), %rdx
movsbl 0x8b8(%rdx), %ecx
movl %ecx, %esi
imull %esi, %esi
movl %ecx, %eax
addl %esi, %eax
movsbl 0x8b9(%rdx), %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x4c(%rbp)
subl $0x1, %eax
je 0x10fbf
jmp 0x10fa0
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0x11053
jmp 0x10fae
movl -0x4c(%rbp), %eax
subl $0x3, %eax
je 0x11178
jmp 0x1126d
movb $0x0, -0x21(%rbp)
movq -0x48(%rbp), %rcx
movsbl -0x21(%rbp), %eax
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0x1104e
movq -0x48(%rbp), %rcx
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x38(%rbp), %xmm0
movq 0x10(%rcx), %rax
movsbq -0x21(%rbp), %rdx
movsd (%rax,%rdx,8), %xmm1
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movsbl 0xe1(%rcx), %ecx
imull -0x3c(%rbp), %ecx
movsbl -0x21(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
callq 0xc360
movq -0x48(%rbp), %rax
movaps %xmm0, %xmm2
movsd -0x58(%rbp), %xmm0
movq 0x58(%rax), %rax
movsbq -0x21(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movb -0x21(%rbp), %al
addb $0x1, %al
movb %al, -0x21(%rbp)
jmp 0x10fc3
jmp 0x11285
movb $0x0, -0x24(%rbp)
movq -0x48(%rbp), %rcx
movsbl -0x24(%rbp), %eax
movsbl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x11173
movb $0x0, -0x21(%rbp)
movq -0x48(%rbp), %rcx
movsbl -0x21(%rbp), %eax
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0x11164
movb $0x0, -0x22(%rbp)
movq -0x48(%rbp), %rcx
movsbl -0x22(%rbp), %eax
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0x11155
movq -0x48(%rbp), %rcx
movsbl 0x1(%rcx), %eax
movl %eax, -0x28(%rbp)
movsbl -0x21(%rbp), %eax
movsbl 0x1(%rcx), %edx
imull %edx, %eax
movl %eax, -0x2c(%rbp)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x38(%rbp), %xmm0
movq 0x18(%rcx), %rax
movsbq -0x24(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movsbq -0x21(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movsbq -0x22(%rbp), %rdx
movsd (%rax,%rdx,8), %xmm1
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movsbl 0xe1(%rcx), %ecx
imull -0x3c(%rbp), %ecx
addl -0x28(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movsbl -0x22(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
callq 0xc360
movq -0x48(%rbp), %rax
movaps %xmm0, %xmm2
movsd -0x60(%rbp), %xmm0
movq 0x60(%rax), %rax
movsbq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x21(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x22(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movb -0x22(%rbp), %al
addb $0x1, %al
movb %al, -0x22(%rbp)
jmp 0x11087
jmp 0x11157
movb -0x21(%rbp), %al
addb $0x1, %al
movb %al, -0x21(%rbp)
jmp 0x1106f
jmp 0x11166
movb -0x24(%rbp), %al
addb $0x1, %al
movb %al, -0x24(%rbp)
jmp 0x11057
jmp 0x11285
movb $0x0, -0x21(%rbp)
movq -0x48(%rbp), %rcx
movsbl -0x21(%rbp), %eax
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0x1126b
movb $0x0, -0x23(%rbp)
movq -0x48(%rbp), %rcx
movsbl -0x23(%rbp), %eax
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x1125c
movq -0x48(%rbp), %rcx
movsbl 0x1(%rcx), %eax
movsbl 0x1(%rcx), %edx
movsbl 0x1(%rcx), %esi
imull %esi, %edx
addl %edx, %eax
movl %eax, -0x28(%rbp)
movsbl -0x21(%rbp), %eax
movsbl 0x1(%rcx), %edx
imull %edx, %eax
movl %eax, -0x2c(%rbp)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x38(%rbp), %xmm0
movq 0x20(%rcx), %rax
movsbq -0x21(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movsbq -0x23(%rbp), %rdx
movsd (%rax,%rdx,8), %xmm1
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movsbl 0xe1(%rcx), %ecx
imull -0x3c(%rbp), %ecx
addl -0x28(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movsbl -0x23(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
callq 0xc360
movq -0x48(%rbp), %rax
movaps %xmm0, %xmm2
movsd -0x68(%rbp), %xmm0
movq 0x68(%rax), %rax
movsbq -0x21(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x23(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movb -0x23(%rbp), %al
addb $0x1, %al
movb %al, -0x23(%rbp)
jmp 0x11194
jmp 0x1125e
movb -0x21(%rbp), %al
addb $0x1, %al
movb %al, -0x21(%rbp)
jmp 0x1117c
jmp 0x11285
movq 0x49d64(%rip), %rax     # 0x5afd8
movq (%rax), %rdi
leaq 0x3ec7e(%rip), %rsi     # 0x4fefc
movb $0x0, %al
callq 0x5440
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)