// File: bobverity[P]MavericK/writeOut.cpp
// Function: printQmatrixError_ind(globals&, int)
void printQmatrixError_ind(globals &globals, int Kindex) {
    int K = globals.Kmin+Kindex;
    
    // open outputQmatrixError_ind filestream for this K
    string s = globals.outputQmatrixError_ind_filePath;
    s.erase(end(s)-4,end(s));
    s = s + "_K" + to_string((long long)K) + ".csv";
    globals.outputQmatrixError_ind_fileStream = safe_ofstream(s,globals.outputLog_on, globals.outputLog_fileStream);
    
    // write headers
    globals.outputQmatrixError_ind_fileStream << "index,label";
    if (globals.popCol_on)
        globals.outputQmatrixError_ind_fileStream << ",given_population";
    for (int k=0; k<K; k++)
        globals.outputQmatrixError_ind_fileStream << ",deme" << k+1;
    globals.outputQmatrixError_ind_fileStream << "\n";
    
    // write results
    for (int i=0; i<globals.n; i++) {
        
        // individual index
        globals.outputQmatrixError_ind_fileStream << i+1;
        globals.outputQmatrixError_ind_fileStream << ",";
        
        // individual label
        globals.outputQmatrixError_ind_fileStream << globals.indLabels_vec[i];
        globals.outputQmatrixError_ind_fileStream << ",";
        
        // population data
        if (globals.popCol_on) {
            globals.outputQmatrixError_ind_fileStream << globals.pop_vec[i];
            globals.outputQmatrixError_ind_fileStream << ",";
        }
        
        // standard errors
        for (int k=0; k<K; k++) {
            char * buffer = new char[256];
            sprintf(buffer, "%.6f", my_round(globals.QmatrixError_ind[Kindex][i][k]*1e6)/1e6);
            string s = buffer;
            delete [] buffer;
            globals.outputQmatrixError_ind_fileStream << s;
            if (k<(K-1))
                globals.outputQmatrixError_ind_fileStream << ",";
        }
        
        globals.outputQmatrixError_ind_fileStream << "\n";      
    }
    
    globals.outputQmatrixError_ind_fileStream.flush();
}

