// File: bobverity[P]MavericK/writeOut.cpp
// Function: printQmatrixError_pop(globals&, int)
void printQmatrixError_pop(globals &globals, int Kindex) {
    int K = globals.Kmin+Kindex;
    
    // open outputQmatrixError_pop filestream for this K
    string s = globals.outputQmatrixError_pop_filePath;
    s.erase(end(s)-4,end(s));
    s = s + "_K" + to_string((long long)K) + ".csv";
    globals.outputQmatrixError_pop_fileStream = safe_ofstream(s,globals.outputLog_on, globals.outputLog_fileStream);
    
    // write headers
    globals.outputQmatrixError_pop_fileStream << "given_population,individuals";
    for (int k=0; k<K; k++)
        globals.outputQmatrixError_pop_fileStream << ",deme" << k+1;
    globals.outputQmatrixError_pop_fileStream << "\n";
    
    // write results
    for (int i=0; i<int(globals.uniquePops.size()); i++) {
        
        // given population and number of individuals
        globals.outputQmatrixError_pop_fileStream << globals.uniquePops[i] << "," << globals.uniquePop_counts[i];
        
        // standard errors
        for (int k=0; k<K; k++) {
            char * buffer = new char[256];
            sprintf(buffer, "%.6f", my_round(globals.QmatrixError_pop[Kindex][i][k]*1e6)/1e6);
            string s = buffer;
            delete [] buffer;
            globals.outputQmatrixError_pop_fileStream << "," << s;
        }
        
        globals.outputQmatrixError_pop_fileStream << "\n";
        
    }
    
    globals.outputQmatrixError_pop_fileStream.flush();
    
}

