// File: /workspace/github_cpp_makefile_star2_O2/bobverity[P]MavericK/writeOut.cpp
// Function: printQmatrix_ind(globals&, int)
void printQmatrix_ind(globals &globals, int Kindex) {
    int K = globals.Kmin+Kindex;
    
    if (globals.outputQmatrix_structureFormat_on) {
        
        // open outputQmatrix_ind filestream for this K
        string s = globals.outputQmatrix_ind_filePath;
        s.erase(end(s)-4,end(s));
        s = s + "_K" + to_string((long long)K) + ".txt";
        globals.outputQmatrix_ind_fileStream = safe_ofstream(s,globals.outputLog_on, globals.outputLog_fileStream);
        
        // write headers
        /*
        globals.outputQmatrix_ind_fileStream << "        Label (%Miss) ";
        if (globals.popCol_on)
            globals.outputQmatrix_ind_fileStream << "Pop";
        globals.outputQmatrix_ind_fileStream << ":  Inferred clusters\n";
        */
        
        // write results
        for (int i=0; i<globals.n; i++) {
            
            // individual index
            if ((i+1)<100)
                globals.outputQmatrix_ind_fileStream << " ";
            if ((i+1)<10)
                globals.outputQmatrix_ind_fileStream << " ";
            globals.outputQmatrix_ind_fileStream << i+1;
            
            // individual label
            int stringLength = int(globals.indLabels_vec[i].length());
            if (stringLength<8) {
                for (int j=0; j<(8-stringLength); j++) {
                    globals.outputQmatrix_ind_fileStream << " ";
                }
            }
            globals.outputQmatrix_ind_fileStream << " ";
            string s = globals.indLabels_vec[i];
            if (stringLength>11)
                s.erase(begin(s)+11,end(s));
            globals.outputQmatrix_ind_fileStream << s;
            
            // missing data
            double missPercent = my_round(globals.missing_vec[i]/double(globals.loci)/double(globals.ploidy_vec[i])*100);
            if (missPercent<10)
                globals.outputQmatrix_ind_fileStream << " ";
            globals.outputQmatrix_ind_fileStream << "  (" << missPercent << ")   ";
            
            // population data
            if (globals.popCol_on) {
                if (globals.pop_vec[i].length()==1)
                    globals.outputQmatrix_ind_fileStream << " ";
                globals.outputQmatrix_ind_fileStream << " " << globals.pop_vec[i] << " ";
            }
            
            globals.outputQmatrix_ind_fileStream << ": ";
            
            // probabilities
            for (int k=0; k<K; k++) {
                char * buffer = new char[256];
                sprintf(buffer, "%.3f", my_round(globals.Qmatrix_ind[Kindex][i][k]*1000)/1000.0);
                string s = buffer;
                delete [] buffer;
                globals.outputQmatrix_ind_fileStream << " " << s;
            }
            globals.outputQmatrix_ind_fileStream << "\n";
            
        }
        
    } // end of if outputQmatrix_structureFormat_on=true
    
    // open outputQmatrix_ind filestream for this K
    string s = globals.outputQmatrix_ind_filePath;
    s.erase(end(s)-4,end(s));
    s = s + "_K" + to_string((long long)K) + ".csv";
    globals.outputQmatrix_ind_fileStream = safe_ofstream(s,globals.outputLog_on, globals.outputLog_fileStream);
    
    // write headers
    globals.outputQmatrix_ind_fileStream << "index,label";
    if (globals.popCol_on)
        globals.outputQmatrix_ind_fileStream << ",given_population";
    for (int k=0; k<K; k++)
        globals.outputQmatrix_ind_fileStream << ",deme" << k+1;
    globals.outputQmatrix_ind_fileStream << "\n";
    
    // write results
    for (int i=0; i<globals.n; i++) {
        
        // individual index
        globals.outputQmatrix_ind_fileStream << i+1;
        globals.outputQmatrix_ind_fileStream << ",";
        
        // individual label
        globals.outputQmatrix_ind_fileStream << globals.indLabels_vec[i];
        globals.outputQmatrix_ind_fileStream << ",";
        
        // population data
        if (globals.popCol_on) {
            globals.outputQmatrix_ind_fileStream << globals.pop_vec[i];
            globals.outputQmatrix_ind_fileStream << ",";
        }
        
        // probabilities
        for (int k=0; k<K; k++) {
            char * buffer = new char[256];
            sprintf(buffer, "%.3f", my_round(globals.Qmatrix_ind[Kindex][i][k]*1000)/1000.0);
            string s = buffer;
            delete [] buffer;
            globals.outputQmatrix_ind_fileStream << s;
            if (k<(K-1))
                globals.outputQmatrix_ind_fileStream << ",";
        }
        
        globals.outputQmatrix_ind_fileStream << "\n";
        
    }
    
    globals.outputQmatrix_ind_fileStream.flush();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f8, %rsp            # imm = 0x2F8
movq %rdi, %rbx
movslq %esi, %rax
movq %rax, 0x28(%rsp)
addl 0x2bc8(%rdi), %esi
cmpb $0x1, 0x2c4d(%rdi)
movl %esi, 0xc(%rsp)
movslq %esi, %r12
movq %rdi, (%rsp)
jne 0x2566f
leaq 0x360(%rbx), %rsi
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x3430
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq (%rax,%rcx), %rdx
leaq (%rax,%rcx), %rsi
addq $-0x4, %rsi
movq %r14, %rdi
callq 0x30a0
leaq 0x45bb(%rip), %rdx      # 0x2983e
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x110be
leaq 0x98(%rsp), %rdi
movq %r12, %rsi
callq 0x60a6
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0x601b
leaq 0x1fb6(%rip), %rdx      # 0x27276
leaq 0xf8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xcf2e
leaq 0x50(%rsp), %r14
leaq 0xf8(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x33f0
movq %r15, %rdi
callq 0x3170
leaq 0x30(%rsp), %rdi
callq 0x3170
leaq 0x98(%rsp), %rdi
callq 0x3170
leaq 0x70(%rsp), %rdi
callq 0x3170
leaq 0xd8(%rsp), %rdi
movq %r14, %rsi
callq 0x3430
movzbl 0x2c3c(%rbx), %edx
leaq 0x970(%rbx), %rcx
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x22438
movq %r12, 0x90(%rsp)
leaq 0xd70(%rbx), %r15
leaq 0xf8(%rsp), %rsi
movq %r15, %rdi
callq 0x33d0
leaq 0xf8(%rsp), %rdi
callq 0x3460
leaq 0xd8(%rsp), %rdi
callq 0x3170
xorl %r13d, %r13d
movl 0xc(%rsp), %eax
testl %eax, %eax
movl $0x0, %r12d
cmovgl %eax, %r12d
imulq $0x18, 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x30(%rsp), %rbp
movq (%rsp), %rax
movslq 0x2d18(%rax), %rax
cmpq %rax, %r13
jge 0x25659
cmpq $0x62, %r13
ja 0x253e0
movq %r15, %rdi
leaq 0x467d(%rip), %rsi      # 0x29a43
callq 0x3350
cmpq $0x8, %r13
ja 0x253e0
movq %r15, %rdi
leaq 0x4668(%rip), %rsi      # 0x29a43
callq 0x3350
leaq 0x1(%r13), %rsi
movq %r15, %rdi
movq %rsi, 0x18(%rsp)
callq 0x3570
movq (%rsp), %rax
movq 0x2c58(%rax), %rax
movq %r13, %rcx
shlq $0x5, %rcx
movq %rcx, 0x10(%rsp)
movl 0x8(%rax,%rcx), %ebx
cmpl $0x7, %ebx
jg 0x2542e
leal -0x8(%rbx), %r14d
testl %r14d, %r14d
je 0x2542e
movq %r15, %rdi
leaq 0x461f(%rip), %rsi      # 0x29a43
callq 0x3350
incl %r14d
jmp 0x25415
movq %r15, %rdi
leaq 0x460b(%rip), %rsi      # 0x29a43
callq 0x3350
movq (%rsp), %rax
movq 0x2c58(%rax), %rsi
addq 0x10(%rsp), %rsi
leaq 0xf8(%rsp), %rdi
callq 0x3430
cmpl $0xc, %ebx
jl 0x25480
movq 0xf8(%rsp), %rdx
leaq 0xb(%rdx), %rsi
addq 0x100(%rsp), %rdx
leaq 0xf8(%rsp), %rdi
callq 0x30a0
movq %r15, %rdi
leaq 0xf8(%rsp), %rsi
callq 0x3310
movq (%rsp), %rcx
movq 0x2ce8(%rcx), %rax
cvtsi2sdl (%rax,%r13,4), %xmm0
movq 0x2cd0(%rcx), %rax
cvtsi2sdl 0x2d1c(%rcx), %xmm1
divsd %xmm1, %xmm0
cvtsi2sdl (%rax,%r13,4), %xmm1
divsd %xmm1, %xmm0
mulsd 0x2682(%rip), %xmm0     # 0x27b48
callq 0x14cb8
movl %eax, %r14d
cmpl $0x9, %eax
jg 0x254e2
movq %r15, %rdi
leaq 0x4566(%rip), %rsi      # 0x29a43
callq 0x3350
movq %r15, %rdi
leaq 0x4544(%rip), %rsi      # 0x29a30
callq 0x3350
cvtsi2sd %r14d, %xmm0
movq %rax, %rdi
callq 0x34d0
movq %rax, %rdi
leaq 0x452c(%rip), %rsi      # 0x29a34
callq 0x3350
movq (%rsp), %rax
cmpb $0x1, 0x2ba1(%rax)
jne 0x25577
movq (%rsp), %rax
movq 0x2c70(%rax), %rax
movq 0x10(%rsp), %rcx
cmpq $0x1, 0x8(%rax,%rcx)
jne 0x25541
movq %r15, %rdi
leaq 0x4507(%rip), %rsi      # 0x29a43
callq 0x3350
movq %r15, %rdi
leaq 0x44f8(%rip), %rsi      # 0x29a43
callq 0x3350
movq (%rsp), %rcx
movq 0x10(%rsp), %rsi
addq 0x2c70(%rcx), %rsi
movq %rax, %rdi
callq 0x3310
movq %rax, %rdi
leaq 0x44d1(%rip), %rsi      # 0x29a43
callq 0x3350
movq %r15, %rdi
leaq 0x24fb(%rip), %rsi      # 0x27a7c
callq 0x3350
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x25633
movl $0x100, %edi            # imm = 0x100
callq 0x3030
movsd 0x4125(%rip), %xmm1     # 0x296c8
movq %rax, %r14
movq (%rsp), %rax
movq 0x2da0(%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx), %rax
imulq $0x18, %r13, %rcx
movq (%rax,%rcx), %rax
movsd (%rax,%rbx,8), %xmm0
mulsd %xmm1, %xmm0
callq 0x14cb8
movsd 0x40f0(%rip), %xmm1     # 0x296c8
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
movq %r14, %rdi
leaq 0x4441(%rip), %rsi      # 0x29a2b
movb $0x1, %al
callq 0x3080
movq %rbp, %rdi
movq %r14, %rsi
leaq 0x70(%rsp), %rdx
callq 0x3130
movq %r14, %rdi
callq 0x3400
movq %r15, %rdi
leaq 0x4430(%rip), %rsi      # 0x29a43
callq 0x3350
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3310
movq %rbp, %rdi
callq 0x3170
incq %rbx
jmp 0x25588
movq %r15, %rdi
leaq 0x227e(%rip), %rsi      # 0x278bb
callq 0x3350
leaq 0xf8(%rsp), %rdi
callq 0x3170
movq 0x18(%rsp), %r13
jmp 0x253a2
leaq 0x50(%rsp), %rdi
callq 0x3170
movq (%rsp), %rbx
movq 0x90(%rsp), %r12
leaq 0x360(%rbx), %rsi
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x3430
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq (%rax,%rcx), %rdx
leaq (%rax,%rcx), %rsi
addq $-0x4, %rsi
movq %r14, %rdi
callq 0x30a0
leaq 0x4199(%rip), %rdx      # 0x2983e
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x110be
leaq 0x98(%rsp), %rdi
movq %r12, %rsi
callq 0x60a6
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0x601b
leaq 0x1c8b(%rip), %rdx      # 0x2736d
leaq 0xf8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xcf2e
leaq 0x50(%rsp), %r14
leaq 0xf8(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x33f0
movq %r15, %rdi
callq 0x3170
leaq 0x30(%rsp), %rdi
callq 0x3170
leaq 0x98(%rsp), %rdi
callq 0x3170
leaq 0x70(%rsp), %rdi
callq 0x3170
leaq 0xb8(%rsp), %rdi
movq %r14, %rsi
callq 0x3430
movzbl 0x2c3c(%rbx), %edx
leaq 0x970(%rbx), %rcx
leaq 0xf8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x22438
leaq 0xd70(%rbx), %r14
leaq 0xf8(%rsp), %rsi
movq %r14, %rdi
callq 0x33d0
leaq 0xf8(%rsp), %rdi
callq 0x3460
leaq 0xb8(%rsp), %rdi
callq 0x3170
leaq 0x4256(%rip), %rsi      # 0x299f6
movq %r14, %rdi
callq 0x3350
cmpb $0x1, 0x2ba1(%rbx)
jne 0x257c0
leaq 0x424a(%rip), %rsi      # 0x29a02
movq %r14, %rdi
callq 0x3350
xorl %ebx, %ebx
movl 0xc(%rsp), %eax
testl %eax, %eax
cmovgl %eax, %ebx
movl %ebx, %r13d
negl %r13d
pushq $0x1
popq %r12
leaq 0x4249(%rip), %r15      # 0x29a25
leal (%r12,%r13), %eax
cmpl $0x1, %eax
je 0x25805
movq %r14, %rdi
movq %r15, %rsi
callq 0x3350
leal 0x1(%r12), %ebp
movq %rax, %rdi
movl %r12d, %esi
callq 0x3570
movl %ebp, %r12d
jmp 0x257dc
leaq 0x20af(%rip), %rsi      # 0x278bb
movq %r14, %rdi
callq 0x3350
movl 0xc(%rsp), %eax
decl %eax
cltq
movq %rax, 0x10(%rsp)
movl %ebx, %eax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
imulq $0x18, 0x28(%rsp), %r12
leaq 0xf8(%rsp), %rbp
movq (%rsp), %rax
movslq 0x2d18(%rax), %rax
cmpq %rax, %rbx
jge 0x25996
leaq 0x1(%rbx), %rsi
movq %r14, %rdi
movq %rsi, 0x18(%rsp)
callq 0x3570
movq %r14, %rdi
leaq 0x19d9(%rip), %rsi      # 0x27240
callq 0x3350
movq %rbx, %r15
shlq $0x5, %r15
movq (%rsp), %rax
movq 0x2c58(%rax), %rsi
addq %r15, %rsi
movq %r14, %rdi
callq 0x3310
movq %r14, %rdi
leaq 0x19ad(%rip), %rsi      # 0x27240
callq 0x3350
movq (%rsp), %rax
cmpb $0x0, 0x2ba1(%rax)
je 0x258ca
movq (%rsp), %rax
addq 0x2c70(%rax), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3310
movq %r14, %rdi
leaq 0x197b(%rip), %rsi      # 0x27240
callq 0x3350
imulq $0x18, %rbx, %rbx
xorl %r13d, %r13d
cmpq %r13, 0x20(%rsp)
je 0x2597d
movl $0x100, %edi            # imm = 0x100
callq 0x3030
movsd 0x3dda(%rip), %xmm1     # 0x296c8
movq %rax, %r15
movq (%rsp), %rax
movq 0x2da0(%rax), %rax
movq (%rax,%r12), %rax
movq (%rax,%rbx), %rax
movsd (%rax,%r13,8), %xmm0
mulsd %xmm1, %xmm0
callq 0x14cb8
movsd 0x3dad(%rip), %xmm1     # 0x296c8
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
movq %r15, %rdi
leaq 0x40fe(%rip), %rsi      # 0x29a2b
movb $0x1, %al
callq 0x3080
movq %rbp, %rdi
movq %r15, %rsi
leaq 0x30(%rsp), %rdx
callq 0x3130
movq %r15, %rdi
callq 0x3400
movq %r14, %rdi
movq %rbp, %rsi
callq 0x3310
cmpq 0x10(%rsp), %r13
jge 0x2596d
movq %r14, %rdi
leaq 0x18d8(%rip), %rsi      # 0x27240
callq 0x3350
movq %rbp, %rdi
callq 0x3170
incq %r13
jmp 0x258d1
movq %r14, %rdi
leaq 0x1f34(%rip), %rsi      # 0x278bb
callq 0x3350
movq 0x18(%rsp), %rbx
jmp 0x25838
movq %r14, %rdi
callq 0x3230
leaq 0x50(%rsp), %rdi
callq 0x3170
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x3460
jmp 0x259cf
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
jmp 0x25a75
jmp 0x25a7c
jmp 0x25a12
jmp 0x25a21
jmp 0x25a33
jmp 0x25a7c
jmp 0x25a7c
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x3460
jmp 0x25a06
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0x25a75
jmp 0x25a7c
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3170
jmp 0x25a24
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x3170
jmp 0x25a36
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
jmp 0x25a75
jmp 0x25a7c
jmp 0x25a7c
jmp 0x25a7c
jmp 0x25a6a
jmp 0x25a7c
jmp 0x25a6a
jmp 0x25a7c
jmp 0x25a7c
jmp 0x25a7c
jmp 0x25a6a
jmp 0x25a7c
jmp 0x25a7c
jmp 0x25a6a
jmp 0x25a7c
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3170
jmp 0x25a6d
jmp 0x25a6a
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x3170
jmp 0x25a7f
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x3170
movq %rbx, %rdi
callq 0x35a0