// File: /workspace/github_cpp_makefile_star2_O1/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 0x2b9c
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 0x2bbe
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 0x2bcf
movq -0xb8(%rbp), %rdx
testq %rdx, %rdx
je 0x2d92
movq -0xc0(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xa, %eax
je 0x2937
cmpl $0x23, %eax
je 0x2937
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 0x2da9
cmpq $0x80, %rcx
je 0x2da2
movq 0x68(%rax), %rcx
cmpq 0x88(%rax), %rcx
je 0x2b8b
cmpq $0x7, %rdx
jbe 0x2dcf
leaq -0x38(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movq 0xe0(%rax), %rsi
movq 0xe8(%rax), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x3492
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x3492
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq $0x2, %rdx
jbe 0x2dbc
leaq -0x78(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %rdi
callq 0x3492
leaq -0xf8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x381a
cmpq %r14, %rax
je 0x2b20
leaq -0xf8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2fea
movq %r13, %rdi
movq %rax, %rsi
callq 0x3060
movq -0x110(%rbp), %r12
leaq -0x88(%rbp), %rax
movq %rax, -0xc8(%rbp)
cmpq %r13, %r12
je 0x2adf
leaq -0xc8(%rbp), %rdi
movq %r12, %rsi
callq 0x3916
testb %al, %al
jne 0x2adf
movq (%r12), %r12
jmp 0x2ac1
cmpq %r13, %r12
jne 0x2b16
leaq -0xf8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x309c
movq %rax, %r12
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x38c8
movq %rax, %rdi
movq %r12, %rsi
callq 0x2050
incq 0x10(%r12)
movq %r13, %rdi
callq 0x33be
jmp 0x2b52
leaq -0xf8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x309c
movq %rax, %r12
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x38c8
movq %rax, %rdi
movq %r12, %rsi
callq 0x2050
incq 0x10(%r12)
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x2b67
callq 0x2190
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x2b79
callq 0x2190
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x2b8b
callq 0x2190
leaq -0xa0(%rbp), %rdi
callq 0x2f9c
jmp 0x2937
movq 0x344d(%rip), %rdi      # 0x5ff0
leaq 0x145a(%rip), %rsi      # 0x4004
movl $0x53, %edx
callq 0x2200
movl $0x1, %ebx
jmp 0x2d7e
movl $0x22, %edx
leaq 0x148e(%rip), %rsi      # 0x4058
jmp 0x2d07
leaq -0x518(%rbp), %rdi
callq 0x2070
leaq -0x2a0(%rbp), %rdi
callq 0x2080
testb %al, %al
leaq -0x48(%rbp), %r13
je 0x2cfb
movq -0xe0(%rbp), %r15
cmpq %r14, %r15
je 0x2ceb
leaq 0x1473(%rip), %r12      # 0x407d
leaq 0x40(%r15), %rsi
movq %r13, %rdi
callq 0x3060
cmpq $0x2, -0x38(%rbp)
jb 0x2ccf
movq %r13, %rdi
callq 0x3130
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x1443(%rip), %rsi      # 0x407b
callq 0x2200
movq %r13, %rax
movq -0x48(%rbp), %r13
cmpq %rax, %r13
je 0x2c85
movl $0x1, %r14d
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
movq %rbx, %rdi
callq 0x2200
cmpq %r14, -0x38(%rbp)
jbe 0x2c75
movl $0x2, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2200
incq %r14
movq (%r13), %r13
leaq -0x48(%rbp), %rax
cmpq %rax, %r13
jne 0x2c4f
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x13ec(%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 0x33be
movq %r15, %rdi
callq 0x2110
movq %rax, %r15
cmpq %r14, %rax
jne 0x2c0a
xorl %ebx, %ebx
leaq -0x310(%rbp), %rdi
callq 0x2210
jmp 0x2d18
movl $0x1a, %edx
leaq 0x137b(%rip), %rsi      # 0x4082
movl $0x1, %ebx
movq 0x32dd(%rip), %rdi      # 0x5ff0
callq 0x2200
leaq -0xf8(%rbp), %rdi
callq 0x3404
movq 0x32a5(%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 0x2d7e
callq 0x2190
movl %ebx, %eax
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1348(%rip), %rdi      # 0x40e1
xorl %esi, %esi
xorl %eax, %eax
callq 0x2250
movl $0x4, %esi
jmp 0x2dae
movl $0x3, %esi
leaq 0x1370(%rip), %rdi      # 0x4125
xorl %eax, %eax
callq 0x2250
leaq 0x1362(%rip), %rdi      # 0x4125
movl $0x2, %esi
xorl %eax, %eax
callq 0x2250
leaq 0x134f(%rip), %rdi      # 0x4125
movl $0x7, %esi
xorl %eax, %eax
callq 0x2250
movq %rax, %rbx
jmp 0x2e95
movq %rax, %rbx
jmp 0x2ea1
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x33be
jmp 0x2e18
movq %rax, %rbx
jmp 0x2e3f
jmp 0x2e57
jmp 0x2e0c
movq %rax, %rbx
jmp 0x2e2d
jmp 0x2e57
jmp 0x2e15
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x2e2d
callq 0x2190
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x2e3f
callq 0x2190
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x2e5a
callq 0x2190
jmp 0x2e5a
jmp 0x2e6c
jmp 0x2e6c
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x2f9c
jmp 0x2e7d
jmp 0x2e71
jmp 0x2e6c
movq %rax, %rbx
jmp 0x2e7d
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x33be
leaq -0xf8(%rbp), %rdi
callq 0x3404
leaq -0x310(%rbp), %rdi
callq 0x2240
leaq -0x518(%rbp), %rdi
callq 0x2090
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x2eb9
callq 0x2190
movq %rbx, %rdi
callq 0x22a0
nop