// File: 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:
subq $0x408, %rsp            # imm = 0x408
movq %rdi, 0x400(%rsp)
movl %esi, 0x3fc(%rsp)
movq 0x400(%rsp), %rax
movl 0x2bc8(%rax), %eax
movl 0x3fc(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x3f8(%rsp)
movq 0x400(%rsp), %rsi
addq $0x400, %rsi            # imm = 0x400
leaq 0x3d8(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x4180
movq 0xa0(%rsp), %rdi
callq 0x5bc90
movq %rax, 0xa8(%rsp)
jmp 0x5860f
movq 0xa8(%rsp), %rax
movq %rax, 0x3c0(%rsp)
leaq 0x3c0(%rsp), %rdi
movl $0x4, %esi
callq 0x5bcc0
movq %rax, 0x3c8(%rsp)
leaq 0x3d0(%rsp), %rdi
leaq 0x3c8(%rsp), %rsi
callq 0x5bd00
leaq 0x3d8(%rsp), %rdi
callq 0x5bc90
movq %rax, 0x98(%rsp)
jmp 0x58665
movq 0x98(%rsp), %rax
movq %rax, 0x3a0(%rsp)
leaq 0x3a8(%rsp), %rdi
leaq 0x3a0(%rsp), %rsi
callq 0x5bd00
movq 0x3d0(%rsp), %rsi
movq 0x3a8(%rsp), %rdx
leaq 0x3d8(%rsp), %rdi
callq 0x40d0
movq %rax, 0x90(%rsp)
jmp 0x586b1
movq 0x90(%rsp), %rax
movq %rax, 0x398(%rsp)
leaq 0x612e(%rip), %rdx      # 0x5e7f6
leaq 0x338(%rsp), %rdi
leaq 0x3d8(%rsp), %rsi
callq 0x2af00
jmp 0x586df
movslq 0x3f8(%rsp), %rsi
leaq 0x318(%rsp), %rdi
callq 0xcb30
jmp 0x586f6
leaq 0x358(%rsp), %rdi
leaq 0x338(%rsp), %rsi
leaq 0x318(%rsp), %rdx
callq 0xc9f0
jmp 0x58715
leaq 0x3c39(%rip), %rdx      # 0x5c355
leaq 0x378(%rsp), %rdi
leaq 0x358(%rsp), %rsi
callq 0x22900
jmp 0x58733
leaq 0x3d8(%rsp), %rdi
movq %rdi, 0x88(%rsp)
leaq 0x378(%rsp), %rsi
movq %rsi, 0x80(%rsp)
callq 0x4500
movq 0x80(%rsp), %rdi
callq 0x4270
leaq 0x358(%rsp), %rdi
callq 0x4270
leaq 0x318(%rsp), %rdi
callq 0x4270
leaq 0x338(%rsp), %rdi
callq 0x4270
movq 0x88(%rsp), %rsi
leaq 0xf8(%rsp), %rdi
callq 0x4180
jmp 0x587a3
movq 0x400(%rsp), %rax
movq %rax, %rcx
addq $0x970, %rcx            # imm = 0x970
movzbl 0x2c3c(%rax), %edx
andl $0x1, %edx
leaq 0x118(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x52e90
jmp 0x587d6
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
leaq 0x118(%rsp), %rsi
callq 0x44e0
jmp 0x587f4
leaq 0x118(%rsp), %rdi
callq 0x45d0
leaq 0xf8(%rsp), %rdi
callq 0x4270
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
leaq 0x618a(%rip), %rsi      # 0x5e9ae
callq 0x4430
jmp 0x5882b
movq 0x400(%rsp), %rax
testb $0x1, 0x2ba1(%rax)
je 0x58930
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
leaq 0x6164(%rip), %rsi      # 0x5e9ba
callq 0x4430
jmp 0x5885d
jmp 0x58930
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3b8(%rsp)
movl %eax, 0x3b4(%rsp)
jmp 0x58e4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3b8(%rsp)
movl %eax, 0x3b4(%rsp)
jmp 0x588d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3b8(%rsp)
movl %eax, 0x3b4(%rsp)
jmp 0x588c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3b8(%rsp)
movl %eax, 0x3b4(%rsp)
leaq 0x358(%rsp), %rdi
callq 0x4270
leaq 0x318(%rsp), %rdi
callq 0x4270
leaq 0x338(%rsp), %rdi
callq 0x4270
jmp 0x58e4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3b8(%rsp)
movl %eax, 0x3b4(%rsp)
jmp 0x5891e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3b8(%rsp)
movl %eax, 0x3b4(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x45d0
leaq 0xf8(%rsp), %rdi
callq 0x4270
jmp 0x58e4e
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
leaq 0x6086(%rip), %rsi      # 0x5e9cc
callq 0x4430
jmp 0x5894d
movl $0x0, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
cmpl 0x3f8(%rsp), %eax
jge 0x589b4
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
leaq 0x605f(%rip), %rsi      # 0x5e9dd
callq 0x4430
movq %rax, 0x78(%rsp)
jmp 0x5898a
movq 0x78(%rsp), %rdi
movl 0xf4(%rsp), %esi
incl %esi
callq 0x4700
jmp 0x5899f
jmp 0x589a1
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x58958
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
leaq 0x3ec8(%rip), %rsi      # 0x5c892
callq 0x4430
jmp 0x589d1
movl $0xffffffff, 0xf0(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0xec(%rsp)
movl 0xec(%rsp), %eax
movq 0x400(%rsp), %rcx
cmpl 0x2d18(%rcx), %eax
jge 0x58e23
movl $0x0, 0xe8(%rsp)
movl 0xe8(%rsp), %eax
movq 0x400(%rsp), %rcx
cmpl 0x2d1c(%rcx), %eax
jge 0x58e0b
movl $0x0, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
movl %eax, 0x74(%rsp)
movq 0x400(%rsp), %rdi
addq $0x2cd0, %rdi           # imm = 0x2CD0
movslq 0xec(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movl 0x74(%rsp), %eax
cmpl (%rcx), %eax
jge 0x58df3
movl 0xf0(%rsp), %eax
incl %eax
movl %eax, 0xf0(%rsp)
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
movl 0xec(%rsp), %esi
incl %esi
callq 0x4700
movq %rax, 0x68(%rsp)
jmp 0x58a9d
movq 0x68(%rsp), %rdi
leaq 0x377f(%rip), %rsi      # 0x5c228
callq 0x4430
jmp 0x58ab0
movq 0x400(%rsp), %rdi
movq %rdi, %rax
addq $0x1770, %rax           # imm = 0x1770
movq %rax, 0x58(%rsp)
addq $0x2c58, %rdi           # imm = 0x2C58
movslq 0xec(%rsp), %rsi
callq 0x4fe90
movq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x43e0
movq %rax, 0x60(%rsp)
jmp 0x58aee
movq 0x60(%rsp), %rdi
leaq 0x372e(%rip), %rsi      # 0x5c228
callq 0x4430
jmp 0x58b01
movq 0x400(%rsp), %rax
testb $0x1, 0x2ba1(%rax)
je 0x58b65
movq 0x400(%rsp), %rdi
movq %rdi, %rax
addq $0x1770, %rax           # imm = 0x1770
movq %rax, 0x48(%rsp)
addq $0x2c70, %rdi           # imm = 0x2C70
movslq 0xec(%rsp), %rsi
callq 0x4fe90
movq 0x48(%rsp), %rdi
movq %rax, %rsi
callq 0x43e0
movq %rax, 0x50(%rsp)
jmp 0x58b50
movq 0x50(%rsp), %rdi
leaq 0x36cc(%rip), %rsi      # 0x5c228
callq 0x4430
jmp 0x58b63
jmp 0x58b65
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
movl 0xe8(%rsp), %esi
incl %esi
callq 0x4700
movq %rax, 0x40(%rsp)
jmp 0x58b89
movq 0x40(%rsp), %rdi
leaq 0x3693(%rip), %rsi      # 0x5c228
callq 0x4430
jmp 0x58b9c
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
movl 0xe4(%rsp), %esi
incl %esi
callq 0x4700
movq %rax, 0x38(%rsp)
jmp 0x58bc0
movq 0x38(%rsp), %rdi
leaq 0x365c(%rip), %rsi      # 0x5c228
callq 0x4430
jmp 0x58bd3
movl $0x0, 0xe0(%rsp)
movl 0xe0(%rsp), %eax
cmpl 0x3f8(%rsp), %eax
jge 0x58dbe
movl $0x100, %edi            # imm = 0x100
callq 0x4030
movq %rax, 0x30(%rsp)
jmp 0x58c03
movq 0x30(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x400(%rsp), %rdi
addq $0x2d88, %rdi           # imm = 0x2D88
movslq 0x3fc(%rsp), %rsi
callq 0x8ae0
movq %rax, %rdi
movslq 0xf0(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0xe0(%rsp), %rsi
callq 0x8c20
movsd (%rax), %xmm0
movsd 0x5a1b(%rip), %xmm1     # 0x5e680
mulsd %xmm1, %xmm0
callq 0x33950
movl %eax, 0x2c(%rsp)
jmp 0x58c74
movq 0x20(%rsp), %rdi
movl 0x2c(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd 0x59f7(%rip), %xmm1     # 0x5e680
divsd %xmm1, %xmm0
leaq 0x5d4f(%rip), %rsi      # 0x5e9e3
movb $0x1, %al
callq 0x40b0
movq 0xd8(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xb7(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x4740
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0xb8(%rsp), %rdi
callq 0x4580
jmp 0x58cd3
leaq 0xb7(%rsp), %rdi
callq 0x4490
movq 0xd8(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x58cfd
movq 0x8(%rsp), %rdi
callq 0x4530
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
leaq 0xb8(%rsp), %rsi
callq 0x43e0
jmp 0x58d1b
movl 0xe0(%rsp), %eax
movl 0x3f8(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x58d9b
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
leaq 0x34e2(%rip), %rsi      # 0x5c228
callq 0x4430
jmp 0x58d4d
jmp 0x58d9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3b8(%rsp)
movl %eax, 0x3b4(%rsp)
leaq 0xb7(%rsp), %rdi
callq 0x4490
jmp 0x58e4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3b8(%rsp)
movl %eax, 0x3b4(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x4270
jmp 0x58e4e
leaq 0xb8(%rsp), %rdi
callq 0x4270
movl 0xe0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe0(%rsp)
jmp 0x58bde
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
leaq 0x3abe(%rip), %rsi      # 0x5c892
callq 0x4430
jmp 0x58ddb
jmp 0x58ddd
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x58a33
jmp 0x58df5
movl 0xe8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe8(%rsp)
jmp 0x58a0d
jmp 0x58e0d
movl 0xec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xec(%rsp)
jmp 0x589e7
movq 0x400(%rsp), %rdi
addq $0x1770, %rdi           # imm = 0x1770
callq 0x42b0
jmp 0x58e39
leaq 0x3d8(%rsp), %rdi
callq 0x4270
addq $0x408, %rsp            # imm = 0x408
retq
leaq 0x3d8(%rsp), %rdi
callq 0x4270
movq 0x3b8(%rsp), %rdi
callq 0x4730
nopl (%rax,%rax)