// File: mshabbirhasan[P]ups-indel/src/ups_indel.cpp
// Function: main
int main(int argc, char const* *argv) {
    if (argc != 5) {
        std::cerr << "USAGE: ups_indel REFERENCE_FILE.fa VCF_FILE.vcf OUTPUT_FILE_NAME -hd=true.\n";
        return 1;
    }

    reference_file_name = argv[1];
    input_file_name = argv[2];
    output_file_name = argv[3];
    string horizontal_decomposition_flag = argv[4];

    if(horizontal_decomposition_flag == "-hd=false"){
        isHorizontalDecompositionEnabled = false;
    }

    int splitFlag = splitInput(input_file_name);
    if (splitFlag < 0) {
      return 1;
    }

    pthread_t threads[25]; // 24 chromosomes and MT

    string input_file_base_name_with_extension =
        input_file_name.substr(0, input_file_name.find_last_of(".vcf") + 1);
    string input_file_name_str(input_file_base_name_with_extension);

    input_file_base_name =
        input_file_name_str.substr(0, input_file_name_str.find_last_of("."));

    for (int k = 0; k < 25; k++) {
        int thread_creation_flag = pthread_create( & threads[k], NULL, executeUPSIndel, (void * )(intptr_t)(k + 1));

        if (thread_creation_flag) {
            std::cerr << "ERROR: Unable to create thread, " << thread_creation_flag << ".\n";
            exit(-1);
        }
    }

    for (int l = 0; l < 25; l++) {
        pthread_join(threads[l], NULL);
    }

    if (merge_outputs()) {
        return 1;
    }

    if (cleanup()) {
      return 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x5, -0x8(%rbp)
je 0x990e
movq 0x2e6fa(%rip), %rdi     # 0x37ff0
leaq 0x1ebda(%rip), %rsi     # 0x284d7
callq 0x4430
movl $0x1, -0x4(%rbp)
jmp 0x9ccd
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x2eb7b(%rip), %rdi     # 0x38498
callq 0x45c0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
leaq 0x2eb87(%rip), %rdi     # 0x384b8
callq 0x45c0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0x2ebb3(%rip), %rdi     # 0x384f8
callq 0x45c0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x1c0(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x4780
movq -0x1c0(%rbp), %rsi
movq -0x1b8(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x45d0
jmp 0x9982
leaq -0x31(%rbp), %rdi
callq 0x44a0
leaq 0x1eb91(%rip), %rsi     # 0x28523
leaq -0x30(%rbp), %rdi
callq 0xa360
movb %al, -0x1c1(%rbp)
jmp 0x99a3
movb -0x1c1(%rbp), %al
testb $0x1, %al
jne 0x99af
jmp 0x99e3
movb $0x0, 0x2eab2(%rip)     # 0x38468
jmp 0x99e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x44a0
jmp 0x9cd9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x9cc2
leaq 0x2eace(%rip), %rsi     # 0x384b8
leaq -0x68(%rbp), %rdi
callq 0x41f0
jmp 0x99f5
leaq -0x68(%rbp), %rdi
callq 0x8d60
movl %eax, -0x1c8(%rbp)
jmp 0x9a06
leaq -0x68(%rbp), %rdi
callq 0x48b8
movl -0x1c8(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jge 0x9a4b
movl $0x1, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x9cb7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x48b8
jmp 0x9cc2
leaq 0x2ea66(%rip), %rdi     # 0x384b8
movq %rdi, -0x1d0(%rbp)
leaq 0x1ea6a(%rip), %rsi     # 0x284ca
movq $-0x1, %rdx
callq 0x4400
movq -0x1d0(%rbp), %rsi
movq %rax, %rcx
incq %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x160(%rbp), %rdi
callq 0x4460
jmp 0x9a8b
leaq -0x180(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x41f0
jmp 0x9aa0
leaq 0x1e98a(%rip), %rsi     # 0x28431
leaq -0x180(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
movq $-0x1, %rdx
callq 0x4400
movq -0x1d8(%rbp), %rsi
movq %rax, %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x1a0(%rbp), %rdi
callq 0x4460
jmp 0x9add
leaq 0x2e9f4(%rip), %rdi     # 0x384d8
leaq -0x1a0(%rbp), %rsi
callq 0x4510
leaq -0x1a0(%rbp), %rdi
callq 0x48b8
movl $0x0, -0x1a4(%rbp)
cmpl $0x19, -0x1a4(%rbp)
jge 0x9bf1
movslq -0x1a4(%rbp), %rax
leaq -0x140(%rbp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
movl -0x1a4(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
xorl %eax, %eax
movl %eax, %esi
leaq -0xd6f(%rip), %rdx      # 0x8dd0
callq 0x47d0
movl %eax, -0x1a8(%rbp)
cmpl $0x0, -0x1a8(%rbp)
je 0x9bdb
movq 0x2e492(%rip), %rdi     # 0x37ff0
leaq 0x1e9c8(%rip), %rsi     # 0x2852d
callq 0x4430
movq %rax, -0x1e0(%rbp)
jmp 0x9b73
movq -0x1e0(%rbp), %rdi
movl -0x1a8(%rbp), %esi
callq 0x4740
movq %rax, -0x1e8(%rbp)
jmp 0x9b8e
movq -0x1e8(%rbp), %rdi
leaq 0x1e984(%rip), %rsi     # 0x28520
callq 0x4430
jmp 0x9ba3
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x44f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x9ca9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x48b8
jmp 0x9ca9
jmp 0x9bdd
movl -0x1a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1a4(%rbp)
jmp 0x9b06
movl $0x0, -0x1ac(%rbp)
cmpl $0x19, -0x1ac(%rbp)
jge 0x9c31
movslq -0x1ac(%rbp), %rax
movq -0x140(%rbp,%rax,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x43e0
jmp 0x9c1e
jmp 0x9c20
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ac(%rbp)
jmp 0x9bfb
callq 0x9110
movl %eax, -0x1ec(%rbp)
jmp 0x9c3e
movl -0x1ec(%rbp), %eax
cmpl $0x0, %eax
je 0x9c59
movl $0x1, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x9c8f
callq 0x9730
movl %eax, -0x1f0(%rbp)
jmp 0x9c66
movl -0x1f0(%rbp), %eax
cmpl $0x0, %eax
je 0x9c81
movl $0x1, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x9c8f
movl $0x0, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x48b8
leaq -0x160(%rbp), %rdi
callq 0x48b8
jmp 0x9cb7
leaq -0x160(%rbp), %rdi
callq 0x48b8
jmp 0x9cc2
leaq -0x30(%rbp), %rdi
callq 0x48b8
jmp 0x9ccd
leaq -0x30(%rbp), %rdi
callq 0x48b8
jmp 0x9cd9
movl -0x4(%rbp), %eax
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x4770
nopw %cs:(%rax,%rax)
nopl (%rax)