// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/HMMProblemPiGKww.cpp
// Function: HMMProblemPiGKww::readModelBody(_IO_FILE*, param*, int*, bool)
void HMMProblemPiGKww::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];
    // null skill ratios
    readNullObsRatio(fid, param, line_no);
    // ww weights
    fscanf(fid, "Student and skill component ratios\t");
    this->ww[0] = 0.5;//1;
    this->ww[1] = 0.5;//1;
    this->ww[2] = 0;//0;
    fscanf(fid,"%lf\t",&this->ww[0] );
    fscanf(fid,"%lf\t",&this->ww[1] );
    fscanf(fid,"%lf\n",&this->ww[2] );
    (*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<this->p->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,"%*s\n");
                fscanf(fid,"%*s\n");
                fscanf(fid,"%*s\n");
                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<this->p->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 $0x868, %rsp            # imm = 0x868
movl %r8d, 0x14(%rsp)
movq %rsi, %r15
movq %rdi, %r12
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq %rcx, 0x8(%rsp)
callq 0x15374
leaq 0x14f28(%rip), %rsi     # 0x2da5a
movq %r15, %rdi
xorl %eax, %eax
callq 0x4480
movq 0x98(%r12), %rdx
movaps 0x14ed5(%rip), %xmm0    # 0x2da20
movups %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x14d08(%rip), %rsi     # 0x2d862
movq %r15, %rdi
xorl %eax, %eax
callq 0x4480
movq 0x98(%r12), %rdx
addq $0x8, %rdx
leaq 0x14ceb(%rip), %rsi     # 0x2d862
movq %r15, %rdi
xorl %eax, %eax
callq 0x4480
movq 0x98(%r12), %rdx
addq $0x10, %rdx
leaq 0x14cc9(%rip), %rsi     # 0x2d85d
movq %r15, %rdi
xorl %eax, %eax
callq 0x4480
movq 0x8(%rsp), %rax
incl (%rax)
cmpb $0x0, 0x14(%rsp)
je 0x18c6c
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(%r12), %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 0x60(%rsp), %rbx
xorl %ecx, %ecx
movq 0x88(%r12), %rax
movl %ecx, 0x4(%rsp)
cmpl 0x8bc(%rax), %ecx
jge 0x18e50
movq %r15, %rdi
leaq 0x14bd2(%rip), %rsi     # 0x2d867
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4480
leaq 0x18(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0x3(%rsp), %rdx
callq 0x7dea
leaq 0x40(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x42b0
movq %rbp, %rdi
callq 0x40f0
movq 0x8(%rsp), %rax
incl (%rax)
movq 0x88(%r12), %rax
movq 0x920(%rax), %r14
cmpb $0x0, 0x14(%rsp)
je 0x18d51
movq %r13, %rsi
movq 0x28(%r14), %r13
movq %rbp, %rdi
callq 0x4320
movl %r13d, 0x38(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0xcf7e
movq %rbp, %rdi
callq 0x40f0
movq 0x88(%r12), %rax
movq 0x928(%rax), %r14
movl 0x28(%r14), %eax
movl %eax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x4320
movq %r14, %rdi
movq %rbp, %rsi
callq 0xd16a
leaq 0x20(%rsp), %rdi
callq 0x40f0
movl 0x4(%rsp), %ebp
jmp 0x18d7b
movq %r14, %rdi
movq %r13, %rsi
callq 0xce76
movq 0x88(%r12), %rcx
movq 0x920(%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0x18e1b
movl 0x40(%rax), %ebp
movq %r15, %rdi
leaq 0x14ba4(%rip), %rsi     # 0x2d929
xorl %eax, %eax
callq 0x4480
movslq %ebp, %r14
xorl %r13d, %r13d
movq 0x88(%r12), %rax
movsbl 0x8b8(%rax), %eax
decl %eax
cmpl %r13d, %eax
jle 0x18ddb
movq %r15, %rdi
leaq 0x14ac8(%rip), %rsi     # 0x2d87a
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4480
movq %rbx, %rdi
callq 0x42c0
movq 0x90(%r12), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%r13,8)
incq %r13
jmp 0x18d92
movq %r15, %rdi
leaq 0x14a86(%rip), %rsi     # 0x2d86b
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4480
movq %rbx, %rdi
callq 0x42c0
movq 0x90(%r12), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%r13,8)
movq 0x8(%rsp), %rax
incl (%rax)
movl 0x4(%rsp), %ecx
incl %ecx
jmp 0x18c73
movq %r15, %rdi
leaq 0x14be3(%rip), %rsi     # 0x2da08
xorl %eax, %eax
callq 0x4480
movq %r15, %rdi
leaq 0x14bd2(%rip), %rsi     # 0x2da08
xorl %eax, %eax
callq 0x4480
movq %r15, %rdi
leaq 0x14bc1(%rip), %rsi     # 0x2da08
xorl %eax, %eax
callq 0x4480
jmp 0x18e10
leaq 0x60(%rsp), %rbx
xorl %ecx, %ecx
movl %ecx, 0x4(%rsp)
cmpl 0x8c0(%rax), %ecx
jge 0x19162
movq %r15, %rdi
leaq 0x149f6(%rip), %rsi     # 0x2d867
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4480
leaq 0x18(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0x3(%rsp), %rdx
callq 0x7dea
leaq 0x40(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x42b0
movq %rbp, %rdi
callq 0x40f0
movq 0x8(%rsp), %rax
incl (%rax)
movq 0x88(%r12), %rax
movq 0x940(%rax), %r14
cmpb $0x0, 0x14(%rsp)
je 0x18f2d
movq %r13, %rsi
movq 0x28(%r14), %r13
movq %rbp, %rdi
callq 0x4320
movl %r13d, 0x38(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0xcf7e
movq %rbp, %rdi
callq 0x40f0
movq 0x88(%r12), %rax
movq 0x948(%rax), %r14
movl 0x28(%r14), %eax
movl %eax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x4320
movq %r14, %rdi
movq %rbp, %rsi
callq 0xd16a
leaq 0x20(%rsp), %rdi
callq 0x40f0
movl 0x4(%rsp), %ebp
jmp 0x18f57
movq %r14, %rdi
movq %r13, %rsi
callq 0xce76
movq 0x88(%r12), %rcx
movq 0x940(%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0x19125
movl 0x40(%rax), %ebp
movq %r15, %rdi
leaq 0x149cd(%rip), %rsi     # 0x2d92e
xorl %eax, %eax
callq 0x4480
movslq %ebp, %r14
xorl %r13d, %r13d
movq 0x88(%r12), %rax
movsbl 0x8b8(%rax), %eax
decl %eax
cmpl %r13d, %eax
jle 0x18fb4
movq %r15, %rdi
leaq 0x148ec(%rip), %rsi     # 0x2d87a
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4480
movq %rbx, %rdi
callq 0x42c0
movq 0x38(%r12), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%r13,8)
incq %r13
jmp 0x18f6e
movq %r15, %rdi
leaq 0x148ad(%rip), %rsi     # 0x2d86b
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4480
movq %rbx, %rdi
callq 0x42c0
movq 0x38(%r12), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%r13,8)
movq 0x8(%rsp), %rax
incl (%rax)
movq %r15, %rdi
leaq 0x145a2(%rip), %rsi     # 0x2d592
xorl %eax, %eax
callq 0x4480
movq 0x88(%r12), %rax
movb 0x8b8(%rax), %al
xorl %r13d, %r13d
movsbq %al, %rcx
cmpq %rcx, %r13
jge 0x19079
xorl %ebp, %ebp
movsbq %al, %rcx
cmpq %rcx, %rbp
jge 0x19074
movsbl %al, %eax
decl %eax
movl %ebp, %ecx
xorl %eax, %ecx
xorl %r13d, %eax
orl %ecx, %eax
leaq 0x1483a(%rip), %rsi     # 0x2d86b
je 0x1903a
leaq 0x14840(%rip), %rsi     # 0x2d87a
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4480
movq %rbx, %rdi
callq 0x42c0
movq 0x40(%r12), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r13,8), %rax
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
movq 0x88(%r12), %rax
movb 0x8b8(%rax), %al
jmp 0x19013
incq %r13
jmp 0x19008
movq 0x8(%rsp), %rax
incl (%rax)
movq %r15, %rdi
leaq 0x1450b(%rip), %rsi     # 0x2d595
xorl %eax, %eax
callq 0x4480
movq 0x88(%r12), %rax
xorl %r13d, %r13d
movsbq 0x8b8(%rax), %rcx
cmpq %rcx, %r13
jge 0x19113
xorl %ebp, %ebp
movsbq 0x8b9(%rax), %rcx
cmpq %rcx, %rbp
jge 0x1910e
movsbl 0x8b8(%rax), %eax
decl %eax
xorl %r13d, %eax
decl %ecx
xorl %ebp, %ecx
orl %eax, %ecx
leaq 0x1479a(%rip), %rsi     # 0x2d86b
je 0x190da
leaq 0x147a0(%rip), %rsi     # 0x2d87a
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4480
movq %rbx, %rdi
callq 0x42c0
movq 0x48(%r12), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r13,8), %rax
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
movq 0x88(%r12), %rax
jmp 0x190ab
incq %r13
jmp 0x1909c
movq 0x8(%rsp), %rcx
incl (%rcx)
movl 0x4(%rsp), %ecx
incl %ecx
jmp 0x18e57
movq %r15, %rdi
leaq 0x148d9(%rip), %rsi     # 0x2da08
xorl %eax, %eax
callq 0x4480
movq %r15, %rdi
leaq 0x148c8(%rip), %rsi     # 0x2da08
xorl %eax, %eax
callq 0x4480
movq %r15, %rdi
leaq 0x148b7(%rip), %rsi     # 0x2da08
xorl %eax, %eax
callq 0x4480
movq 0x88(%r12), %rax
jmp 0x1911a
leaq 0x40(%rsp), %rdi
callq 0x40f0
addq $0x868, %rsp            # imm = 0x868
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x191b7
jmp 0x191b7
jmp 0x19198
jmp 0x191b7
jmp 0x1918c
jmp 0x191b7
jmp 0x191b7
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x191a0
jmp 0x191b7
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x40f0
jmp 0x191ba
jmp 0x191b7
jmp 0x191b7
jmp 0x191b7
jmp 0x191b7
jmp 0x191b7
jmp 0x191b7
jmp 0x191b7
jmp 0x191b7
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x40f0
movq %rbx, %rdi
callq 0x4450