// File: /workspace/github_cpp_makefile_star2_O2/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, 0x14(%rsp)
movq %rsi, %r12
movq %rdi, %r13
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq %rdx, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
callq 0x15374
cmpb $0x0, 0x14(%rsp)
je 0x171ac
pushq $0x30
popq %rdi
callq 0x4220
movq %rax, %rcx
addq $0x8, %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
movq %rcx, 0x18(%rax)
movq %rcx, 0x20(%rax)
andq $0x0, 0x28(%rax)
movq 0x88(%r13), %rbx
movq %rax, 0x920(%rbx)
pushq $0x30
popq %rdi
callq 0x4220
movq %rax, %rcx
addq $0x8, %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
movq %rcx, 0x18(%rax)
movq %rcx, 0x20(%rax)
andq $0x0, 0x28(%rax)
movq %rax, 0x928(%rbx)
pushq $0x30
popq %rdi
callq 0x4220
movq %rax, %rcx
addq $0x8, %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
movq %rcx, 0x18(%rax)
movq %rcx, 0x20(%rax)
andq $0x0, 0x28(%rax)
movq %rax, 0x940(%rbx)
pushq $0x30
popq %rdi
callq 0x4220
movq %rax, %rcx
addq $0x8, %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
movq %rcx, 0x18(%rax)
movq %rcx, 0x20(%rax)
andq $0x0, 0x28(%rax)
movq %rax, 0x948(%rbx)
leaq 0x70(%rsp), %r15
xorl %ecx, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x10(%rsp)
cmpl 0x8bc(%rax), %ecx
jge 0x17363
movq %r12, %rdi
leaq 0x16695(%rip), %rsi     # 0x2d867
movq %r15, %rdx
xorl %eax, %eax
callq 0x4480
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
leaq 0xf(%rsp), %rdx
callq 0x7dea
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x42b0
movq %rbp, %rdi
callq 0x40f0
movq 0x18(%rsp), %rax
incl (%rax)
movq 0x88(%r13), %rax
movq 0x920(%rax), %r14
cmpb $0x0, 0x14(%rsp)
je 0x1728b
movq %rbx, %rsi
movq 0x28(%r14), %rbx
movq %rbp, %rdi
callq 0x4320
movl %ebx, 0x48(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0xcf7e
movq %rbp, %rdi
callq 0x40f0
movq 0x88(%r13), %rax
movq 0x928(%rax), %r14
movl 0x28(%r14), %eax
movl %eax, 0x28(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x4320
movq %r14, %rdi
movq %rbp, %rsi
callq 0xd16a
leaq 0x30(%rsp), %rdi
callq 0x40f0
movl 0x10(%rsp), %ebx
jmp 0x172b4
movq %r14, %rdi
movq %rbx, %rsi
callq 0xce76
movq 0x88(%r13), %rcx
movq 0x920(%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0x1734d
movl 0x40(%rax), %ebx
movq %r12, %rdi
leaq 0x1666b(%rip), %rsi     # 0x2d929
xorl %eax, %eax
callq 0x4480
movslq %ebx, %r14
xorl %ebp, %ebp
movq 0x88(%r13), %rax
movsbl 0x8b8(%rax), %eax
decl %eax
cmpl %ebp, %eax
jle 0x1730f
movq %r12, %rdi
leaq 0x16592(%rip), %rsi     # 0x2d87a
movq %r15, %rdx
xorl %eax, %eax
callq 0x4480
movq %r15, %rdi
callq 0x42c0
movq 0x90(%r13), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
jmp 0x172ca
movq %r12, %rdi
leaq 0x16552(%rip), %rsi     # 0x2d86b
movq %r15, %rdx
xorl %eax, %eax
callq 0x4480
movq %r15, %rdi
callq 0x42c0
movq 0x90(%r13), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%rbp,8)
movq 0x18(%rsp), %rax
incl (%rax)
movl 0x10(%rsp), %ecx
incl %ecx
jmp 0x171b3
movq %r12, %rdi
leaq 0x16514(%rip), %rsi     # 0x2d86b
movq %r15, %rdx
xorl %eax, %eax
callq 0x4480
jmp 0x1733b
leaq 0x70(%rsp), %r15
xorl %ecx, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x10(%rsp)
cmpl 0x8c0(%rax), %ecx
jge 0x1765d
movq %r12, %rdi
leaq 0x164de(%rip), %rsi     # 0x2d867
movq %r15, %rdx
xorl %eax, %eax
callq 0x4480
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
leaq 0xf(%rsp), %rdx
callq 0x7dea
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x42b0
movq %rbp, %rdi
callq 0x40f0
movq 0x18(%rsp), %rax
incl (%rax)
movq 0x88(%r13), %rax
movq 0x940(%rax), %r14
cmpb $0x0, 0x14(%rsp)
je 0x17442
movq %rbx, %rsi
movq 0x28(%r14), %rbx
movq %rbp, %rdi
callq 0x4320
movl %ebx, 0x48(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0xcf7e
movq %rbp, %rdi
callq 0x40f0
movq 0x88(%r13), %rax
movq 0x948(%rax), %r14
movl 0x28(%r14), %eax
movl %eax, 0x28(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x4320
movq %r14, %rdi
movq %rbp, %rsi
callq 0xd16a
leaq 0x30(%rsp), %rdi
callq 0x40f0
movl 0x10(%rsp), %ebx
jmp 0x1746b
movq %r14, %rdi
movq %rbx, %rsi
callq 0xce76
movq 0x88(%r13), %rcx
movq 0x940(%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0x17628
movl 0x40(%rax), %ebx
movq %r12, %rdi
leaq 0x164b9(%rip), %rsi     # 0x2d92e
xorl %eax, %eax
callq 0x4480
movslq %ebx, %r14
xorl %ebp, %ebp
movq 0x88(%r13), %rax
movsbl 0x8b8(%rax), %eax
decl %eax
cmpl %ebp, %eax
jle 0x174c3
movq %r12, %rdi
leaq 0x163db(%rip), %rsi     # 0x2d87a
movq %r15, %rdx
xorl %eax, %eax
callq 0x4480
movq %r15, %rdi
callq 0x42c0
movq 0x38(%r13), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
jmp 0x17481
movq %r12, %rdi
leaq 0x1639e(%rip), %rsi     # 0x2d86b
movq %r15, %rdx
xorl %eax, %eax
callq 0x4480
movq %r15, %rdi
callq 0x42c0
movq 0x38(%r13), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%rbp,8)
movq 0x18(%rsp), %rax
incl (%rax)
movq %r12, %rdi
leaq 0x16095(%rip), %rsi     # 0x2d592
xorl %eax, %eax
callq 0x4480
movq 0x88(%r13), %rax
movb 0x8b8(%rax), %al
xorl %ebp, %ebp
movsbq %al, %rcx
cmpq %rcx, %rbp
jge 0x17581
xorl %ebx, %ebx
movsbq %al, %rcx
cmpq %rcx, %rbx
jge 0x1757c
movsbl %al, %eax
decl %eax
movl %ebx, %ecx
xorl %eax, %ecx
xorl %ebp, %eax
orl %ecx, %eax
leaq 0x16330(%rip), %rsi     # 0x2d86b
je 0x17544
leaq 0x16336(%rip), %rsi     # 0x2d87a
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x4480
movq %r15, %rdi
callq 0x42c0
movq 0x40(%r13), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%rbp,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movq 0x88(%r13), %rax
movb 0x8b8(%rax), %al
jmp 0x1751e
incq %rbp
jmp 0x17513
movq 0x18(%rsp), %rax
incl (%rax)
movq %r12, %rdi
leaq 0x16003(%rip), %rsi     # 0x2d595
xorl %eax, %eax
callq 0x4480
movq 0x88(%r13), %rax
xorl %ebp, %ebp
movsbq 0x8b8(%rax), %rcx
cmpq %rcx, %rbp
jge 0x17616
xorl %ebx, %ebx
movsbq 0x8b9(%rax), %rcx
cmpq %rcx, %rbx
jge 0x17611
movsbl 0x8b8(%rax), %eax
decl %eax
xorl %ebp, %eax
decl %ecx
xorl %ebx, %ecx
orl %eax, %ecx
leaq 0x16295(%rip), %rsi     # 0x2d86b
je 0x175df
leaq 0x1629b(%rip), %rsi     # 0x2d87a
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x4480
movq %r15, %rdi
callq 0x42c0
movq 0x48(%r13), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%rbp,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movq 0x88(%r13), %rax
jmp 0x175b1
incq %rbp
jmp 0x175a2
movq 0x18(%rsp), %rax
incl (%rax)
movl 0x10(%rsp), %ecx
incl %ecx
jmp 0x1736a
movq %r12, %rdi
leaq 0x163d6(%rip), %rsi     # 0x2da08
xorl %eax, %eax
callq 0x4480
movq %r12, %rdi
leaq 0x163c5(%rip), %rsi     # 0x2da08
xorl %eax, %eax
callq 0x4480
movq %r12, %rdi
leaq 0x163b4(%rip), %rsi     # 0x2da08
xorl %eax, %eax
callq 0x4480
jmp 0x1761d
leaq 0x50(%rsp), %rdi
callq 0x40f0
addq $0x878, %rsp            # imm = 0x878
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x176b2
jmp 0x176b2
jmp 0x17693
jmp 0x176b2
jmp 0x17687
jmp 0x176b2
jmp 0x176b2
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
jmp 0x1769b
jmp 0x176b2
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x40f0
jmp 0x176b5
jmp 0x176b2
jmp 0x176b2
jmp 0x176b2
jmp 0x176b2
jmp 0x176b2
jmp 0x176b2
jmp 0x176b2
jmp 0x176b2
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x40f0
movq %rbx, %rdi
callq 0x4450
nop