// File: /workspace/github_cpp_makefile_star2_O3/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 $0x2d8, %rsp            # imm = 0x2D8
movl %esi, %ebp
movl 0x2bc8(%rdi), %eax
addl %esi, %eax
movq %rax, 0x10(%rsp)
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x3a0(%rdi), %rsi
movq %rdi, (%rsp)
movq 0x3a8(%rdi), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0xbb9a
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq -0x4(%rcx), %rdx
movq %rdx, 0x8(%r14)
movb $0x0, -0x4(%rax,%rcx)
movq (%r14), %rsi
leaq 0x58(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0xbb9a
leaq 0x6447(%rip), %rsi      # 0x3887e
leaq 0x48(%rsp), %rdi
callq 0x35e0
movslq 0x10(%rsp), %r15
movq %r15, %r14
negq %r14
cmovsq %r15, %r14
movl $0x1, %r12d
cmpq $0xa, %r14
jb 0x324b0
movl $0x4, %r12d
movabsq $0x346dc5d63886594b, %rsi # imm = 0x346DC5D63886594B
movq %r14, %rcx
cmpq $0x63, %rcx
jbe 0x324a7
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x324ad
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x324b0
movq %rcx, %rax
mulq %rsi
shrq $0xb, %rdx
addl $0x4, %r12d
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x3246f
addl $-0x3, %r12d
jmp 0x324b0
addl $-0x2, %r12d
jmp 0x324b0
decl %r12d
shrq $0x3f, %r15
leal (%r15,%r12), %esi
leaq 0x78(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x68(%rsp), %rdi
movl $0x2d, %edx
callq 0x33a0
addq 0x68(%rsp), %r15
movq %r15, %rdi
movl %r12d, %esi
movq %r14, %rdx
callq 0x6d20
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r8
movq 0x70(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %edi
cmpq %r13, %rcx
je 0x32505
movq 0x58(%rsp), %rdi
movq 0x68(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x32523
movl $0xf, %edi
cmpq %rbx, %rsi
je 0x3251e
movq 0x78(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x3252f
leaq 0x48(%rsp), %rdi
callq 0x30e0
jmp 0x3253d
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3370
leaq 0x38(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x32561
movq %rsi, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0x32569
movupd (%rcx), %xmm0
movupd %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x3e58(%rip), %rsi      # 0x363e5
leaq 0x28(%rsp), %rdi
callq 0x35e0
leaq 0xe8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x325c7
movq %rdx, 0xd8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xe8(%rsp)
jmp 0x325d0
movupd (%rcx), %xmm0
movupd %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0xd8(%rsp), %r14
movq %rdx, 0x8(%r14)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0x33e0
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x3260c
callq 0x3310
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movq (%rsp), %r14
je 0x32623
callq 0x3310
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x32632
callq 0x3310
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x32641
callq 0x3310
leaq 0xc8(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0xbb9a
movzbl 0x2c3c(%r14), %edx
leaq 0x970(%r14), %rcx
leaq 0xd8(%rsp), %r12
leaq 0xb8(%rsp), %rsi
movq %r12, %rdi
callq 0x2eff8
movq %r14, %r13
addq $0x1170, %r14           # imm = 0x1170
movq 0x1170(%r13), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
leaq 0xe0(%rsp), %r15
movq -0x8(%r15), %rax
addq -0x18(%rax), %r12
movq %r12, %rsi
callq 0x35d0
leaq 0x1178(%r13), %rdi
movq %r15, %rsi
callq 0x3340
movq 0xe8c6(%rip), %rax      # 0x40fa0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x1d0(%rsp), %r12
movq %rcx, -0xf8(%r12)
movq -0x18(%rcx), %rcx
movq %rax, 0xd8(%rsp,%rcx)
movq %r15, %rdi
callq 0x32b0
movq %r12, %rdi
callq 0x30f0
movq 0xb8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3271f
callq 0x3310
leaq 0x6310(%rip), %rsi      # 0x38a36
movl $0xb, %edx
movq %r14, %rdi
callq 0x3390
movq (%rsp), %rax
cmpb $0x1, 0x2ba1(%rax)
jne 0x32754
leaq 0x62fb(%rip), %rsi      # 0x38a42
movl $0x11, %edx
movq %r14, %rdi
callq 0x3390
leaq 0x62f9(%rip), %rsi      # 0x38a54
movl $0x10, %edx
movq %r14, %rdi
callq 0x3390
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
testl %eax, %eax
cmovgl %eax, %ebx
negl %ebx
movl $0x1, %r12d
leaq 0x62e2(%rip), %r15      # 0x38a65
leal (%rbx,%r12), %eax
cmpl $0x1, %eax
je 0x327b1
movl $0x5, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x3390
leal 0x1(%r12), %r13d
movq %r14, %rdi
movl %r12d, %esi
callq 0x3550
movl %r13d, %r12d
jmp 0x32783
leaq 0x416a(%rip), %rsi      # 0x36922
movl $0x1, %edx
movq %r14, %rdi
callq 0x3390
movq (%rsp), %rax
movl 0x2d18(%rax), %eax
testl %eax, %eax
jle 0x32a8d
movslq %ebp, %rdx
movq 0x10(%rsp), %rsi
leal -0x1(%rsi), %ecx
movslq %ecx, %rcx
movq %rcx, 0xb0(%rsp)
movq (%rsp), %rcx
movl 0x2d1c(%rcx), %ecx
movl %esi, %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %esi, %esi
leaq (%rdx,%rdx,2), %rbx
leaq 0x1(%rsi), %rdx
movq %rdx, 0x18(%rsp)
testl %ecx, %ecx
jle 0x32a79
movq %rsi, 0xa8(%rsp)
xorl %eax, %eax
shlq $0x5, %rsi
movq %rsi, 0x20(%rsp)
incl %eax
movl %eax, 0xc(%rsp)
movslq %r13d, %r13
movl $0x0, 0x8(%rsp)
movq (%rsp), %rax
movq 0x2cd0(%rax), %rax
movq 0xa8(%rsp), %rcx
movl 0x8(%rsp), %edx
cmpl (%rax,%rcx,4), %edx
jge 0x32a59
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x3550
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3a19(%rip), %rsi      # 0x36290
callq 0x3390
movq (%rsp), %rax
movq 0x2c58(%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
movq %r14, %rdi
callq 0x3390
movl $0x1, %edx
movq %rax, %rdi
leaq 0x39e4(%rip), %rsi      # 0x36290
callq 0x3390
movq (%rsp), %rax
cmpb $0x1, 0x2ba1(%rax)
jne 0x328f3
movq (%rsp), %rax
movq 0x2c70(%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
movq %r14, %rdi
callq 0x3390
movl $0x1, %edx
movq %rax, %rdi
leaq 0x39a2(%rip), %rsi      # 0x36290
callq 0x3390
movq %r14, %rdi
movl 0xc(%rsp), %esi
callq 0x3550
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3982(%rip), %rsi      # 0x36290
callq 0x3390
movl 0x8(%rsp), %esi
incl %esi
movq %r14, %rdi
movl %esi, 0x8(%rsp)
callq 0x3550
movl $0x1, %edx
movq %rax, %rdi
leaq 0x395c(%rip), %rsi      # 0x36290
callq 0x3390
incq %r13
cmpl $0x0, 0x10(%rsp)
jle 0x32a40
xorl %ebp, %ebp
movl $0x100, %edi            # imm = 0x100
callq 0x3030
movsd 0x5dad(%rip), %xmm1     # 0x38708
movq %rax, %r15
movq (%rsp), %rax
movq 0x2d70(%rax), %rax
movq (%rax,%rbx,8), %rax
leaq (,%r13,2), %rcx
addq %r13, %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%rbp,8), %xmm0
mulsd %xmm1, %xmm0
callq 0x1a730
movsd 0x5d76(%rip), %xmm1     # 0x38708
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
movq %r15, %rdi
leaq 0x60c4(%rip), %rsi      # 0x38a6b
movb $0x1, %al
callq 0x3080
leaq 0xe8(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq %r15, %rdi
callq 0x3140
movq %r15, %rdx
addq %rax, %rdx
leaq 0xd8(%rsp), %rdi
movq %r15, %rsi
callq 0x6d9c
movq %r15, %rdi
callq 0x33f0
movq 0xd8(%rsp), %rsi
movq 0xe0(%rsp), %rdx
movq %r14, %rdi
callq 0x3390
cmpq 0xb0(%rsp), %rbp
jge 0x32a1a
movl $0x1, %edx
movq %r14, %rdi
leaq 0x387b(%rip), %rsi      # 0x36290
callq 0x3390
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x32a34
callq 0x3310
incq %rbp
cmpq %rbp, %r12
jne 0x32949
movl $0x1, %edx
movq %r14, %rdi
leaq 0x3ed3(%rip), %rsi      # 0x36922
callq 0x3390
jmp 0x3283b
movq (%rsp), %rax
movl 0x2d1c(%rax), %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jl 0x3282a
movq (%rsp), %rax
movl 0x2d18(%rax), %eax
movslq %eax, %rdx
movq 0x18(%rsp), %rdi
movq %rdi, %rsi
cmpq %rdx, %rdi
jl 0x32806
movq %r14, %rdi
callq 0x31f0
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x32aaf
callq 0x3310
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x32b52
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0x3440
jmp 0x32adb
movq %rax, %r14
movq 0xb8(%rsp), %rdi
cmpq %rbx, %rdi
jne 0x32b4b
jmp 0x32b55
jmp 0x32b52
movq %rax, %r14
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x32b07
callq 0x3310
jmp 0x32b07
movq %rax, %r14
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x32b1d
callq 0x3310
jmp 0x32b1d
jmp 0x32b1a
movq %rax, %r14
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
jne 0x32b4b
jmp 0x32b55
jmp 0x32b52
jmp 0x32b52
jmp 0x32b52
jmp 0x32b52
jmp 0x32b52
movq %rax, %r14
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x32b55
callq 0x3310
jmp 0x32b55
movq %rax, %r14
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x32b6f
callq 0x3310
movq %r14, %rdi
callq 0x3580