// File: /workspace/github_cpp_makefile_star2_O2/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 $0x4e8, %rsp            # imm = 0x4E8
cmpl $0x3, %edi
jne 0x299c
movq %rsi, %rbx
leaq -0xe0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x8(%rsi), %rsi
leaq -0x510(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x22b0
movq 0x10(%rbx), %rsi
leaq -0x308(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x21d0
leaq -0xb0(%rbp), %r13
andl $0x0, (%r13)
andq $0x0, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
andq $0x0, 0x20(%r13)
leaq -0x498(%rbp), %rdi
callq 0x2080
testb %al, %al
je 0x29b7
leaq -0xf0(%rbp), %r15
leaq -0x108(%rbp), %r12
leaq -0x48(%rbp), %rbx
leaq -0x510(%rbp), %rdi
movq %r15, %rsi
callq 0x2060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x29c3
movq %r15, %rdi
xorl %esi, %esi
callq 0x22d0
cmpb $0x23, (%rax)
je 0x2823
movq %r15, %rdi
xorl %esi, %esi
callq 0x22d0
cmpb $0xa, (%rax)
je 0x2823
movq %r12, %rdi
movq %r15, %rsi
pushq $0x9
popq %rdx
callq 0x24e3
movq %r12, %rdi
pushq $0x3
popq %rsi
callq 0x2ca4
movq 0x8(%rax), %rbx
movq %r12, %rdi
pushq $0x4
popq %rsi
callq 0x2ca4
cmpq 0x8(%rax), %rbx
leaq -0x48(%rbp), %rbx
je 0x298f
movq %r12, %rdi
pushq $0x7
popq %rsi
callq 0x2ca4
movq %rbx, %rdi
movq %rax, %rsi
callq 0x21f0
leaq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x21f0
movq %r12, %rdi
pushq $0x2
popq %rsi
callq 0x2ca4
leaq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x21f0
leaq -0xb8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2cc6
testq %rax, %rax
je 0x2953
leaq -0xb8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2cea
leaq -0xd0(%rbp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x2d3a
movq -0xd0(%rbp), %rdi
movq %r14, %rsi
leaq -0x88(%rbp), %rdx
callq 0x35aa
cmpq %r14, %rax
jne 0x2945
leaq -0xb8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2d74
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x2dde
leaq -0xd0(%rbp), %rdi
callq 0x2fbc
jmp 0x2972
leaq -0xb8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2d74
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x2dde
leaq -0x88(%rbp), %rdi
callq 0x20e0
leaq -0x68(%rbp), %rdi
callq 0x20e0
movq %rbx, %rdi
callq 0x20e0
movq %r12, %rdi
callq 0x2c48
jmp 0x2823
movq 0x464d(%rip), %rdi      # 0x6ff0
leaq 0x165a(%rip), %rsi      # 0x4004
callq 0x2190
pushq $0x1
popq %rbx
jmp 0x2aee
leaq 0x169a(%rip), %rsi      # 0x4058
jmp 0x2a9f
leaq -0x510(%rbp), %rdi
callq 0x2070
leaq -0x298(%rbp), %rdi
callq 0x2080
testb %al, %al
je 0x2a98
movq -0xa0(%rbp), %r12
leaq -0x308(%rbp), %r15
leaq 0x1685(%rip), %r14      # 0x407d
cmpq %r13, %r12
je 0x2ab0
leaq 0x40(%r12), %rsi
movq %rbx, %rdi
callq 0x2d3a
cmpq $0x2, -0x38(%rbp)
jb 0x2a80
movq %rbx, %rdi
callq 0x2dee
movq %r15, %rdi
leaq 0x1654(%rip), %rsi      # 0x407b
callq 0x2190
pushq $0x1
popq %r13
movq (%rbx), %rbx
leaq -0x48(%rbp), %rax
cmpq %rax, %rbx
je 0x2a5e
leaq 0x10(%rbx), %rsi
movq %r15, %rdi
callq 0x2170
cmpq %r13, -0x38(%rbp)
jbe 0x2a59
movq %r15, %rdi
movq %r14, %rsi
callq 0x2190
incq %r13
jmp 0x2a30
movq %r15, %rdi
leaq 0x1618(%rip), %rsi      # 0x4080
callq 0x2190
leaq -0xb0(%rbp), %r13
leaq -0x48(%rbp), %rbx
movq %rax, %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2fbc
movq %r12, %rdi
callq 0x2120
movq %rax, %r12
jmp 0x29f8
leaq 0x15e3(%rip), %rsi      # 0x4082
movq 0x454a(%rip), %rdi      # 0x6ff0
callq 0x2190
pushq $0x1
popq %rbx
jmp 0x2abe
xorl %ebx, %ebx
leaq -0x308(%rbp), %rdi
callq 0x2200
leaq -0xb8(%rbp), %rdi
callq 0x2ff6
leaq -0x308(%rbp), %rdi
callq 0x2230
leaq -0x510(%rbp), %rdi
callq 0x2090
leaq -0xf0(%rbp), %rdi
callq 0x20e0
movl %ebx, %eax
addq $0x4e8, %rsp            # imm = 0x4E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2b14
movq %rax, %rbx
jmp 0x2b98
movq %rax, %rbx
jmp 0x2ba4
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x2fbc
jmp 0x2b31
jmp 0x2b6f
movq %rax, %rbx
jmp 0x2b4d
jmp 0x2b2e
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x20e0
jmp 0x2b44
jmp 0x2b5c
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x20e0
leaq -0x48(%rbp), %rdi
callq 0x20e0
jmp 0x2b5f
jmp 0x2b6f
jmp 0x2b6f
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
callq 0x2c48
jmp 0x2b80
jmp 0x2b74
movq %rax, %rbx
jmp 0x2b80
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x2fbc
leaq -0xb8(%rbp), %rdi
callq 0x2ff6
leaq -0x308(%rbp), %rdi
callq 0x2230
leaq -0x510(%rbp), %rdi
callq 0x2090
leaq -0xf0(%rbp), %rdi
callq 0x20e0
movq %rbx, %rdi
callq 0x2290