// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/FitBit.cpp
// Function: FitBit::checkConvergence(FitResult*)
bool FitBit::checkConvergence(FitResult *fr) {
    
    NUMBER criterion = 0;
    NUMBER criterion_oscil = 0; // oscillation between PAR and PARm1, i.e. PAR is close to PARm2
    bool res = false;
    switch (this->tol_mode) {
        case 'p':
            for(NPAR i=0; i<this->nS; i++)
            {
                if(this->pi != NULL) criterion += pow( this->pi[i]-this->PIm1[i], 2 )/*:0*/;
                for(NPAR j=0; (this->A != NULL) && j<this->nS; j++) {
                    criterion += pow(this->A[i][j] - this->Am1[i][j],2);
                }
                for(NPAR k=0; (this->B != NULL) && k<this->nO; k++) {
                    criterion += pow(this->B[i][k] - this->Bm1[i][k],2);
                }
            }
            
            if( (!(sqrt(criterion) < this->tol)) && ( this->PIm2 != NULL || this->Am2 != NULL || this->Bm2 != NULL ) ) {
                for(NPAR i=0; i<this->nS; i++)
                {
                    if(this->pi != NULL) criterion_oscil += pow( this->pi[i]-this->PIm2[i], 2 )/*:0*/;
                    for(NPAR j=0; (this->A != NULL) && j<this->nS; j++) {
                        criterion_oscil += pow(this->A[i][j] - this->Am2[i][j],2);
                    }
                    for(NPAR k=0; (this->B != NULL) && k<this->nO; k++) {
                        criterion_oscil += pow(this->B[i][k] - this->Bm2[i][k],2);
                    }
                }
                res = sqrt(criterion_oscil) < this->tol; // double the truth or false
            }
            else
                res = sqrt(criterion) < this->tol; // double the truth or false
            break;
        case 'l':
            criterion = (fr->pOmid-fr->pO)/fr->ndat;
            res = criterion < this->tol;
            break;
    }
    return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movzbl 0x108(%rdi), %eax
cmpl $0x6c, %eax
je 0x8ad6
cmpl $0x70, %eax
jne 0x8aee
movsbq 0x1(%rbx), %rax
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %rdx
movq 0x28(%rbx), %rsi
movq 0x30(%rbx), %rdi
movq 0x20(%rbx), %r8
movsbq (%rbx), %r9
movq 0x38(%rbx), %r10
xorl %r11d, %r11d
testb %al, %al
movl $0x0, %ebp
cmovgl %eax, %ebp
movslq %ebp, %r14
xorpd %xmm2, %xmm2
cmpq %r14, %r11
je 0x8ac6
testq %rcx, %rcx
je 0x8a65
movsd (%rcx,%r11,8), %xmm0
subsd (%rsi,%r11,8), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm0, %xmm2
xorl %r15d, %r15d
testq %rdx, %rdx
je 0x8a93
cmpq %rax, %r15
jge 0x8a93
movq (%rdx,%r11,8), %r12
movsd (%r12,%r15,8), %xmm0
movq (%rdi,%r11,8), %r12
subsd (%r12,%r15,8), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm0, %xmm2
incq %r15
jmp 0x8a68
xorl %r15d, %r15d
testq %r8, %r8
je 0x8ac1
cmpq %r9, %r15
jge 0x8ac1
movq (%r8,%r11,8), %r12
movsd (%r12,%r15,8), %xmm0
movq (%r10,%r11,8), %r12
subsd (%r12,%r15,8), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm0, %xmm2
incq %r15
jmp 0x8a96
incq %r11
jmp 0x8a47
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jb 0x8af5
sqrtsd %xmm2, %xmm0
jmp 0x8b0a
movsd 0x10(%rsi), %xmm0
subsd 0x18(%rsi), %xmm0
cvtsi2sdl 0x24(%rsi), %xmm1
divsd %xmm1, %xmm0
jmp 0x8c09
xorl %eax, %eax
jmp 0x8c18
movapd %xmm2, %xmm0
movsd %xmm2, 0x8(%rsp)
callq 0x41a0
movsd 0x8(%rsp), %xmm2
movsd 0x100(%rbx), %xmm1
ucomisd %xmm0, %xmm1
ja 0x8b2f
movq 0x40(%rbx), %rax
movq 0x48(%rbx), %rcx
movq %rax, %rsi
orq %rcx, %rsi
movq 0x50(%rbx), %rdx
orq %rdx, %rsi
jne 0x8b4b
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jb 0x8b42
sqrtsd %xmm2, %xmm0
jmp 0x8c09
movapd %xmm2, %xmm0
jmp 0x8c04
movsbq 0x1(%rbx), %rsi
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %r8
movq 0x20(%rbx), %r9
movsbq (%rbx), %r10
xorl %r11d, %r11d
testb %sil, %sil
movl $0x0, %ebp
cmovgl %esi, %ebp
movslq %ebp, %r14
xorpd %xmm0, %xmm0
cmpq %r14, %r11
je 0x8bf4
testq %rdi, %rdi
je 0x8b93
movsd (%rdi,%r11,8), %xmm1
subsd (%rax,%r11,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
xorl %r15d, %r15d
testq %r8, %r8
je 0x8bc1
cmpq %rsi, %r15
jge 0x8bc1
movq (%r8,%r11,8), %r12
movsd (%r12,%r15,8), %xmm1
movq (%rcx,%r11,8), %r12
subsd (%r12,%r15,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %r15
jmp 0x8b96
xorl %r15d, %r15d
testq %r9, %r9
je 0x8bef
cmpq %r10, %r15
jge 0x8bef
movq (%r9,%r11,8), %r12
movsd (%r12,%r15,8), %xmm1
movq (%rdx,%r11,8), %r12
subsd (%r12,%r15,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %r15
jmp 0x8bc4
incq %r11
jmp 0x8b75
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x8c04
sqrtsd %xmm0, %xmm0
jmp 0x8c09
callq 0x41a0
movsd 0x100(%rbx), %xmm1
ucomisd %xmm0, %xmm1
seta %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop