// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movzbl 0x108(%rdi), %eax
cmpl $0x6c, %eax
je 0xb28b
cmpl $0x70, %eax
jne 0xb2a3
movsbq 0x1(%rbx), %rax
xorpd %xmm0, %xmm0
xorpd %xmm2, %xmm2
testq %rax, %rax
jle 0xb27c
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %rdx
movq 0x28(%rbx), %rsi
movq 0x30(%rbx), %rdi
movq 0x20(%rbx), %r8
testq %r8, %r8
setne %r11b
movsbq (%rbx), %r9
testq %r9, %r9
setg %r10b
andb %r11b, %r10b
movq 0x38(%rbx), %r11
xorl %r14d, %r14d
testq %rcx, %rcx
je 0xb21c
movsd (%rcx,%r14,8), %xmm1
subsd (%rsi,%r14,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm2
testq %rdx, %rdx
je 0xb248
movq (%rdx,%r14,8), %r15
movq (%rdi,%r14,8), %r12
xorl %r13d, %r13d
movsd (%r15,%r13,8), %xmm1
subsd (%r12,%r13,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm2
incq %r13
cmpq %rax, %r13
jb 0xb22c
testb %r10b, %r10b
je 0xb274
movq (%r8,%r14,8), %r15
movq (%r11,%r14,8), %r12
xorl %r13d, %r13d
movsd (%r15,%r13,8), %xmm1
subsd (%r12,%r13,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm2
incq %r13
cmpq %r9, %r13
jl 0xb258
incq %r14
cmpq %rax, %r14
jne 0xb203
ucomisd %xmm0, %xmm2
jb 0xb2aa
xorps %xmm0, %xmm0
sqrtsd %xmm2, %xmm0
jmp 0xb2bd
movsd 0x10(%rsi), %xmm0
subsd 0x18(%rsi), %xmm0
cvtsi2sdl 0x24(%rsi), %xmm1
divsd %xmm1, %xmm0
jmp 0xb3c5
xorl %eax, %eax
jmp 0xb3d4
movapd %xmm2, %xmm0
movsd %xmm2, (%rsp)
callq 0x41a0
movsd (%rsp), %xmm2
movsd 0x100(%rbx), %xmm1
ucomisd %xmm0, %xmm1
ja 0xb2e2
movq 0x40(%rbx), %rax
movq 0x48(%rbx), %rcx
movq %rax, %rsi
orq %rcx, %rsi
movq 0x50(%rbx), %rdx
orq %rdx, %rsi
jne 0xb301
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jb 0xb2f8
xorps %xmm0, %xmm0
sqrtsd %xmm2, %xmm0
jmp 0xb3c5
movapd %xmm2, %xmm0
jmp 0xb3c0
movsbq 0x1(%rbx), %rsi
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
testq %rsi, %rsi
jle 0xb3b4
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %r8
movq 0x20(%rbx), %r9
testq %r9, %r9
setne %bpl
movsbq (%rbx), %r10
testq %r10, %r10
setg %r11b
andb %bpl, %r11b
xorl %r14d, %r14d
testq %rdi, %rdi
je 0xb354
movsd (%rdi,%r14,8), %xmm2
subsd (%rax,%r14,8), %xmm2
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm0
testq %r8, %r8
je 0xb380
movq (%r8,%r14,8), %r15
movq (%rcx,%r14,8), %r12
xorl %r13d, %r13d
movsd (%r15,%r13,8), %xmm2
subsd (%r12,%r13,8), %xmm2
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm0
incq %r13
cmpq %rsi, %r13
jb 0xb364
testb %r11b, %r11b
je 0xb3ac
movq (%r9,%r14,8), %r15
movq (%rdx,%r14,8), %r12
xorl %r13d, %r13d
movsd (%r15,%r13,8), %xmm2
subsd (%r12,%r13,8), %xmm2
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm0
incq %r13
cmpq %r10, %r13
jl 0xb390
incq %r14
cmpq %rsi, %r14
jne 0xb33b
ucomisd %xmm1, %xmm0
jb 0xb3c0
sqrtsd %xmm0, %xmm0
jmp 0xb3c5
callq 0x41a0
movsd 0x100(%rbx), %xmm1
ucomisd %xmm0, %xmm1
seta %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop