// File: /workspace/github_cpp_makefile_star2_O2/mshabbirhasan[P]ups-indel/src/ups_indel.cpp
// Function: merge_outputs()
int merge_outputs() {
    bool hasHeaderPrinted = false;
    ofstream fout(output_file_name + ".uvcf");
    if (fout.is_open()) {
        for (int chrNum = 1; chrNum <= 25; chrNum++) {
            string chr = "";
            if (chrNum >= 1 && chrNum <= 22) {
                chr = to_string(chrNum);
            } else if (chrNum == 23) {
                chr = "X";
            } else if (chrNum == 24) {
                chr = "Y";
            } else if (chrNum == 25) {
                chr = "MT";
            }

            string chromosome_wise_uvcf_file_name =
                output_file_name + "." + chr + ".uvcf";
            string line;

            ifstream uvcfFile(chromosome_wise_uvcf_file_name);
            if (fileExists(chromosome_wise_uvcf_file_name)) {
                if(uvcfFile.is_open()){
                    while (getline(uvcfFile, line)) {
                        if (line.at(0) == '#' && !hasHeaderPrinted) {
                            fout << line << endl;
                        } else if (line.at(0) != '#') {
                            fout << line << endl;
                        }
                    }
                    uvcfFile.close();
                } else {
                    std::cerr << "ERROR: Could not read from UVCF file: " << chromosome_wise_uvcf_file_name << ".\n";
                    return 1;
                }

                hasHeaderPrinted = true;
            }
        }

        fout.close();
    } else {
        std::cerr << "ERROR: Could not write output: " << output_file_name << ".uvcf.\n";
        return 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
leaq 0xe2ea(%rip), %rsi      # 0x143d0
leaq 0x70ee(%rip), %rdx      # 0xd1db
leaq -0x290(%rbp), %rbx
movq %rbx, %rdi
callq 0x6863
leaq -0x490(%rbp), %rdi
pushq $0x10
popq %rdx
movq %rbx, %rsi
callq 0x3630
leaq -0x290(%rbp), %rdi
callq 0x3668
leaq -0x420(%rbp), %rdi
callq 0x30d0
testb %al, %al
je 0x630b
pushq $0x1
popq %r12
xorl %ebx, %ebx
leaq -0x290(%rbp), %r13
leaq -0x48(%rbp), %r15
cmpl $0x1a, %r12d
je 0x6341
leaq -0x88(%rbp), %r14
movq %r14, %rdi
leaq 0x70d2(%rip), %rsi      # 0xd22c
movq %r13, %rdx
callq 0x3150
cmpl $0x16, %r12d
ja 0x6188
movq %r13, %rdi
movl %r12d, %esi
callq 0x6b0e
movq %r14, %rdi
movq %r13, %rsi
callq 0x33e0
movq %r13, %rdi
callq 0x3668
jmp 0x61b5
cmpl $0x18, %r12d
leaq 0x6fe9(%rip), %rsi      # 0xd17c
leaq 0x7426(%rip), %rax      # 0xd5c0
cmoveq %rax, %rsi
cmpl $0x17, %r12d
leaq 0x739a(%rip), %rax      # 0xd543
cmoveq %rax, %rsi
movq %r14, %rdi
callq 0x3610
movq %r15, %rdi
leaq 0xe211(%rip), %rsi      # 0x143d0
leaq 0x6f75(%rip), %rdx      # 0xd13b
callq 0x6863
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x6cb7
leaq -0x68(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
leaq 0x6ff1(%rip), %rdx      # 0xd1db
callq 0x6c8e
movq %r13, %rdi
callq 0x3668
movq %r15, %rdi
callq 0x3668
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
andq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movq %r13, %rdi
movq %r14, %rsi
pushq $0x8
popq %rdx
callq 0x3500
movq %r14, %rdi
callq 0x6ce0
movb $0x1, %r14b
testb %al, %al
je 0x62d8
leaq -0x218(%rbp), %rdi
callq 0x30d0
testb %al, %al
je 0x6298
movq %r13, %rdi
movq %r15, %rsi
callq 0x30b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x62cb
movq %r15, %rdi
xorl %esi, %esi
callq 0x3620
cmpb $0x23, (%rax)
setne %al
orb %bl, %al
testb $0x1, %al
je 0x627f
movq %r15, %rdi
xorl %esi, %esi
callq 0x3620
cmpb $0x23, (%rax)
je 0x6241
leaq -0x490(%rbp), %rdi
movq %r15, %rsi
callq 0x32c0
movq %rax, %rdi
callq 0x31a0
jmp 0x6241
movq 0xdd51(%rip), %rdi      # 0x13ff0
leaq 0x6ed9(%rip), %rsi      # 0xd17f
callq 0x3310
movq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x32c0
movq %rax, %rdi
leaq 0x6f69(%rip), %rsi      # 0xd22a
callq 0x3310
xorl %r14d, %r14d
jmp 0x62d8
movb $0x1, %bl
movq %r13, %rdi
callq 0x30c0
movb $0x1, %r14b
movq %r13, %rdi
callq 0x30e0
movq %r15, %rdi
callq 0x3668
leaq -0x68(%rbp), %rdi
callq 0x3668
leaq -0x88(%rbp), %rdi
callq 0x3668
incl %r12d
testb %r14b, %r14b
jne 0x613f
jmp 0x633c
movq 0xdcde(%rip), %rdi      # 0x13ff0
leaq 0x6e8d(%rip), %rsi      # 0xd1a6
callq 0x3310
leaq 0xe0ab(%rip), %rsi      # 0x143d0
movq %rax, %rdi
callq 0x32c0
leaq 0x6e92(%rip), %rsi      # 0xd1c6
movq %rax, %rdi
callq 0x3310
pushq $0x1
popq %rbx
jmp 0x634f
xorl %ebx, %ebx
leaq -0x490(%rbp), %rdi
callq 0x3460
leaq -0x490(%rbp), %rdi
callq 0x3490
movl %ebx, %eax
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x290(%rbp), %rdi
callq 0x3668
jmp 0x63ea
jmp 0x6386
jmp 0x638b
jmp 0x638b
movq %rax, %rbx
jmp 0x63de
movq %rax, %rbx
jmp 0x63d2
movq %rax, %rbx
leaq -0x290(%rbp), %rdi
callq 0x3668
jmp 0x63a4
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
jmp 0x63cd
movq %rax, %rbx
jmp 0x63c0
jmp 0x63b1
movq %rax, %rbx
leaq -0x290(%rbp), %rdi
callq 0x30e0
leaq -0x48(%rbp), %rdi
callq 0x3668
leaq -0x68(%rbp), %rdi
callq 0x3668
leaq -0x88(%rbp), %rdi
callq 0x3668
leaq -0x490(%rbp), %rdi
callq 0x3490
movq %rbx, %rdi
callq 0x3590