// File: /workspace/github_cpp_makefile_star2_O3/myudelson[P]hmm-scalable/HMMProblemPiGK.cpp
// Function: HMMProblemPiGK::readModelBody(_IO_FILE*, param*, int*, bool)
void HMMProblemPiGK::readModelBody(FILE *fid, struct param* param, NDAT *line_no, bool overwrite) {
	NPAR i,j,m;
	NCAT k = 0, g = 0, idxk = 0, idxg = 0;
	string s;
    std::map<std::string,NCAT>::iterator it;
    char col[2048];
    //
    readNullObsRatio(fid, param, line_no);
    //
    // init param
    //
    if(overwrite) {
        this->p->map_group_fwd = new map<string,NCAT>();
        this->p->map_group_bwd = new map<NCAT,string>();
        this->p->map_skill_fwd = new map<string,NCAT>();
        this->p->map_skill_bwd = new map<NCAT,string>();
    }
	//
	// read grouped PIg
	//
    for(g=0; g<param->nG; g++) {
		// read group label
        fscanf(fid,"%*s\t%[^\n]\n",col);
        s = string( col );
        (*line_no)++;        
        if(overwrite) {
            this->p->map_group_fwd->insert(pair<string,NCAT>(s, (NCAT)this->p->map_group_fwd->size()));
            this->p->map_group_bwd->insert(pair<NCAT,string>((NCAT)this->p->map_group_bwd->size(), s));
            idxg = g;
        } else {
            it = this->p->map_group_fwd->find(s);
            if( it==this->p->map_group_fwd->end() ) { // not found, skip 3 lines and continue
                fscanf(fid,"%[^\n]\n",col);
                (*line_no)++;
                continue; // skip this iteration
            }
            else
                idxg =it->second;
        }

        // read PIg
        fscanf(fid,"PIg\t");
        for(i=0; i<(this->p->nS-1); i++) { // read 1 less then necessary
            fscanf(fid,"%[^\t]\t",col);
            this->PIg[idxg][i] = atof(col);
        }
        fscanf(fid,"%[^\n]\n",col);// read last one
        this->PIg[idxg][i] = atof(col);
        (*line_no)++;
    }
    //
    // read skills
    //
	for(k=0; k<param->nK; k++) {
		// read skill label
        fscanf(fid,"%*s\t%[^\n]\n",col);
        s = string( col );
        (*line_no)++;
        if(overwrite) {
            this->p->map_skill_fwd->insert(pair<string,NCAT>(s, (NCAT)this->p->map_skill_fwd->size()));
            this->p->map_skill_bwd->insert(pair<NCAT,string>((NCAT)this->p->map_skill_bwd->size(), s));
            idxk = k;
        } else {
            it = this->p->map_skill_fwd->find(s);
            if( it==this->p->map_skill_fwd->end() ) { // not found, skip 3 lines and continue
                fscanf(fid,"%*s\n");
                fscanf(fid,"%*s\n");
                fscanf(fid,"%*s\n");
                continue; // skip this iteration
            }
            else
                idxk =it->second;
        }
        
        // read PI
        fscanf(fid,"PIk\t");
        for(i=0; i<(this->p->nS-1); i++) { // read 1 less then necessary
            fscanf(fid,"%[^\t]\t",col);
            this->pi[idxk][i] = atof(col);
        }
        fscanf(fid,"%[^\n]\n",col);// read last one
        this->pi[idxk][i] = atof(col);
        (*line_no)++;
		// read A
        fscanf(fid,"A\t");
		for(i=0; i<this->p->nS; i++)
			for(j=0; j<this->p->nS; j++) {
                if(i==(this->p->nS-1) && j==(this->p->nS-1)) {
                    fscanf(fid,"%[^\n]\n", col); // last one;
                    this->A[idxk][i][j] = atof(col);
                }
                else {
                    fscanf(fid,"%[^\t]\t", col); // not las one
                    this->A[idxk][i][j] = atof(col);
                }
			}
        (*line_no)++;
		// read B
        fscanf(fid,"B\t");
		for(i=0; i<this->p->nS; i++)
			for(m=0; m<this->p->nO; m++) {
                if(i==(this->p->nS-1) && m==(this->p->nO-1)) {
                    fscanf(fid,"%[^\n]\n", col); // last one;
                    this->B[idxk][i][m] = atof(col);
                }
                else {
                    fscanf(fid,"%[^\t]\t", col); // not las one
                    this->B[idxk][i][m] = atof(col);
                }
			}
        (*line_no)++;
	} // for all k
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x878, %rsp            # imm = 0x878
movl %r8d, 0x3c(%rsp)
movq %rsi, %r12
movq %rdi, %r13
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
callq 0x190c2
cmpb $0x0, 0x3c(%rsp)
je 0x1b2fb
movl $0x30, %edi
callq 0x4210
movq %rax, %rcx
addq $0x8, %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
movq %rcx, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq $0x0, 0x28(%rax)
movq 0x88(%r13), %rbx
movq %rax, 0x920(%rbx)
movl $0x30, %edi
callq 0x4210
movq %rax, %rcx
addq $0x8, %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
movq %rcx, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq $0x0, 0x28(%rax)
movq %rax, 0x928(%rbx)
movl $0x30, %edi
callq 0x4210
movq %rax, %rcx
addq $0x8, %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
movq %rcx, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq $0x0, 0x28(%rax)
movq %rax, 0x940(%rbx)
movl $0x30, %edi
callq 0x4210
movq %rax, %rcx
addq $0x8, %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
movq %rcx, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq $0x0, 0x28(%rax)
movq %rax, 0x948(%rbx)
movq 0x48(%rsp), %rax
cmpl $0x0, 0x8bc(%rax)
jle 0x1b570
leaq 0x70(%rsp), %rbp
movl $0x0, 0xc(%rsp)
movq %r12, %rdi
leaq 0x19543(%rip), %rsi     # 0x34867
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4460
leaq 0x20(%rsp), %r14
movq %r14, 0x10(%rsp)
movq %rbp, %rdi
callq 0x4100
leaq (%rsp,%rax), %rdx
addq $0x70, %rdx
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xa7c0
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x42c0
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x1b37c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x40(%rsp), %rax
incl (%rax)
movq 0x88(%r13), %rax
movq 0x920(%rax), %r14
cmpb $0x0, 0x3c(%rsp)
je 0x1b45e
movq 0x28(%r14), %r15
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0xa6be
movl %r15d, 0x30(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x100c0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
leaq 0x19492(%rip), %rbx     # 0x3487a
je 0x1b3f7
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x88(%r13), %rax
movq 0x928(%rax), %r14
movl 0x28(%r14), %eax
movl %eax, 0x10(%rsp)
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rdi
callq 0xa6be
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x1028a
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x1b457
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4220
movl 0xc(%rsp), %r14d
jmp 0x1b491
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
callq 0xffc8
leaq 0x19408(%rip), %rbx     # 0x3487a
movq 0x88(%r13), %rcx
movq 0x920(%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0x1b55a
movl 0x40(%rax), %r14d
movq %r12, %rdi
leaq 0x194c4(%rip), %rsi     # 0x3495f
xorl %eax, %eax
callq 0x4460
movq 0x88(%r13), %rax
cmpb $0x2, 0x8b8(%rax)
movslq %r14d, %r14
jl 0x1b506
xorl %r15d, %r15d
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4460
movq %rbp, %rdi
callq 0x42d0
movq 0x90(%r13), %rax
movq (%rax,%r14,8), %rax
movsbq %r15b, %r15
movsd %xmm0, (%rax,%r15,8)
incb %r15b
movsbl %r15b, %eax
movq 0x88(%r13), %rcx
movsbl 0x8b8(%rcx), %ecx
decl %ecx
cmpl %eax, %ecx
jg 0x1b4b8
movsbq %r15b, %r15
jmp 0x1b509
xorl %r15d, %r15d
movq %r12, %rdi
leaq 0x19358(%rip), %rsi     # 0x3486b
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4460
movq %rbp, %rdi
callq 0x42d0
movq 0x90(%r13), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%r15,8)
movq 0x40(%rsp), %rax
incl (%rax)
movl 0xc(%rsp), %ecx
incl %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0xc(%rsp)
cmpl 0x8bc(%rax), %ecx
jl 0x1b31a
jmp 0x1b570
movq %r12, %rdi
leaq 0x19307(%rip), %rsi     # 0x3486b
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4460
jmp 0x1b536
movq 0x48(%rsp), %rax
cmpl $0x0, 0x8c0(%rax)
jle 0x1b933
leaq 0x70(%rsp), %rbp
leaq 0x10(%rsp), %r15
movl $0x0, 0xc(%rsp)
movq %r12, %rdi
leaq 0x192c9(%rip), %rsi     # 0x34867
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4460
leaq 0x20(%rsp), %rbx
movq %rbx, 0x10(%rsp)
movq %rbp, %rdi
callq 0x4100
leaq (%rsp,%rax), %rdx
addq $0x70, %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0xa7c0
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x42c0
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x1b5f1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x40(%rsp), %rax
incl (%rax)
movq 0x88(%r13), %rax
movq 0x940(%rax), %r14
cmpb $0x0, 0x3c(%rsp)
je 0x1b6c3
movq 0x28(%r14), %rbx
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0xa6be
movl %ebx, 0x30(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x100c0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x1b65f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x88(%r13), %rax
movq 0x948(%rax), %r14
movl 0x28(%r14), %eax
movl %eax, 0x10(%rsp)
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rdi
callq 0xa6be
movq %r14, %rdi
movq %r15, %rsi
callq 0x1028a
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x1b6bd
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4220
movl 0xc(%rsp), %ebx
jmp 0x1b6ee
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
callq 0xffc8
movq 0x88(%r13), %rcx
movq 0x940(%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0x1b8fe
movl 0x40(%rax), %ebx
movq %r12, %rdi
leaq 0x1926c(%rip), %rsi     # 0x34964
xorl %eax, %eax
callq 0x4460
movq 0x88(%r13), %rax
cmpb $0x2, 0x8b8(%rax)
movslq %ebx, %r14
jl 0x1b760
xorl %ebx, %ebx
movq %r12, %rdi
leaq 0x1915c(%rip), %rsi     # 0x3487a
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4460
movq %rbp, %rdi
callq 0x42d0
movq 0x38(%r13), %rax
movq (%rax,%r14,8), %rax
movsbq %bl, %rbx
movsd %xmm0, (%rax,%rbx,8)
incb %bl
movsbl %bl, %eax
movq 0x88(%r13), %rcx
movsbl 0x8b8(%rcx), %ecx
decl %ecx
cmpl %eax, %ecx
jg 0x1b714
movsbq %bl, %rbx
jmp 0x1b762
xorl %ebx, %ebx
movq %r12, %rdi
leaq 0x190ff(%rip), %rsi     # 0x3486b
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4460
movq %rbp, %rdi
callq 0x42d0
movq 0x38(%r13), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%rbx,8)
movq 0x40(%rsp), %rax
incl (%rax)
movq %r12, %rdi
leaq 0x18df6(%rip), %rsi     # 0x34592
xorl %eax, %eax
callq 0x4460
movq 0x88(%r13), %rax
movb 0x8b8(%rax), %al
testb %al, %al
jle 0x1b828
xorl %r15d, %r15d
testb %al, %al
jle 0x1b81c
xorl %ebx, %ebx
movsbl %al, %eax
decl %eax
movl %ebx, %ecx
xorl %eax, %ecx
xorl %r15d, %eax
orl %ecx, %eax
leaq 0x19099(%rip), %rsi     # 0x3486b
je 0x1b7db
leaq 0x1909f(%rip), %rsi     # 0x3487a
movq %r12, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4460
movq %rbp, %rdi
callq 0x42d0
movq 0x40(%r13), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movq 0x88(%r13), %rax
movb 0x8b8(%rax), %al
movsbq %al, %rcx
cmpq %rcx, %rbx
jl 0x1b7bd
jmp 0x1b820
movsbq %al, %rcx
incq %r15
cmpq %rcx, %r15
jl 0x1b7b7
movq 0x40(%rsp), %rax
incl (%rax)
movq %r12, %rdi
leaq 0x18d5c(%rip), %rsi     # 0x34595
xorl %eax, %eax
callq 0x4460
movq 0x88(%r13), %rax
cmpb $0x0, 0x8b8(%rax)
jle 0x1b8d5
xorl %r15d, %r15d
movb 0x8b9(%rax), %cl
testb %cl, %cl
jle 0x1b8c5
xorl %ebx, %ebx
movsbl %cl, %ecx
movsbl 0x8b8(%rax), %eax
decl %eax
xorl %r15d, %eax
decl %ecx
xorl %ebx, %ecx
orl %eax, %ecx
leaq 0x18fec(%rip), %rsi     # 0x3486b
je 0x1b888
leaq 0x18ff2(%rip), %rsi     # 0x3487a
movq %r12, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4460
movq %rbp, %rdi
callq 0x42d0
movq 0x48(%r13), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movq 0x88(%r13), %rax
movsbq 0x8b9(%rax), %rcx
cmpq %rcx, %rbx
jl 0x1b863
incq %r15
movsbq 0x8b8(%rax), %rcx
cmpq %rcx, %r15
jl 0x1b857
movq 0x40(%rsp), %rax
incl (%rax)
leaq 0x10(%rsp), %r15
movl 0xc(%rsp), %ecx
incl %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0xc(%rsp)
cmpl 0x8c0(%rax), %ecx
jl 0x1b594
jmp 0x1b933
movq %r12, %rdi
leaq 0x19136(%rip), %rsi     # 0x34a3e
xorl %eax, %eax
callq 0x4460
movq %r12, %rdi
leaq 0x19125(%rip), %rsi     # 0x34a3e
xorl %eax, %eax
callq 0x4460
movq %r12, %rdi
leaq 0x19114(%rip), %rsi     # 0x34a3e
xorl %eax, %eax
callq 0x4460
jmp 0x1b8e1
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x1b94f
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4220
addq $0x878, %rsp            # imm = 0x878
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1b9bb
jmp 0x1b9bb
jmp 0x1b9bb
jmp 0x1b9bb
jmp 0x1b96f
jmp 0x1b988
jmp 0x1b9bb
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x1b9be
movq 0x20(%rsp), %rsi
jmp 0x1b99f
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x1b9be
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4220
jmp 0x1b9be
jmp 0x1b9bb
jmp 0x1b9bb
jmp 0x1b9bb
jmp 0x1b9bb
jmp 0x1b9bb
jmp 0x1b9bb
jmp 0x1b9bb
jmp 0x1b9bb
jmp 0x1b9bb
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x1b9da
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4220
movq %rbx, %rdi
callq 0x4430
nop