// Assembly:
subq $0x3e8, %rsp            # imm = 0x3E8
movq %rdi, 0x3e0(%rsp)
movl %esi, 0x3dc(%rsp)
movq 0x3e0(%rsp), %rax
movl 0x2bc8(%rax), %eax
movl 0x3dc(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x3d8(%rsp)
movq 0x3e0(%rsp), %rsi
addq $0x3e0, %rsi            # imm = 0x3E0
leaq 0x3b8(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x4180
movq 0x88(%rsp), %rdi
callq 0x5bc90
movq %rax, 0x90(%rsp)
jmp 0x5b62f
movq 0x90(%rsp), %rax
movq %rax, 0x3a0(%rsp)
leaq 0x3a0(%rsp), %rdi
movl $0x4, %esi
callq 0x5bcc0
movq %rax, 0x3a8(%rsp)
leaq 0x3b0(%rsp), %rdi
leaq 0x3a8(%rsp), %rsi
callq 0x5bd00
leaq 0x3b8(%rsp), %rdi
callq 0x5bc90
movq %rax, 0x80(%rsp)
jmp 0x5b685
movq 0x80(%rsp), %rax
movq %rax, 0x380(%rsp)
leaq 0x388(%rsp), %rdi
leaq 0x380(%rsp), %rsi
callq 0x5bd00
movq 0x3b0(%rsp), %rsi
movq 0x388(%rsp), %rdx
leaq 0x3b8(%rsp), %rdi
callq 0x40d0
movq %rax, 0x78(%rsp)
jmp 0x5b6ce
movq 0x78(%rsp), %rax
movq %rax, 0x378(%rsp)
leaq 0x3114(%rip), %rdx      # 0x5e7f6
leaq 0x318(%rsp), %rdi
leaq 0x3b8(%rsp), %rsi
callq 0x2af00
jmp 0x5b6f9
movslq 0x3d8(%rsp), %rsi
leaq 0x2f8(%rsp), %rdi
callq 0xcb30
jmp 0x5b710
leaq 0x338(%rsp), %rdi
leaq 0x318(%rsp), %rsi
leaq 0x2f8(%rsp), %rdx
callq 0xc9f0
jmp 0x5b72f
leaq 0xc1f(%rip), %rdx       # 0x5c355
leaq 0x358(%rsp), %rdi
leaq 0x338(%rsp), %rsi
callq 0x22900
jmp 0x5b74d
leaq 0x3b8(%rsp), %rdi
movq %rdi, 0x70(%rsp)
leaq 0x358(%rsp), %rsi
movq %rsi, 0x68(%rsp)
callq 0x4500
movq 0x68(%rsp), %rdi
callq 0x4270
leaq 0x338(%rsp), %rdi
callq 0x4270
leaq 0x2f8(%rsp), %rdi
callq 0x4270
leaq 0x318(%rsp), %rdi
callq 0x4270
movq 0x70(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x4180
jmp 0x5b7b1
movq 0x3e0(%rsp), %rax
movq %rax, %rcx
addq $0x970, %rcx            # imm = 0x970
movzbl 0x2c3c(%rax), %edx
andl $0x1, %edx
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x52e90
jmp 0x5b7e4
movq 0x3e0(%rsp), %rdi
addq $0x1570, %rdi           # imm = 0x1570
leaq 0xf8(%rsp), %rsi
callq 0x44e0
jmp 0x5b802
leaq 0xf8(%rsp), %rdi
callq 0x45d0
leaq 0xd8(%rsp), %rdi
callq 0x4270
movq 0x3e0(%rsp), %rdi
addq $0x1570, %rdi           # imm = 0x1570
leaq 0x31e4(%rip), %rsi      # 0x5ea16
callq 0x4430
jmp 0x5b839
movl $0x0, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
cmpl 0x3d8(%rsp), %eax
jge 0x5b972
movq 0x3e0(%rsp), %rdi
addq $0x1570, %rdi           # imm = 0x1570
leaq 0x316f(%rip), %rsi      # 0x5e9dd
callq 0x4430
movq %rax, 0x60(%rsp)
jmp 0x5b87a
movq 0x60(%rsp), %rdi
movl 0xd4(%rsp), %esi
incl %esi
callq 0x4700
jmp 0x5b88f
jmp 0x5b891
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x5b844
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x398(%rsp)
movl %eax, 0x394(%rsp)
jmp 0x5bc74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x398(%rsp)
movl %eax, 0x394(%rsp)
jmp 0x5b917
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x398(%rsp)
movl %eax, 0x394(%rsp)
jmp 0x5b90a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x398(%rsp)
movl %eax, 0x394(%rsp)
leaq 0x338(%rsp), %rdi
callq 0x4270
leaq 0x2f8(%rsp), %rdi
callq 0x4270
leaq 0x318(%rsp), %rdi
callq 0x4270
jmp 0x5bc74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x398(%rsp)
movl %eax, 0x394(%rsp)
jmp 0x5b960
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x398(%rsp)
movl %eax, 0x394(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x45d0
leaq 0xd8(%rsp), %rdi
callq 0x4270
jmp 0x5bc74
movq 0x3e0(%rsp), %rdi
addq $0x1570, %rdi           # imm = 0x1570
leaq 0xf0a(%rip), %rsi       # 0x5c892
callq 0x4430
jmp 0x5b98f
movl $0x0, 0xd0(%rsp)
movl 0xd0(%rsp), %eax
movl %eax, 0x5c(%rsp)
movq 0x3e0(%rsp), %rdi
addq $0x2c88, %rdi           # imm = 0x2C88
callq 0x16bb0
movq %rax, %rcx
movl 0x5c(%rsp), %eax
cmpl %ecx, %eax
jge 0x5bc49
movq 0x3e0(%rsp), %rdi
movq %rdi, %rax
addq $0x1570, %rax           # imm = 0x1570
movq %rax, 0x48(%rsp)
addq $0x2c88, %rdi           # imm = 0x2C88
movslq 0xd0(%rsp), %rsi
callq 0x4fe90
movq 0x48(%rsp), %rdi
movq %rax, %rsi
callq 0x43e0
movq %rax, 0x50(%rsp)
jmp 0x5ba06
movq 0x50(%rsp), %rdi
leaq 0x816(%rip), %rsi       # 0x5c228
callq 0x4430
movq %rax, 0x40(%rsp)
jmp 0x5ba1e
movq 0x3e0(%rsp), %rdi
addq $0x2ca0, %rdi           # imm = 0x2CA0
movslq 0xd0(%rsp), %rsi
callq 0x8ba0
movq 0x40(%rsp), %rdi
movl (%rax), %esi
callq 0x4700
jmp 0x5ba48
movl $0x0, 0xcc(%rsp)
movl 0xcc(%rsp), %eax
cmpl 0x3d8(%rsp), %eax
jge 0x5bc14
movl $0x100, %edi            # imm = 0x100
callq 0x4030
movq %rax, 0x38(%rsp)
jmp 0x5ba78
movq 0x38(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x3e0(%rsp), %rdi
addq $0x2de8, %rdi           # imm = 0x2DE8
movslq 0x3dc(%rsp), %rsi
callq 0x8ae0
movq %rax, %rdi
movslq 0xd0(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0xcc(%rsp), %rsi
callq 0x8c20
movsd (%rax), %xmm0
movsd 0x2bae(%rip), %xmm1     # 0x5e688
mulsd %xmm1, %xmm0
callq 0x33950
movl %eax, 0x34(%rsp)
jmp 0x5bae9
movq 0x28(%rsp), %rdi
movl 0x34(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd 0x2b8a(%rip), %xmm1     # 0x5e688
divsd %xmm1, %xmm0
leaq 0x2ee8(%rip), %rsi      # 0x5e9f1
movb $0x1, %al
callq 0x40b0
movq 0xc0(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x4740
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0xa0(%rsp), %rdi
callq 0x4580
jmp 0x5bb48
leaq 0x9f(%rsp), %rdi
callq 0x4490
movq 0xc0(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x5bb72
movq 0x10(%rsp), %rdi
callq 0x4530
movq 0x3e0(%rsp), %rdi
addq $0x1570, %rdi           # imm = 0x1570
leaq 0x6a0(%rip), %rsi       # 0x5c228
callq 0x4430
movq %rax, 0x8(%rsp)
jmp 0x5bb94
movq 0x8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x43e0
jmp 0x5bba8
leaq 0xa0(%rsp), %rdi
callq 0x4270
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x5ba53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x398(%rsp)
movl %eax, 0x394(%rsp)
leaq 0x9f(%rsp), %rdi
callq 0x4490
jmp 0x5bc74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x398(%rsp)
movl %eax, 0x394(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x4270
jmp 0x5bc74
movq 0x3e0(%rsp), %rdi
addq $0x1570, %rdi           # imm = 0x1570
leaq 0xc68(%rip), %rsi       # 0x5c892
callq 0x4430
jmp 0x5bc31
jmp 0x5bc33
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0x5b99a
movq 0x3e0(%rsp), %rdi
addq $0x1570, %rdi           # imm = 0x1570
callq 0x42b0
jmp 0x5bc5f
leaq 0x3b8(%rsp), %rdi
callq 0x4270
addq $0x3e8, %rsp            # imm = 0x3E8
retq
leaq 0x3b8(%rsp), %rdi
callq 0x4270
movq 0x398(%rsp), %rdi
callq 0x4730
nop