// File: /workspace/github_cpp_makefile_star2_O2/bobverity[P]MavericK/writeOut.cpp
// Function: printQmatrix_gene(globals&, int)
void printQmatrix_gene(globals &globals, int Kindex) {
    int K = globals.Kmin+Kindex;
    
    // open outputQmatrix_gene filestream for this K
    string s = globals.outputQmatrix_gene_filePath;
    s.erase(end(s)-4,end(s));
    s = s + "_K" + to_string((long long)K) + ".csv";
    globals.outputQmatrix_gene_fileStream = safe_ofstream(s,globals.outputLog_on, globals.outputLog_fileStream);
    
    // write headers
    globals.outputQmatrix_gene_fileStream << "index,label";
    if (globals.popCol_on)
        globals.outputQmatrix_gene_fileStream << ",given_population";
    globals.outputQmatrix_gene_fileStream << ",locus,gene_copy";
    for (int k=0; k<K; k++)
        globals.outputQmatrix_gene_fileStream << ",deme" << k+1;
    globals.outputQmatrix_gene_fileStream << "\n";
    
    // write results
    int groupIndex=-1;
    for (int ind=0; ind<globals.n; ind++) {
        for (int l=0; l<globals.loci; l++) {
            for (int p=0; p<globals.ploidy_vec[ind]; p++) {
                groupIndex++;
                
                // individual index
                globals.outputQmatrix_gene_fileStream << ind+1 << ",";
                
                // individual label
                globals.outputQmatrix_gene_fileStream << globals.indLabels_vec[ind] << ",";
                
                // population data
                if (globals.popCol_on)
                    globals.outputQmatrix_gene_fileStream << globals.pop_vec[ind] << ",";
                
                // locus
                globals.outputQmatrix_gene_fileStream << l+1 << ",";
                
                // gene copy
                globals.outputQmatrix_gene_fileStream << p+1 << ",";
                
                // probabilities
                for (int k=0; k<K; k++) {
                    char * buffer = new char[256];
                    sprintf(buffer, "%.3f", my_round(globals.Qmatrix_gene[Kindex][groupIndex][k]*1000)/1000.0);
                    string s = buffer;
                    delete [] buffer;
                    globals.outputQmatrix_gene_fileStream << s;
                    if (k<(K-1))
                        globals.outputQmatrix_gene_fileStream << ",";
                }
                
                globals.outputQmatrix_gene_fileStream << "\n";
                
            }
        }
    }
    globals.outputQmatrix_gene_fileStream.flush();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2e8, %rsp            # imm = 0x2E8
movl %esi, %r12d
movl 0x2bc8(%rdi), %ebp
addl %esi, %ebp
movq %rdi, 0x8(%rsp)
leaq 0x3a0(%rdi), %rsi
leaq 0x68(%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 0x4f94(%rip), %rdx      # 0x2983e
leaq 0xc8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x110be
movslq %ebp, %rsi
leaq 0xa8(%rsp), %rdi
callq 0x60a6
leaq 0x48(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x601b
leaq 0x2a80(%rip), %rdx      # 0x2736d
leaq 0xe8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0xcf2e
leaq 0x68(%rsp), %r14
leaq 0xe8(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x33f0
movq %r15, %rdi
callq 0x3170
leaq 0x48(%rsp), %rdi
callq 0x3170
leaq 0xa8(%rsp), %rdi
callq 0x3170
leaq 0xc8(%rsp), %rdi
callq 0x3170
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0x3430
movq 0x8(%rsp), %rbx
movzbl 0x2c3c(%rbx), %edx
leaq 0x970(%rbx), %rcx
leaq 0xe8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x22438
movl %r12d, 0x28(%rsp)
movl %ebp, 0x20(%rsp)
leaq 0x1170(%rbx), %r14
leaq 0xe8(%rsp), %rsi
movq %r14, %rdi
callq 0x33d0
leaq 0xe8(%rsp), %rdi
callq 0x3460
leaq 0x88(%rsp), %rdi
callq 0x3170
leaq 0x503a(%rip), %rsi      # 0x299f6
movq %r14, %rdi
callq 0x3350
movq 0x8(%rsp), %rax
cmpb $0x1, 0x2ba1(%rax)
jne 0x249e1
leaq 0x5029(%rip), %rsi      # 0x29a02
movq %r14, %rdi
callq 0x3350
leaq 0x502c(%rip), %rsi      # 0x29a14
movq %r14, %rdi
callq 0x3350
xorl %r13d, %r13d
movl 0x20(%rsp), %eax
testl %eax, %eax
cmovgl %eax, %r13d
movl %r13d, %ebp
negl %ebp
pushq $0x1
popq %r12
leaq 0x5018(%rip), %r15      # 0x29a25
leal (%r12,%rbp), %eax
cmpl $0x1, %eax
je 0x24a36
movq %r14, %rdi
movq %r15, %rsi
callq 0x3350
leal 0x1(%r12), %ebx
movq %rax, %rdi
movl %r12d, %esi
callq 0x3570
movl %ebx, %r12d
jmp 0x24a0d
leaq 0x2e7e(%rip), %rsi      # 0x278bb
movq %r14, %rdi
callq 0x3350
movslq 0x28(%rsp), %rax
movl 0x20(%rsp), %ecx
decl %ecx
movslq %ecx, %rcx
movq %rcx, 0x28(%rsp)
movl %r13d, %r12d
pushq $-0x1
popq %rcx
movq %rcx, 0x18(%rsp)
xorl %ecx, %ecx
imulq $0x18, %rax, %rax
movq %rax, 0x20(%rsp)
leaq 0xe8(%rsp), %rbp
movq 0x8(%rsp), %rax
movslq 0x2d18(%rax), %rax
cmpq %rax, %rcx
jge 0x24c8b
leaq 0x1(%rcx), %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x10(%rsp)
movq %rcx, 0x40(%rsp)
shlq $0x5, %rcx
movq %rcx, 0x38(%rsp)
movq 0x8(%rsp), %rax
movl 0x10(%rsp), %ecx
cmpl 0x2d1c(%rax), %ecx
jge 0x24c81
movl %ecx, %eax
incl %eax
movl %eax, 0x10(%rsp)
movq 0x18(%rsp), %rax
cltq
movq %rax, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movq 0x8(%rsp), %rax
movq 0x2cd0(%rax), %rax
movq 0x40(%rsp), %rcx
movl 0x14(%rsp), %edx
cmpl (%rax,%rcx,4), %edx
jge 0x24aaa
movq %r14, %rdi
movq 0x30(%rsp), %rsi
callq 0x3570
movq %rax, %rdi
leaq 0x2734(%rip), %rsi      # 0x27240
callq 0x3350
movq 0x8(%rsp), %rax
movq 0x2c58(%rax), %rsi
addq 0x38(%rsp), %rsi
movq %r14, %rdi
callq 0x3310
movq %rax, %rdi
leaq 0x270c(%rip), %rsi      # 0x27240
callq 0x3350
movq 0x8(%rsp), %rax
cmpb $0x1, 0x2ba1(%rax)
jne 0x24b6f
movq 0x8(%rsp), %rax
movq 0x2c70(%rax), %rsi
addq 0x38(%rsp), %rsi
movq %r14, %rdi
callq 0x3310
movq %rax, %rdi
leaq 0x26d6(%rip), %rsi      # 0x27240
callq 0x3350
movq %r14, %rdi
movl 0x10(%rsp), %esi
callq 0x3570
movq %rax, %rdi
leaq 0x26bb(%rip), %rsi      # 0x27240
callq 0x3350
movl 0x14(%rsp), %esi
incl %esi
movq %r14, %rdi
movl %esi, 0x14(%rsp)
callq 0x3570
movq %rax, %rdi
leaq 0x269a(%rip), %rsi      # 0x27240
callq 0x3350
movq 0x18(%rsp), %rcx
incq %rcx
movq %rcx, 0x18(%rsp)
imulq $0x18, %rcx, %r13
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x24c6d
movl $0x100, %edi            # imm = 0x100
callq 0x3030
movsd 0x4aef(%rip), %xmm1     # 0x296c8
movq %rax, %r15
movq 0x8(%rsp), %rax
movq 0x2d70(%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx), %rax
movq (%rax,%r13), %rax
movsd (%rax,%rbx,8), %xmm0
mulsd %xmm1, %xmm0
callq 0x14cb8
movsd 0x4abd(%rip), %xmm1     # 0x296c8
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
movq %r15, %rdi
leaq 0x4e0e(%rip), %rsi      # 0x29a2b
movb $0x1, %al
callq 0x3080
movq %rbp, %rdi
movq %r15, %rsi
leaq 0x48(%rsp), %rdx
callq 0x3130
movq %r15, %rdi
callq 0x3400
movq %r14, %rdi
movq %rbp, %rsi
callq 0x3310
cmpq 0x28(%rsp), %rbx
jge 0x24c5d
movq %r14, %rdi
leaq 0x25e8(%rip), %rsi      # 0x27240
callq 0x3350
movq %rbp, %rdi
callq 0x3170
incq %rbx
jmp 0x24bbe
movq %r14, %rdi
leaq 0x2c44(%rip), %rsi      # 0x278bb
callq 0x3350
jmp 0x24adb
movq 0x30(%rsp), %rcx
jmp 0x24a76
movq %r14, %rdi
callq 0x3230
leaq 0x68(%rsp), %rdi
callq 0x3170
addq $0x2e8, %rsp            # imm = 0x2E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x24d1e
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x3460
jmp 0x24cc6
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x24d17
jmp 0x24d1e
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3170
jmp 0x24ce4
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3170
jmp 0x24cf6
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x24d17
jmp 0x24d1e
jmp 0x24d1e
jmp 0x24d1e
jmp 0x24d1e
jmp 0x24d1e
jmp 0x24d1e
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x3170
jmp 0x24d21
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x3170
movq %rbx, %rdi
callq 0x35a0