// File: /workspace/github_cpp_makefile_star2_O2/bobverity[P]MavericK/writeOut.cpp
// Function: printQmatrixError_gene(globals&, int)
void printQmatrixError_gene(globals &globals, int Kindex) {
    int K = globals.Kmin+Kindex;
    
    // open outputQmatrixError_gene filestream for this K
    string s = globals.outputQmatrixError_gene_filePath;
    s.erase(end(s)-4,end(s));
    s = s + "_K" + to_string((long long)K) + ".csv";
    globals.outputQmatrixError_gene_fileStream = safe_ofstream(s,globals.outputLog_on, globals.outputLog_fileStream);
    
    // write headers
    globals.outputQmatrixError_gene_fileStream << "index,label";
    if (globals.popCol_on)
        globals.outputQmatrixError_gene_fileStream << ",given_population";
    globals.outputQmatrixError_gene_fileStream << ",locus,gene_copy";
    for (int k=0; k<K; k++)
        globals.outputQmatrixError_gene_fileStream << ",deme" << k+1;
    globals.outputQmatrixError_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.outputQmatrixError_gene_fileStream << ind+1 << ",";
                
                // individual label
                globals.outputQmatrixError_gene_fileStream << globals.indLabels_vec[ind] << ",";
                
                // population data
                if (globals.popCol_on)
                    globals.outputQmatrixError_gene_fileStream << globals.pop_vec[ind] << ",";
                
                // locus
                globals.outputQmatrixError_gene_fileStream << l+1 << ",";
                
                // gene copy
                globals.outputQmatrixError_gene_fileStream << p+1 << ",";
                
                // probabilities
                for (int k=0; k<K; k++) {
                    char * buffer = new char[256];
                    sprintf(buffer, "%.3f", my_round(globals.QmatrixError_gene[Kindex][groupIndex][k]*1000)/1000.0);
                    string s = buffer;
                    delete [] buffer;
                    globals.outputQmatrixError_gene_fileStream << s;
                    if (k<(K-1))
                        globals.outputQmatrixError_gene_fileStream << ",";
                }
                
                globals.outputQmatrixError_gene_fileStream << "\n";
                
            }
        }
    }
    globals.outputQmatrixError_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 0x400(%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 0x4ab4(%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 0x25a0(%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 0x1770(%rbx), %r14
leaq 0xe8(%rsp), %rsi
movq %r14, %rdi
callq 0x33d0
leaq 0xe8(%rsp), %rdi
callq 0x3460
leaq 0x88(%rsp), %rdi
callq 0x3170
leaq 0x4b5a(%rip), %rsi      # 0x299f6
movq %r14, %rdi
callq 0x3350
movq 0x8(%rsp), %rax
cmpb $0x1, 0x2ba1(%rax)
jne 0x24ec1
leaq 0x4b49(%rip), %rsi      # 0x29a02
movq %r14, %rdi
callq 0x3350
leaq 0x4b4c(%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 0x4b38(%rip), %r15      # 0x29a25
leal (%r12,%rbp), %eax
cmpl $0x1, %eax
je 0x24f16
movq %r14, %rdi
movq %r15, %rsi
callq 0x3350
leal 0x1(%r12), %ebx
movq %rax, %rdi
movl %r12d, %esi
callq 0x3570
movl %ebx, %r12d
jmp 0x24eed
leaq 0x299e(%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 0x2516b
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 0x25161
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 0x24f8a
movq %r14, %rdi
movq 0x30(%rsp), %rsi
callq 0x3570
movq %rax, %rdi
leaq 0x2254(%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 0x222c(%rip), %rsi      # 0x27240
callq 0x3350
movq 0x8(%rsp), %rax
cmpb $0x1, 0x2ba1(%rax)
jne 0x2504f
movq 0x8(%rsp), %rax
movq 0x2c70(%rax), %rsi
addq 0x38(%rsp), %rsi
movq %r14, %rdi
callq 0x3310
movq %rax, %rdi
leaq 0x21f6(%rip), %rsi      # 0x27240
callq 0x3350
movq %r14, %rdi
movl 0x10(%rsp), %esi
callq 0x3570
movq %rax, %rdi
leaq 0x21db(%rip), %rsi      # 0x27240
callq 0x3350
movl 0x14(%rsp), %esi
incl %esi
movq %r14, %rdi
movl %esi, 0x14(%rsp)
callq 0x3570
movq %rax, %rdi
leaq 0x21ba(%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 0x2514d
movl $0x100, %edi            # imm = 0x100
callq 0x3030
movsd 0x460f(%rip), %xmm1     # 0x296c8
movq %rax, %r15
movq 0x8(%rsp), %rax
movq 0x2d88(%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 0x45dd(%rip), %xmm1     # 0x296c8
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
movq %r15, %rdi
leaq 0x492e(%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 0x2513d
movq %r14, %rdi
leaq 0x2108(%rip), %rsi      # 0x27240
callq 0x3350
movq %rbp, %rdi
callq 0x3170
incq %rbx
jmp 0x2509e
movq %r14, %rdi
leaq 0x2764(%rip), %rsi      # 0x278bb
callq 0x3350
jmp 0x24fbb
movq 0x30(%rsp), %rcx
jmp 0x24f56
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 0x251fe
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x3460
jmp 0x251a6
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x251f7
jmp 0x251fe
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3170
jmp 0x251c4
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3170
jmp 0x251d6
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x251f7
jmp 0x251fe
jmp 0x251fe
jmp 0x251fe
jmp 0x251fe
jmp 0x251fe
jmp 0x251fe
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x3170
jmp 0x25201
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x3170
movq %rbx, %rdi
callq 0x35a0