// File: 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
subq $0x620, %rsp            # imm = 0x620
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
je 0x2bae
movq 0xa45a(%rip), %rdi      # 0xcff0
leaq 0x5467(%rip), %rsi      # 0x8004
callq 0x21e0
movl $0x1, -0x4(%rbp)
jmp 0x332c
leaq -0x30(%rbp), %rdi
callq 0x2260
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x238(%rbp), %rdi
movl $0x8, %edx
callq 0x2330
jmp 0x2bd2
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x448(%rbp), %rdi
movl $0x10, %edx
callq 0x2230
jmp 0x2bed
leaq -0x478(%rbp), %rdi
callq 0x3610
leaq -0x238(%rbp), %rdi
callq 0x22f0
movb %al, -0x581(%rbp)
jmp 0x2c0d
movb -0x581(%rbp), %al
testb $0x1, %al
jne 0x2c1c
jmp 0x304b
jmp 0x2c1e
leaq -0x238(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2060
movq %rax, -0x590(%rbp)
jmp 0x2c37
movq -0x590(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2240
movb %al, -0x591(%rbp)
jmp 0x2c55
movb -0x591(%rbp), %al
testb $0x1, %al
jne 0x2c64
jmp 0x303b
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x2350
movq %rax, -0x5a0(%rbp)
jmp 0x2c7a
movq -0x5a0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0x3036
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x2350
movq %rax, -0x5a8(%rbp)
jmp 0x2ca3
movq -0x5a8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
je 0x3036
leaq -0x490(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x9, %edx
callq 0x25e0
jmp 0x2ccd
leaq -0x490(%rbp), %rdi
movl $0x3, %esi
callq 0x3630
movq %rax, -0x5b0(%rbp)
jmp 0x2ce7
movq -0x5b0(%rbp), %rdi
callq 0x22b0
movq %rax, -0x5c0(%rbp)
leaq -0x490(%rbp), %rdi
movl $0x4, %esi
callq 0x3630
movq %rax, -0x5b8(%rbp)
jmp 0x2d14
movq -0x5b8(%rbp), %rdi
callq 0x22b0
movq %rax, %rcx
movq -0x5c0(%rbp), %rax
cmpq %rcx, %rax
je 0x3017
leaq -0x490(%rbp), %rdi
movl $0x7, %esi
callq 0x3630
movq %rax, -0x5c8(%rbp)
jmp 0x2d4d
movq -0x5c8(%rbp), %rsi
leaq -0x4b0(%rbp), %rdi
callq 0x20c0
jmp 0x2d62
leaq -0x4d0(%rbp), %rdi
leaq -0x4b0(%rbp), %rsi
callq 0x20c0
jmp 0x2d77
leaq -0x490(%rbp), %rdi
movl $0x2, %esi
callq 0x3630
movq %rax, -0x5d0(%rbp)
jmp 0x2d91
movq -0x5d0(%rbp), %rsi
leaq -0x4f0(%rbp), %rdi
callq 0x20c0
jmp 0x2da6
leaq -0x478(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
callq 0x3670
movq %rax, -0x5d8(%rbp)
jmp 0x2dc2
movq -0x5d8(%rbp), %rax
cmpq $0x0, %rax
jbe 0x2f98
leaq -0x478(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
callq 0x36d0
movq %rax, -0x5e0(%rbp)
jmp 0x2def
movq -0x5e0(%rbp), %rsi
leaq -0x508(%rbp), %rdi
callq 0x3770
jmp 0x2e04
leaq -0x508(%rbp), %rdi
movq %rdi, -0x5f0(%rbp)
callq 0x38b0
movq -0x5f0(%rbp), %rdi
movq %rax, -0x518(%rbp)
callq 0x38e0
movq %rax, -0x520(%rbp)
movq -0x518(%rbp), %rdi
movq -0x520(%rbp), %rsi
leaq -0x4f0(%rbp), %rdx
callq 0x3860
movq %rax, -0x5e8(%rbp)
jmp 0x2e54
movq -0x5e8(%rbp), %rax
movq %rax, -0x510(%rbp)
leaq -0x508(%rbp), %rdi
callq 0x38e0
movq %rax, -0x528(%rbp)
leaq -0x510(%rbp), %rdi
leaq -0x528(%rbp), %rsi
callq 0x3830
xorb $-0x1, %al
testb $0x1, %al
jne 0x2e93
jmp 0x2f8a
leaq -0x478(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
callq 0x3910
movq %rax, -0x5f8(%rbp)
jmp 0x2eaf
movq -0x5f8(%rbp), %rdi
leaq -0x4f0(%rbp), %rsi
callq 0x39f0
jmp 0x2ec4
jmp 0x2f8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x3321
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x3315
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x32fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x3025
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x3009
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x2ffd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x2ff1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x508(%rbp), %rdi
callq 0x3a30
jmp 0x2ff1
leaq -0x508(%rbp), %rdi
callq 0x3a30
jmp 0x2fcb
leaq -0x478(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
callq 0x3910
movq %rax, -0x600(%rbp)
jmp 0x2fb4
movq -0x600(%rbp), %rdi
leaq -0x4f0(%rbp), %rsi
callq 0x39f0
jmp 0x2fc9
jmp 0x2fcb
leaq -0x4f0(%rbp), %rdi
callq 0x2130
leaq -0x4d0(%rbp), %rdi
callq 0x2130
leaq -0x4b0(%rbp), %rdi
callq 0x2130
jmp 0x3017
leaq -0x4f0(%rbp), %rdi
callq 0x2130
leaq -0x4d0(%rbp), %rdi
callq 0x2130
leaq -0x4b0(%rbp), %rdi
callq 0x2130
jmp 0x3025
leaq -0x490(%rbp), %rdi
callq 0x34f0
jmp 0x3036
leaq -0x490(%rbp), %rdi
callq 0x34f0
jmp 0x32fd
jmp 0x2c1e
leaq -0x238(%rbp), %rdi
callq 0x2070
jmp 0x3049
jmp 0x3076
movq 0x9f9e(%rip), %rdi      # 0xcff0
leaq 0x4fff(%rip), %rsi      # 0x8058
callq 0x21e0
jmp 0x3060
movl $0x1, -0x4(%rbp)
movl $0x1, -0x52c(%rbp)
jmp 0x32ce
leaq -0x448(%rbp), %rdi
callq 0x2180
movb %al, -0x601(%rbp)
jmp 0x308a
movb -0x601(%rbp), %al
testb $0x1, %al
jne 0x3099
jmp 0x3295
leaq -0x478(%rbp), %rdi
callq 0x3a50
movq %rax, -0x538(%rbp)
leaq -0x478(%rbp), %rdi
callq 0x3ab0
movq %rax, -0x540(%rbp)
leaq -0x538(%rbp), %rdi
leaq -0x540(%rbp), %rsi
callq 0x3a80
testb $0x1, %al
jne 0x30db
jmp 0x3285
leaq -0x538(%rbp), %rdi
callq 0x3ae0
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x558(%rbp), %rdi
callq 0x3770
jmp 0x30fc
leaq -0x558(%rbp), %rdi
callq 0x3b00
cmpq $0x1, %rax
jbe 0x325f
movl $0x1, -0x55c(%rbp)
leaq -0x558(%rbp), %rdi
callq 0x3b30
jmp 0x312a
leaq 0x4f4a(%rip), %rsi      # 0x807b
leaq -0x448(%rbp), %rdi
callq 0x21e0
jmp 0x313f
leaq -0x558(%rbp), %rdi
callq 0x38b0
movq %rax, -0x568(%rbp)
leaq -0x558(%rbp), %rdi
callq 0x38e0
movq %rax, -0x570(%rbp)
leaq -0x568(%rbp), %rdi
leaq -0x570(%rbp), %rsi
callq 0x3830
testb $0x1, %al
jne 0x3181
jmp 0x322c
leaq -0x568(%rbp), %rdi
callq 0x3f30
movq %rax, %rsi
leaq -0x448(%rbp), %rdi
callq 0x21b0
jmp 0x319e
movslq -0x55c(%rbp), %rax
movq %rax, -0x610(%rbp)
leaq -0x558(%rbp), %rdi
callq 0x3b00
movq %rax, %rcx
movq -0x610(%rbp), %rax
cmpq %rcx, %rax
jae 0x3201
leaq 0x4eaf(%rip), %rsi      # 0x807d
leaq -0x448(%rbp), %rdi
callq 0x21e0
jmp 0x31dc
jmp 0x3201
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x558(%rbp), %rdi
callq 0x3a30
jmp 0x32fd
jmp 0x3203
leaq -0x568(%rbp), %rdi
xorl %esi, %esi
callq 0x3f50
movq %rax, -0x578(%rbp)
movl -0x55c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x55c(%rbp)
jmp 0x3152
leaq 0x4e4d(%rip), %rsi      # 0x8080
leaq -0x448(%rbp), %rdi
callq 0x21e0
movq %rax, -0x618(%rbp)
jmp 0x3248
movq -0x618(%rbp), %rdi
movq 0x9d72(%rip), %rsi      # 0xcfc8
callq 0x2220
jmp 0x325d
jmp 0x325f
leaq -0x558(%rbp), %rdi
callq 0x3a30
leaq -0x538(%rbp), %rdi
xorl %esi, %esi
callq 0x3f80
movq %rax, -0x580(%rbp)
jmp 0x30ac
leaq -0x448(%rbp), %rdi
callq 0x2270
jmp 0x3293
jmp 0x32bd
movq 0x9d54(%rip), %rdi      # 0xcff0
leaq 0x4ddf(%rip), %rsi      # 0x8082
callq 0x21e0
jmp 0x32aa
movl $0x1, -0x4(%rbp)
movl $0x1, -0x52c(%rbp)
jmp 0x32ce
movl $0x0, -0x4(%rbp)
movl $0x1, -0x52c(%rbp)
leaq -0x478(%rbp), %rdi
callq 0x3fc0
leaq -0x448(%rbp), %rdi
callq 0x22a0
leaq -0x238(%rbp), %rdi
callq 0x2080
leaq -0x30(%rbp), %rdi
callq 0x2130
jmp 0x332c
leaq -0x478(%rbp), %rdi
callq 0x3fc0
leaq -0x448(%rbp), %rdi
callq 0x22a0
leaq -0x238(%rbp), %rdi
callq 0x2080
leaq -0x30(%rbp), %rdi
callq 0x2130
jmp 0x3338
movl -0x4(%rbp), %eax
addq $0x620, %rsp            # imm = 0x620
popq %rbp
retq
movq -0x240(%rbp), %rdi
callq 0x2310
nopw %cs:(%rax,%rax)
nop