// File: 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
subq $0x580, %rsp            # imm = 0x580
movb $0x0, -0x5(%rbp)
leaq 0x2f3d2(%rip), %rsi     # 0x384f8
leaq 0x1f3a4(%rip), %rdx     # 0x284d1
leaq -0x228(%rbp), %rdi
movq %rdi, -0x518(%rbp)
callq 0xa410
movq -0x518(%rbp), %rsi
leaq -0x208(%rbp), %rdi
movl $0x10, %edx
callq 0x4860
jmp 0x915a
leaq -0x228(%rbp), %rdi
callq 0x48b8
leaq -0x208(%rbp), %rdi
callq 0x4340
movb %al, -0x519(%rbp)
jmp 0x917a
movb -0x519(%rbp), %al
testb $0x1, %al
jne 0x9189
jmp 0x9682
movl $0x1, -0x238(%rbp)
cmpl $0x19, -0x238(%rbp)
jg 0x9672
leaq -0x259(%rbp), %rdi
movq %rdi, -0x528(%rbp)
callq 0x4780
movq -0x528(%rbp), %rdx
leaq 0x1f361(%rip), %rsi     # 0x28522
leaq -0x258(%rbp), %rdi
callq 0x45d0
jmp 0x91cf
leaq -0x259(%rbp), %rdi
callq 0x44a0
cmpl $0x1, -0x238(%rbp)
jl 0x92a1
cmpl $0x16, -0x238(%rbp)
jg 0x92a1
movl -0x238(%rbp), %esi
leaq -0x280(%rbp), %rdi
callq 0xa890
jmp 0x9209
leaq -0x258(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x4510
leaq -0x280(%rbp), %rdi
callq 0x48b8
jmp 0x9307
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x48b8
jmp 0x9717
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x970b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x259(%rbp), %rdi
callq 0x44a0
jmp 0x970b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x9661
cmpl $0x17, -0x238(%rbp)
jne 0x92c1
leaq 0x1f586(%rip), %rsi     # 0x28837
leaq -0x258(%rbp), %rdi
callq 0x45c0
jmp 0x92bf
jmp 0x9305
cmpl $0x18, -0x238(%rbp)
jne 0x92e1
leaq 0x1f5e3(%rip), %rsi     # 0x288b4
leaq -0x258(%rbp), %rdi
callq 0x45c0
jmp 0x92df
jmp 0x9303
cmpl $0x19, -0x238(%rbp)
jne 0x9301
leaq 0x1f181(%rip), %rsi     # 0x28472
leaq -0x258(%rbp), %rdi
callq 0x45c0
jmp 0x92ff
jmp 0x9301
jmp 0x9303
jmp 0x9305
jmp 0x9307
leaq 0x2f1ea(%rip), %rsi     # 0x384f8
leaq 0x1f11c(%rip), %rdx     # 0x28431
leaq -0x2e0(%rbp), %rdi
callq 0xa410
jmp 0x9323
leaq -0x2c0(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
leaq -0x258(%rbp), %rdx
callq 0xad20
jmp 0x933f
leaq 0x1f18b(%rip), %rdx     # 0x284d1
leaq -0x2a0(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0xacd0
jmp 0x935b
leaq -0x2c0(%rbp), %rdi
callq 0x48b8
leaq -0x2e0(%rbp), %rdi
callq 0x48b8
leaq -0x300(%rbp), %rdi
callq 0x45f0
leaq -0x508(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
movl $0x8, %edx
callq 0x46c0
jmp 0x9399
leaq -0x2a0(%rbp), %rdi
callq 0xad70
movb %al, -0x529(%rbp)
jmp 0x93ad
movb -0x529(%rbp), %al
testb $0x1, %al
jne 0x93bc
jmp 0x95e9
leaq -0x508(%rbp), %rdi
callq 0x46b0
movb %al, -0x52a(%rbp)
jmp 0x93d0
movb -0x52a(%rbp), %al
testb $0x1, %al
jne 0x93df
jmp 0x9585
jmp 0x93e1
leaq -0x508(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x4100
movq %rax, -0x538(%rbp)
jmp 0x93fd
movq -0x538(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x4520
movb %al, -0x539(%rbp)
jmp 0x941b
movb -0x539(%rbp), %al
testb $0x1, %al
jne 0x942a
jmp 0x9575
xorl %eax, %eax
movl %eax, %esi
leaq -0x300(%rbp), %rdi
callq 0x4850
movq %rax, -0x548(%rbp)
jmp 0x9443
movq -0x548(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x9513
testb $0x1, -0x5(%rbp)
jne 0x9513
leaq -0x208(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x43c0
movq %rax, -0x550(%rbp)
jmp 0x947c
movq -0x550(%rbp), %rdi
movq 0x2eb16(%rip), %rsi     # 0x37fa0
callq 0x4480
jmp 0x9491
jmp 0x9570
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x94c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x48b8
leaq -0x2e0(%rbp), %rdi
callq 0x48b8
jmp 0x9661
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x9649
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x508(%rbp), %rdi
callq 0x4140
jmp 0x9649
xorl %eax, %eax
movl %eax, %esi
leaq -0x300(%rbp), %rdi
callq 0x4850
movq %rax, -0x558(%rbp)
jmp 0x952c
movq -0x558(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0x956e
leaq -0x208(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x43c0
movq %rax, -0x560(%rbp)
jmp 0x9557
movq -0x560(%rbp), %rdi
movq 0x2ea3b(%rip), %rsi     # 0x37fa0
callq 0x4480
jmp 0x956c
jmp 0x956e
jmp 0x9570
jmp 0x93e1
leaq -0x508(%rbp), %rdi
callq 0x4120
jmp 0x9583
jmp 0x95e5
movq 0x2ea64(%rip), %rdi     # 0x37ff0
leaq 0x1eee2(%rip), %rsi     # 0x28475
callq 0x4430
movq %rax, -0x568(%rbp)
jmp 0x95a1
movq -0x568(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x43c0
movq %rax, -0x570(%rbp)
jmp 0x95bd
movq -0x570(%rbp), %rdi
leaq 0x1ef55(%rip), %rsi     # 0x28520
callq 0x4430
jmp 0x95d2
movl $0x1, -0x4(%rbp)
movl $0x1, -0x50c(%rbp)
jmp 0x95f3
movb $0x1, -0x5(%rbp)
movl $0x0, -0x50c(%rbp)
leaq -0x508(%rbp), %rdi
callq 0x4140
leaq -0x300(%rbp), %rdi
callq 0x48b8
leaq -0x2a0(%rbp), %rdi
callq 0x48b8
leaq -0x258(%rbp), %rdi
callq 0x48b8
movl -0x50c(%rbp), %eax
testl %eax, %eax
jne 0x96f3
jmp 0x9633
jmp 0x9635
movl -0x238(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x238(%rbp)
jmp 0x9193
leaq -0x300(%rbp), %rdi
callq 0x48b8
leaq -0x2a0(%rbp), %rdi
callq 0x48b8
leaq -0x258(%rbp), %rdi
callq 0x48b8
jmp 0x970b
leaq -0x208(%rbp), %rdi
callq 0x4610
jmp 0x9680
jmp 0x96e2
movq 0x2e967(%rip), %rdi     # 0x37ff0
leaq 0x1ee0c(%rip), %rsi     # 0x2849c
callq 0x4430
movq %rax, -0x578(%rbp)
jmp 0x969e
movq -0x578(%rbp), %rdi
leaq 0x2ee4c(%rip), %rsi     # 0x384f8
callq 0x43c0
movq %rax, -0x580(%rbp)
jmp 0x96ba
movq -0x580(%rbp), %rdi
leaq 0x1edf4(%rip), %rsi     # 0x284bc
callq 0x4430
jmp 0x96cf
movl $0x1, -0x4(%rbp)
movl $0x1, -0x50c(%rbp)
jmp 0x96f3
movl $0x0, -0x4(%rbp)
movl $0x1, -0x50c(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x4640
movl -0x4(%rbp), %eax
addq $0x580, %rsp            # imm = 0x580
popq %rbp
retq
leaq -0x208(%rbp), %rdi
callq 0x4640
movq -0x230(%rbp), %rdi
callq 0x4770
nopw %cs:(%rax,%rax)