// Assembly:
subq $0x3c8, %rsp            # imm = 0x3C8
movq %rdi, 0x3c0(%rsp)
movl %esi, 0x3bc(%rsp)
movq 0x3c0(%rsp), %rax
movl 0x2bc8(%rax), %eax
movl 0x3bc(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x3b8(%rsp)
movq 0x3c0(%rsp), %rsi
addq $0x3c0, %rsi            # imm = 0x3C0
leaq 0x398(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x4180
movq 0x68(%rsp), %rdi
callq 0x5bc90
movq %rax, 0x70(%rsp)
jmp 0x5a066
movq 0x70(%rsp), %rax
movq %rax, 0x380(%rsp)
leaq 0x380(%rsp), %rdi
movl $0x4, %esi
callq 0x5bcc0
movq %rax, 0x388(%rsp)
leaq 0x390(%rsp), %rdi
leaq 0x388(%rsp), %rsi
callq 0x5bd00
leaq 0x398(%rsp), %rdi
callq 0x5bc90
movq %rax, 0x60(%rsp)
jmp 0x5a0b6
movq 0x60(%rsp), %rax
movq %rax, 0x360(%rsp)
leaq 0x368(%rsp), %rdi
leaq 0x360(%rsp), %rsi
callq 0x5bd00
movq 0x390(%rsp), %rsi
movq 0x368(%rsp), %rdx
leaq 0x398(%rsp), %rdi
callq 0x40d0
movq %rax, 0x58(%rsp)
jmp 0x5a0fc
movq 0x58(%rsp), %rax
movq %rax, 0x358(%rsp)
leaq 0x46e6(%rip), %rdx      # 0x5e7f6
leaq 0x2f8(%rsp), %rdi
leaq 0x398(%rsp), %rsi
callq 0x2af00
jmp 0x5a127
movslq 0x3b8(%rsp), %rsi
leaq 0x2d8(%rsp), %rdi
callq 0xcb30
jmp 0x5a13e
leaq 0x318(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
leaq 0x2d8(%rsp), %rdx
callq 0xc9f0
jmp 0x5a15d
leaq 0x21f1(%rip), %rdx      # 0x5c355
leaq 0x338(%rsp), %rdi
leaq 0x318(%rsp), %rsi
callq 0x22900
jmp 0x5a17b
leaq 0x398(%rsp), %rdi
movq %rdi, 0x50(%rsp)
leaq 0x338(%rsp), %rsi
movq %rsi, 0x48(%rsp)
callq 0x4500
movq 0x48(%rsp), %rdi
callq 0x4270
leaq 0x318(%rsp), %rdi
callq 0x4270
leaq 0x2d8(%rsp), %rdi
callq 0x4270
leaq 0x2f8(%rsp), %rdi
callq 0x4270
movq 0x50(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x4180
jmp 0x5a1df
movq 0x3c0(%rsp), %rax
movq %rax, %rcx
addq $0x970, %rcx            # imm = 0x970
movzbl 0x2c3c(%rax), %edx
andl $0x1, %edx
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x52e90
jmp 0x5a212
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
leaq 0xd8(%rsp), %rsi
callq 0x44e0
jmp 0x5a230
leaq 0xd8(%rsp), %rdi
callq 0x45d0
leaq 0xb8(%rsp), %rdi
callq 0x4270
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
leaq 0x474e(%rip), %rsi      # 0x5e9ae
callq 0x4430
jmp 0x5a267
movq 0x3c0(%rsp), %rax
testb $0x1, 0x2ba1(%rax)
je 0x5a36c
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
leaq 0x4728(%rip), %rsi      # 0x5e9ba
callq 0x4430
jmp 0x5a299
jmp 0x5a36c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x378(%rsp)
movl %eax, 0x374(%rsp)
jmp 0x5a751
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x378(%rsp)
movl %eax, 0x374(%rsp)
jmp 0x5a311
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x378(%rsp)
movl %eax, 0x374(%rsp)
jmp 0x5a304
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x378(%rsp)
movl %eax, 0x374(%rsp)
leaq 0x318(%rsp), %rdi
callq 0x4270
leaq 0x2d8(%rsp), %rdi
callq 0x4270
leaq 0x2f8(%rsp), %rdi
callq 0x4270
jmp 0x5a751
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x378(%rsp)
movl %eax, 0x374(%rsp)
jmp 0x5a35a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x378(%rsp)
movl %eax, 0x374(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x45d0
leaq 0xb8(%rsp), %rdi
callq 0x4270
jmp 0x5a751
movl $0x0, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
cmpl 0x3b8(%rsp), %eax
jge 0x5a3d3
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
leaq 0x4640(%rip), %rsi      # 0x5e9dd
callq 0x4430
movq %rax, 0x40(%rsp)
jmp 0x5a3a9
movq 0x40(%rsp), %rdi
movl 0xb4(%rsp), %esi
incl %esi
callq 0x4700
jmp 0x5a3be
jmp 0x5a3c0
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x5a377
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
leaq 0x24a9(%rip), %rsi      # 0x5c892
callq 0x4430
jmp 0x5a3f0
movl $0x0, 0xb0(%rsp)
movl 0xb0(%rsp), %eax
movq 0x3c0(%rsp), %rcx
cmpl 0x2d18(%rcx), %eax
jge 0x5a726
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
movl 0xb0(%rsp), %esi
incl %esi
callq 0x4700
jmp 0x5a435
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
leaq 0x1ddd(%rip), %rsi      # 0x5c228
callq 0x4430
jmp 0x5a452
movq 0x3c0(%rsp), %rdi
movq %rdi, %rax
addq $0x1370, %rax           # imm = 0x1370
movq %rax, 0x38(%rsp)
addq $0x2c58, %rdi           # imm = 0x2C58
movslq 0xb0(%rsp), %rsi
callq 0x4fe90
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x43e0
jmp 0x5a48b
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
leaq 0x1d87(%rip), %rsi      # 0x5c228
callq 0x4430
jmp 0x5a4a8
movq 0x3c0(%rsp), %rax
testb $0x1, 0x2ba1(%rax)
je 0x5a511
movq 0x3c0(%rsp), %rdi
movq %rdi, %rax
addq $0x1370, %rax           # imm = 0x1370
movq %rax, 0x30(%rsp)
addq $0x2c70, %rdi           # imm = 0x2C70
movslq 0xb0(%rsp), %rsi
callq 0x4fe90
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x43e0
jmp 0x5a4f2
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
leaq 0x1d20(%rip), %rsi      # 0x5c228
callq 0x4430
jmp 0x5a50f
jmp 0x5a511
movl $0x0, 0xac(%rsp)
movl 0xac(%rsp), %eax
cmpl 0x3b8(%rsp), %eax
jge 0x5a6f1
movl $0x100, %edi            # imm = 0x100
callq 0x4030
movq %rax, 0x28(%rsp)
jmp 0x5a541
movq 0x28(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x3c0(%rsp), %rdi
addq $0x2db8, %rdi           # imm = 0x2DB8
movslq 0x3bc(%rsp), %rsi
callq 0x8ae0
movq %rax, %rdi
movslq 0xb0(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0xac(%rsp), %rsi
callq 0x8c20
movsd (%rax), %xmm0
movsd 0x40e5(%rip), %xmm1     # 0x5e688
mulsd %xmm1, %xmm0
callq 0x33950
movl %eax, 0x24(%rsp)
jmp 0x5a5b2
movq 0x18(%rsp), %rdi
movl 0x24(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd 0x40c1(%rip), %xmm1     # 0x5e688
divsd %xmm1, %xmm0
leaq 0x441f(%rip), %rsi      # 0x5e9f1
movb $0x1, %al
callq 0x40b0
movq 0xa0(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x7f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x4740
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x80(%rsp), %rdi
callq 0x4580
jmp 0x5a60e
leaq 0x7f(%rsp), %rdi
callq 0x4490
movq 0xa0(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x5a633
movq (%rsp), %rdi
callq 0x4530
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
leaq 0x80(%rsp), %rsi
callq 0x43e0
jmp 0x5a651
movl 0xac(%rsp), %eax
movl 0x3b8(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x5a6ce
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
leaq 0x1bac(%rip), %rsi      # 0x5c228
callq 0x4430
jmp 0x5a683
jmp 0x5a6ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x378(%rsp)
movl %eax, 0x374(%rsp)
leaq 0x7f(%rsp), %rdi
callq 0x4490
jmp 0x5a751
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x378(%rsp)
movl %eax, 0x374(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x4270
jmp 0x5a751
leaq 0x80(%rsp), %rdi
callq 0x4270
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x5a51c
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
leaq 0x218b(%rip), %rsi      # 0x5c892
callq 0x4430
jmp 0x5a70e
jmp 0x5a710
movl 0xb0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb0(%rsp)
jmp 0x5a3fb
movq 0x3c0(%rsp), %rdi
addq $0x1370, %rdi           # imm = 0x1370
callq 0x42b0
jmp 0x5a73c
leaq 0x398(%rsp), %rdi
callq 0x4270
addq $0x3c8, %rsp            # imm = 0x3C8
retq
leaq 0x398(%rsp), %rdi
callq 0x4270
movq 0x378(%rsp), %rdi
callq 0x4730
nopl (%rax,%rax)