// File: 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
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 0xf232
jmp 0xf52c
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movsbq 0xfa(%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 0xf29f
jmp 0xf280
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0xf333
jmp 0xf28e
movl -0x4c(%rbp), %eax
subl $0x3, %eax
je 0xf41f
jmp 0xf514
movb $0x0, -0x21(%rbp)
movq -0x48(%rbp), %rcx
movsbl -0x21(%rbp), %eax
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0xf32e
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 0xfa(%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 0xf2a3
jmp 0xf52c
movb $0x0, -0x21(%rbp)
movq -0x48(%rbp), %rcx
movsbl -0x21(%rbp), %eax
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0xf41a
movb $0x0, -0x22(%rbp)
movq -0x48(%rbp), %rcx
movsbl -0x22(%rbp), %eax
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0xf40b
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 -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 0xfa(%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 -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 0xf34f
jmp 0xf40d
movb -0x21(%rbp), %al
addb $0x1, %al
movb %al, -0x21(%rbp)
jmp 0xf337
jmp 0xf52c
movb $0x0, -0x21(%rbp)
movq -0x48(%rbp), %rcx
movsbl -0x21(%rbp), %eax
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0xf512
movb $0x0, -0x23(%rbp)
movq -0x48(%rbp), %rcx
movsbl -0x23(%rbp), %eax
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xf503
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 0xfa(%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 0xf43b
jmp 0xf505
movb -0x21(%rbp), %al
addb $0x1, %al
movb %al, -0x21(%rbp)
jmp 0xf423
jmp 0xf52c
movq 0x4babd(%rip), %rax     # 0x5afd8
movq (%rax), %rdi
leaq 0x4090b(%rip), %rsi     # 0x4fe30
movb $0x0, %al
callq 0x5440
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)