// File: /workspace/github_cpp_makefile_star2_O2/bobverity[P]MavericK/writeOut.cpp
// Function: openFileStreams(globals&)
void openFileStreams(globals &globals) {
    
    // Likelihood
    if (globals.outputLikelihood_on) {
        // open file stream
        globals.outputLikelihood_fileStream = safe_ofstream(globals.outputLikelihood_filePath, globals.outputLog_on, globals.outputLog_fileStream);
        // fixed headers
        globals.outputLikelihood_fileStream << "K,mainRep,MCMCsample,loglike_marginal,loglike_joint";
        // alpha if admixture model
        if (globals.admix_on)
            globals.outputLikelihood_fileStream << ",alpha";
        
        globals.outputLikelihood_fileStream << "\n";
        globals.outputLikelihood_fileStream.flush();
    }
    
    // Evidence
    if (globals.outputEvidence_on) {
        // open file stream
        globals.outputEvidence_fileStream = safe_ofstream(globals.outputEvidence_filePath, globals.outputLog_on, globals.outputLog_fileStream);
        // exhaustive
        globals.outputEvidence_fileStream << "K,logEvidence_exhaustive";
        // harmonic
        for (int mainRep=0; mainRep<globals.mainRepeats; mainRep++) {
            globals.outputEvidence_fileStream << ",logEvidence_harmonic_rep" << mainRep+1;
        }
        globals.outputEvidence_fileStream << ",logEvidence_harmonic_grandMean,logEvidence_harmonic_grandSE";
        // structure
        for (int mainRep=0; mainRep<globals.mainRepeats; mainRep++) {
            globals.outputEvidence_fileStream << ",logEvidence_structure_rep" << mainRep+1;
        }
        globals.outputEvidence_fileStream << ",logEvidence_structure_grandMean,logEvidence_structure_grandSE";
        // TI
        globals.outputEvidence_fileStream << ",logEvidence_TI,logEvidence_TI_SE";
        
        globals.outputEvidence_fileStream << "\n";
        globals.outputEvidence_fileStream.flush();
        
    }
    
    // ComparisonStatistics
    if (globals.outputComparisonStatistics_on) {
        // open file stream
        globals.outputComparisonStatistics_fileStream = safe_ofstream(globals.outputComparisonStatistics_filePath, globals.outputLog_on, globals.outputLog_fileStream);
        // fixed headers
        globals.outputComparisonStatistics_fileStream << "K,AIC,BIC,DIC_S,DIC_G";
        
        globals.outputComparisonStatistics_fileStream << "\n";
        globals.outputComparisonStatistics_fileStream.flush();
        
    }
    
    // Evanno
    if (globals.outputEvanno_on) {
        // open file stream
        globals.outputEvanno_fileStream = safe_ofstream(globals.outputEvanno_filePath, globals.outputLog_on, globals.outputLog_fileStream);
        // fixed headers
        globals.outputEvanno_fileStream << "K,delta_K";
        
        globals.outputEvanno_fileStream << "\n";
        globals.outputEvanno_fileStream.flush();
        
    }
    
    // EvidenceDetails
    if (globals.outputEvidenceDetails_on) {
        // open file stream
        globals.outputEvidenceDetails_fileStream = safe_ofstream(globals.outputEvidenceDetails_filePath, globals.outputLog_on, globals.outputLog_fileStream);
        // fixed headers
        globals.outputEvidenceDetails_fileStream << "K";
        // structure mean and variance
        for (int mainRep=0; mainRep<globals.mainRepeats; mainRep++) {
            globals.outputEvidenceDetails_fileStream << ",structure_loglike_mean_rep" << mainRep+1;
        }
        for (int mainRep=0; mainRep<globals.mainRepeats; mainRep++) {
            globals.outputEvidenceDetails_fileStream << ",structure_loglike_var_rep" << mainRep+1;
        }
        // TI mean and standard error
        if (globals.thermodynamic_on) {
            for (int TIrep=0; TIrep<globals.thermodynamicRungs; TIrep++) {
                globals.outputEvidenceDetails_fileStream << ",TIpoint_mean_rung" << TIrep+1;
            }
            for (int TIrep=0; TIrep<globals.thermodynamicRungs; TIrep++) {
                globals.outputEvidenceDetails_fileStream << ",TIpoint_SE_rung" << TIrep+1;
            }
        }
        
        globals.outputEvidenceDetails_fileStream << "\n";
        globals.outputEvidenceDetails_fileStream.flush();
        
    }
    
    // PosteriorGrouping
    if (globals.outputPosteriorGrouping_on) {
        // open file stream
        globals.outputPosteriorGrouping_fileStream = safe_ofstream(globals.outputPosteriorGrouping_filePath, globals.outputLog_on, globals.outputLog_fileStream);
        // fixed headers
        globals.outputPosteriorGrouping_fileStream << "K,mainRep,MCMCsample";
        // non-admixture version
        if (!globals.admix_on) {
            for (int i=0; i<globals.n; i++) {
                globals.outputPosteriorGrouping_fileStream << ",ind" << i+1;
            }
        }
        // admixture version
        if (globals.admix_on) {
            for (int i=0; i<globals.n; i++) {
                for (int l=0; l<globals.loci; l++) {
                    for (int p=0; p<globals.ploidy_vec[i]; p++) {
                        globals.outputPosteriorGrouping_fileStream << ",ind" << i+1 << "_loc" << l+1 << "_copy" << p+1;
                    }
                }
            }
        }
        globals.outputPosteriorGrouping_fileStream << "\n";
        globals.outputPosteriorGrouping_fileStream.flush();
    }
    
    // MaxLike_alleleFreqs
    if (globals.outputMaxLike_alleleFreqs_on) {
        // open file stream
        globals.outputMaxLike_alleleFreqs_fileStream = safe_ofstream(globals.outputMaxLike_alleleFreqs_filePath, globals.outputLog_on, globals.outputLog_fileStream);
        // fixed headers
        globals.outputMaxLike_alleleFreqs_fileStream << "K,deme,locus,allele,frequency";
        
        globals.outputMaxLike_alleleFreqs_fileStream << "\n";
        globals.outputMaxLike_alleleFreqs_fileStream.flush();
    }
    
    // MaxLike_admixFreqs
    if (globals.outputMaxLike_admixFreqs_on) {
        // open file stream
        globals.outputMaxLike_admixFreqs_fileStream = safe_ofstream(globals.outputMaxLike_admixFreqs_filePath, globals.outputLog_on, globals.outputLog_fileStream);
        // fixed headers
        globals.outputMaxLike_admixFreqs_fileStream << "K,ind,deme,admixture_proportion";
        
        globals.outputMaxLike_admixFreqs_fileStream << "\n";
        globals.outputMaxLike_admixFreqs_fileStream.flush();
    }
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movq %rdi, %r14
cmpb $0x1, 0x2c3d(%rdi)
movq %rdi, (%rsp)
jne 0x230bd
leaq 0x340(%r14), %rsi
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
callq 0x3430
movzbl 0x2c3c(%r14), %edx
leaq 0x970(%r14), %rcx
leaq 0x108(%rsp), %rdi
movq %rbx, %rsi
callq 0x22438
leaq 0xb70(%r14), %rbx
leaq 0x108(%rsp), %rsi
movq %rbx, %rdi
callq 0x33d0
leaq 0x108(%rsp), %rdi
callq 0x3460
leaq 0xe8(%rsp), %rdi
callq 0x3170
leaq 0x6679(%rip), %rsi      # 0x296fa
movq %rbx, %rdi
callq 0x3350
cmpb $0x1, 0x2bd0(%r14)
jne 0x230a2
leaq 0x6694(%rip), %rsi      # 0x2972e
movq %rbx, %rdi
callq 0x3350
leaq 0x4812(%rip), %rsi      # 0x278bb
movq %rbx, %rdi
callq 0x3350
movq %rbx, %rdi
callq 0x3230
movq (%rsp), %r14
cmpb $0x1, 0x2c45(%r14)
jne 0x231ed
leaq 0x440(%r14), %rsi
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
callq 0x3430
movzbl 0x2c3c(%r14), %edx
leaq 0x970(%r14), %rcx
leaq 0x108(%rsp), %rdi
movq %rbx, %rsi
callq 0x22438
addq $0x1970, %r14           # imm = 0x1970
leaq 0x108(%rsp), %rsi
movq %r14, %rdi
callq 0x33d0
leaq 0x108(%rsp), %rdi
callq 0x3460
leaq 0xc8(%rsp), %rdi
callq 0x3170
leaq 0x65fc(%rip), %rsi      # 0x29735
movq %r14, %rdi
callq 0x3350
pushq $0x1
popq %rbx
leaq 0x6603(%rip), %r15      # 0x2974e
leal -0x1(%rbx), %eax
movq (%rsp), %rcx
cmpl 0x2c0c(%rcx), %eax
jge 0x23173
movq %r14, %rdi
movq %r15, %rsi
callq 0x3350
movq %rax, %rdi
movl %ebx, %esi
callq 0x3570
incl %ebx
jmp 0x2314b
leaq 0x65ee(%rip), %rsi      # 0x29768
movq %r14, %rdi
callq 0x3350
pushq $0x1
popq %rbx
leaq 0x6619(%rip), %r15      # 0x297a5
leal -0x1(%rbx), %eax
movq (%rsp), %rcx
cmpl 0x2c0c(%rcx), %eax
jge 0x231b4
movq %r14, %rdi
movq %r15, %rsi
callq 0x3350
movq %rax, %rdi
movl %ebx, %esi
callq 0x3570
incl %ebx
jmp 0x2318c
leaq 0x6605(%rip), %rsi      # 0x297c0
movq %r14, %rdi
callq 0x3350
leaq 0x6635(%rip), %rsi      # 0x297ff
movq %r14, %rdi
callq 0x3350
leaq 0x46e2(%rip), %rsi      # 0x278bb
movq %r14, %rdi
callq 0x3350
movq %r14, %rdi
callq 0x3230
movq (%rsp), %r14
cmpb $0x1, 0x2c49(%r14)
jne 0x2328c
leaq 0x4c0(%r14), %rsi
leaq 0xa8(%rsp), %rbx
movq %rbx, %rdi
callq 0x3430
movzbl 0x2c3c(%r14), %edx
leaq 0x970(%r14), %rcx
leaq 0x108(%rsp), %rdi
movq %rbx, %rsi
callq 0x22438
leaq 0x2170(%r14), %rbx
leaq 0x108(%rsp), %rsi
movq %rbx, %rdi
callq 0x33d0
leaq 0x108(%rsp), %rdi
callq 0x3460
leaq 0xa8(%rsp), %rdi
callq 0x3170
leaq 0x65b8(%rip), %rsi      # 0x29821
movq %rbx, %rdi
callq 0x3350
leaq 0x4643(%rip), %rsi      # 0x278bb
movq %rbx, %rdi
callq 0x3350
movq %rbx, %rdi
callq 0x3230
movq (%rsp), %r14
cmpb $0x1, 0x2c4a(%r14)
jne 0x2332b
leaq 0x4e0(%r14), %rsi
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
callq 0x3430
movzbl 0x2c3c(%r14), %edx
leaq 0x970(%r14), %rcx
leaq 0x108(%rsp), %rdi
movq %rbx, %rsi
callq 0x22438
leaq 0x2370(%r14), %rbx
leaq 0x108(%rsp), %rsi
movq %rbx, %rdi
callq 0x33d0
leaq 0x108(%rsp), %rdi
callq 0x3460
leaq 0x88(%rsp), %rdi
callq 0x3170
leaq 0x652f(%rip), %rsi      # 0x29837
movq %rbx, %rdi
callq 0x3350
leaq 0x45a4(%rip), %rsi      # 0x278bb
movq %rbx, %rdi
callq 0x3350
movq %rbx, %rdi
callq 0x3230
movq (%rsp), %r14
cmpb $0x1, 0x2c47(%r14)
jne 0x234a1
leaq 0x480(%r14), %rsi
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0x3430
movzbl 0x2c3c(%r14), %edx
leaq 0x970(%r14), %rcx
leaq 0x108(%rsp), %rdi
movq %rbx, %rsi
callq 0x22438
addq $0x1d70, %r14           # imm = 0x1D70
leaq 0x108(%rsp), %rsi
movq %r14, %rdi
callq 0x33d0
leaq 0x108(%rsp), %rdi
callq 0x3460
leaq 0x68(%rsp), %rdi
callq 0x3170
leaq 0x649e(%rip), %rsi      # 0x2983f
movq %r14, %rdi
callq 0x3350
pushq $0x1
popq %rbx
leaq 0x648e(%rip), %r15      # 0x29841
leal -0x1(%rbx), %ecx
movq (%rsp), %rax
movl 0x2c0c(%rax), %eax
cmpl %eax, %ecx
jge 0x233dd
movq %r14, %rdi
movq %r15, %rsi
callq 0x3350
movq %rax, %rdi
movl %ebx, %esi
callq 0x3570
incl %ebx
jmp 0x233b3
pushq $0x1
popq %rbx
leaq 0x6476(%rip), %r15      # 0x2985d
leal -0x1(%rbx), %ecx
cmpl %eax, %ecx
jge 0x23411
movq %r14, %rdi
movq %r15, %rsi
callq 0x3350
movq %rax, %rdi
movl %ebx, %esi
callq 0x3570
movq (%rsp), %rax
movl 0x2c0c(%rax), %eax
incl %ebx
jmp 0x233e7
movq (%rsp), %rax
cmpb $0x1, 0x2c1c(%rax)
jne 0x23486
pushq $0x1
popq %rbx
leaq 0x6450(%rip), %r15      # 0x29878
leal -0x1(%rbx), %ecx
movq (%rsp), %rax
movl 0x2c20(%rax), %eax
cmpl %eax, %ecx
jge 0x23452
movq %r14, %rdi
movq %r15, %rsi
callq 0x3350
movq %rax, %rdi
movl %ebx, %esi
callq 0x3570
incl %ebx
jmp 0x23428
pushq $0x1
popq %rbx
leaq 0x642f(%rip), %r15      # 0x2988b
leal -0x1(%rbx), %ecx
cmpl %eax, %ecx
jge 0x23486
movq %r14, %rdi
movq %r15, %rsi
callq 0x3350
movq %rax, %rdi
movl %ebx, %esi
callq 0x3570
movq (%rsp), %rax
movl 0x2c20(%rax), %eax
incl %ebx
jmp 0x2345c
leaq 0x442e(%rip), %rsi      # 0x278bb
movq %r14, %rdi
callq 0x3350
movq %r14, %rdi
callq 0x3230
movq (%rsp), %r14
cmpb $0x1, 0x2c48(%r14)
jne 0x23626
leaq 0x4a0(%r14), %rsi
leaq 0x48(%rsp), %rbx
movq %r14, %r15
movq %rbx, %rdi
callq 0x3430
movzbl 0x2c3c(%r14), %edx
leaq 0x970(%r14), %rcx
leaq 0x108(%rsp), %rdi
movq %rbx, %rsi
callq 0x22438
leaq 0x1f70(%r15), %r14
leaq 0x108(%rsp), %rsi
movq %r14, %rdi
callq 0x33d0
leaq 0x108(%rsp), %rdi
callq 0x3460
leaq 0x48(%rsp), %rdi
callq 0x3170
leaq 0x6382(%rip), %rsi      # 0x2989c
movq %r14, %rdi
callq 0x3350
movb 0x2bd0(%r15), %al
testb %al, %al
movq %r15, %rdx
jne 0x23568
pushq $0x1
popq %rbx
leaq 0x6377(%rip), %r15      # 0x298b1
leal -0x1(%rbx), %eax
cmpl 0x2d18(%rdx), %eax
jge 0x23562
movq %r14, %rdi
movq %r15, %rsi
callq 0x3350
movq %rax, %rdi
movl %ebx, %esi
callq 0x3570
movq (%rsp), %rdx
incl %ebx
jmp 0x2353a
movb 0x2bd0(%rdx), %al
testb $0x1, %al
je 0x2360b
xorl %r12d, %r12d
leaq 0x64a5(%rip), %r13      # 0x29a1f
movslq 0x2d18(%rdx), %rax
cmpq %rax, %r12
jge 0x2360b
leaq 0x1(%r12), %rbp
xorl %ebx, %ebx
cmpl 0x2d1c(%rdx), %ebx
jge 0x23603
incl %ebx
pushq $0x1
popq %rax
movl %eax, %r15d
leal -0x1(%r15), %eax
movq 0x2cd0(%rdx), %rcx
cmpl (%rcx,%r12,4), %eax
jge 0x23591
movq %r14, %rdi
leaq 0x62f5(%rip), %rsi      # 0x298b1
callq 0x3350
movq %rax, %rdi
movl %ebp, %esi
callq 0x3570
movq %rax, %rdi
leaq 0x62e1(%rip), %rsi      # 0x298b6
callq 0x3350
movq %rax, %rdi
movl %ebx, %esi
callq 0x3570
movq %rax, %rdi
movq %r13, %rsi
callq 0x3350
movq %rax, %rdi
movl %r15d, %esi
callq 0x3570
movq (%rsp), %rdx
incl %r15d
jmp 0x235a1
movq %rbp, %r12
jmp 0x2357a
leaq 0x42a9(%rip), %rsi      # 0x278bb
movq %r14, %rdi
callq 0x3350
movq %r14, %rdi
callq 0x3230
movq (%rsp), %r14
cmpb $0x1, 0x2c4b(%r14)
jne 0x236bf
leaq 0x500(%r14), %rsi
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x3430
movzbl 0x2c3c(%r14), %edx
leaq 0x970(%r14), %rcx
leaq 0x108(%rsp), %rdi
movq %rbx, %rsi
callq 0x22438
leaq 0x2570(%r14), %rbx
leaq 0x108(%rsp), %rsi
movq %rbx, %rdi
callq 0x33d0
leaq 0x108(%rsp), %rdi
callq 0x3460
leaq 0x28(%rsp), %rdi
callq 0x3170
leaq 0x621f(%rip), %rsi      # 0x298bb
movq %rbx, %rdi
callq 0x3350
leaq 0x4210(%rip), %rsi      # 0x278bb
movq %rbx, %rdi
callq 0x3350
movq %rbx, %rdi
callq 0x3230
movq (%rsp), %r14
cmpb $0x1, 0x2c4c(%r14)
jne 0x23754
leaq 0x520(%r14), %rsi
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x3430
movzbl 0x2c3c(%r14), %edx
leaq 0x970(%r14), %rcx
leaq 0x108(%rsp), %rdi
movq %rbx, %rsi
callq 0x22438
addq $0x2770, %r14           # imm = 0x2770
leaq 0x108(%rsp), %rsi
movq %r14, %rdi
callq 0x33d0
leaq 0x108(%rsp), %rdi
callq 0x3460
leaq 0x8(%rsp), %rdi
callq 0x3170
leaq 0x61a4(%rip), %rsi      # 0x298d9
movq %r14, %rdi
callq 0x3350
leaq 0x4177(%rip), %rsi      # 0x278bb
movq %r14, %rdi
callq 0x3350
movq %r14, %rdi
callq 0x3230
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3460
jmp 0x2377b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x23859
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3460
jmp 0x2379a
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x23859
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3460
jmp 0x237b9
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x23859
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3460
jmp 0x237d8
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x23859
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3460
jmp 0x237f4
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x23859
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3460
jmp 0x23813
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x23859
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3460
jmp 0x23832
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x23859
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3460
jmp 0x23851
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x3170
movq %rbx, %rdi
callq 0x35a0