// File: /workspace/github_cpp_makefile_star2_O3/mshabbirhasan[P]ups-indel/src/ups_generate_redundant_indel_list.cpp
// Function: main
int main(int argc, char const ** argv){
    if (argc != 3){
        std::cerr << "USAGE: ups_generate_redundant_indel_list UPS_INDEL_VCF_FILE.UVCF OUTPUT_FILE_NAME.\n";
        return 1;
    }

	string line;
    ifstream myInputFile(argv[1]); //input uvcf file
    ofstream myOutputFile(argv[2]); //output text file

    std::map<string, std::list<string> > myHashMap;

    if (myInputFile.is_open()){
        while (getline(myInputFile, line)){
			if(line.at(0)!='#' && line.at(0)!='\n'){
				vector<string> tokens = split(line, '\t');
                if(tokens.at(3).length() != tokens.at(4).length()){
                    string pattern = tokens.at(7); //the whole pattern in the UVCF file Column 7

                    string key = pattern;
                    string value = tokens.at(2);

                    if(myHashMap.count(key) > 0){
                        list<string> valueList = myHashMap.at(key);
                        if(!(std::find(valueList.begin(), valueList.end(),value)!= valueList.end())){
                            myHashMap[key].push_back(value);
                        }
                    }
                    else{
                        myHashMap[key].push_back(value);
                    }
                }
			}
        }
        myInputFile.close();
    }
    else{
        std::cerr << "ERROR: Can't open the input file.\n";
        return 1;
    }

    if(myOutputFile.is_open()){
        for(std::map<string, std::list<string> >::iterator it = myHashMap.begin(); it!= myHashMap.end(); it++){
            std::list<string> myList = it->second;
            if(myList.size() > 1){
                int i = 1;
                myList.sort();
                myOutputFile<<"[";
                for(std::list<string>::iterator it = myList.begin(); it!= myList.end(); it++, i++){
                    myOutputFile<<*it;
                    if(i<myList.size()){
                        myOutputFile<<", ";
                    }
                }
                myOutputFile<<"]"<<endl;
            }
        }
        myOutputFile.close();
    }
    else{
        std::cerr << "ERROR: File output error.\n";
        return 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4f8, %rsp            # imm = 0x4F8
cmpl $0x3, %edi
jne 0x2b83
movq %rsi, %rbx
leaq -0xb0(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x8(%rsi), %rsi
leaq -0x518(%rbp), %r15
movq %r15, %rdi
movl $0x8, %edx
callq 0x22d0
movq 0x10(%rbx), %rsi
leaq -0x310(%rbp), %rbx
movq %rbx, %rdi
movl $0x10, %edx
callq 0x21f0
leaq -0xf0(%rbp), %r14
movl $0x0, (%r14)
xorl %eax, %eax
movq %rax, 0x8(%r14)
movq %r14, 0x10(%r14)
movq %r14, 0x18(%r14)
movq %rax, 0x20(%r14)
leaq -0x4a0(%rbp), %rdi
callq 0x2080
testb %al, %al
je 0x2ba5
leaq -0x110(%rbp), %r13
movq -0x518(%rbp), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %edx
movq %r15, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x22e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2bb6
cmpq $0x0, -0xb8(%rbp)
je 0x2d79
movq -0xc0(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xa, %eax
je 0x2924
cmpl $0x23, %eax
je 0x2924
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movl $0x9, %edx
callq 0x2540
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rcx
subq %rax, %rcx
movq %rcx, %rdx
sarq $0x5, %rdx
cmpq $0x4, %rdx
jb 0x2d92
cmpq $0x80, %rcx
je 0x2d8b
movq 0x68(%rax), %rcx
cmpq 0x88(%rax), %rcx
je 0x2b72
cmpq $0x7, %rdx
jbe 0x2da5
leaq -0x38(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movq 0xe0(%rax), %rsi
movq 0xe8(%rax), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x347a
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x347a
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq $0x2, %rdx
jbe 0x2db8
leaq -0x78(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %rdi
callq 0x347a
leaq -0xf8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x37d4
cmpq %r14, %rax
je 0x2ac6
leaq -0xf8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2fdc
movq %r13, %rdi
movq %rax, %rsi
callq 0x304e
movq -0x110(%rbp), %r12
leaq -0x88(%rbp), %rax
movq %rax, -0xc8(%rbp)
cmpq %r13, %r12
je 0x2aff
leaq -0xc8(%rbp), %rdi
movq %r12, %rsi
callq 0x38cc
testb %al, %al
jne 0x2afa
movq (%r12), %r12
jmp 0x2aa8
leaq -0xf8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x308a
movq %rax, %r12
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x387e
movq %rax, %rdi
movq %r12, %rsi
callq 0x2050
incq 0x10(%r12)
jmp 0x2b39
cmpq %r13, %r12
jne 0x2b31
leaq -0xf8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x308a
movq %rax, %r12
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x387e
movq %rax, %rdi
movq %r12, %rsi
callq 0x2050
incq 0x10(%r12)
movq %r13, %rdi
callq 0x33a6
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x2b4e
callq 0x2190
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x2b60
callq 0x2190
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x2b72
callq 0x2190
leaq -0xa0(%rbp), %rdi
callq 0x2f84
jmp 0x2924
movq 0x3466(%rip), %rdi      # 0x5ff0
leaq 0x1473(%rip), %rsi      # 0x4004
movl $0x53, %edx
callq 0x2200
movl $0x1, %ebx
jmp 0x2d65
movl $0x22, %edx
leaq 0x14a7(%rip), %rsi      # 0x4058
jmp 0x2cee
leaq -0x518(%rbp), %rdi
callq 0x2070
leaq -0x2a0(%rbp), %rdi
callq 0x2080
testb %al, %al
leaq -0x48(%rbp), %r13
je 0x2ce2
movq -0xe0(%rbp), %r15
cmpq %r14, %r15
je 0x2cd2
leaq 0x148c(%rip), %r12      # 0x407d
leaq 0x40(%r15), %rsi
movq %r13, %rdi
callq 0x304e
cmpq $0x2, -0x38(%rbp)
jb 0x2cb6
movq %r13, %rdi
callq 0x3120
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x145c(%rip), %rsi      # 0x407b
callq 0x2200
movq %r13, %rax
movq -0x48(%rbp), %r13
cmpq %rax, %r13
je 0x2c6c
movl $0x1, %r14d
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
movq %rbx, %rdi
callq 0x2200
cmpq %r14, -0x38(%rbp)
jbe 0x2c5c
movl $0x2, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2200
incq %r14
movq (%r13), %r13
leaq -0x48(%rbp), %rax
cmpq %rax, %r13
jne 0x2c36
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x1405(%rip), %rsi      # 0x4080
callq 0x2200
leaq -0xf0(%rbp), %r14
leaq -0x48(%rbp), %r13
movq -0x310(%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq %r13, %rdi
callq 0x33a6
movq %r15, %rdi
callq 0x2110
movq %rax, %r15
cmpq %r14, %rax
jne 0x2bf1
xorl %ebx, %ebx
leaq -0x310(%rbp), %rdi
callq 0x2210
jmp 0x2cff
movl $0x1a, %edx
leaq 0x1394(%rip), %rsi      # 0x4082
movl $0x1, %ebx
movq 0x32f6(%rip), %rdi      # 0x5ff0
callq 0x2200
leaq -0xf8(%rbp), %rdi
callq 0x33ec
movq 0x32be(%rip), %rax      # 0x5fd0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x308(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x310(%rbp,%rcx)
callq 0x2170
leaq -0x218(%rbp), %rdi
callq 0x20b0
leaq -0x518(%rbp), %rdi
callq 0x2090
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x2d65
callq 0x2190
movl %ebx, %eax
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1361(%rip), %rdi      # 0x40e1
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2250
movl $0x4, %esi
jmp 0x2d97
movl $0x3, %esi
leaq 0x1387(%rip), %rdi      # 0x4125
xorl %eax, %eax
callq 0x2250
leaq 0x1379(%rip), %rdi      # 0x4125
movl $0x7, %esi
xorl %eax, %eax
callq 0x2250
leaq 0x1366(%rip), %rdi      # 0x4125
movl $0x2, %esi
xorl %eax, %eax
callq 0x2250
movq %rax, %rbx
jmp 0x2e7e
movq %rax, %rbx
jmp 0x2e8a
jmp 0x2ddd
movq %rax, %rbx
jmp 0x2e16
movq %rax, %rbx
jmp 0x2e28
jmp 0x2e40
jmp 0x2e40
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x33a6
jmp 0x2e01
jmp 0x2dfe
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x2e16
callq 0x2190
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x2e28
callq 0x2190
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x2e43
callq 0x2190
jmp 0x2e43
jmp 0x2e55
jmp 0x2e55
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x2f84
jmp 0x2e66
jmp 0x2e5a
jmp 0x2e55
movq %rax, %rbx
jmp 0x2e66
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x33a6
leaq -0xf8(%rbp), %rdi
callq 0x33ec
leaq -0x310(%rbp), %rdi
callq 0x2240
leaq -0x518(%rbp), %rdi
callq 0x2090
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x2ea2
callq 0x2190
movq %rbx, %rdi
callq 0x22a0