// File: /workspace/github_cpp_makefile_star2_O2/WeichenZhou[P]PALMER/./scp/4_blastn.cpp
// Function: blastn(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int blastn(string WD_dir, string t, string direc){
    
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    
    //cout<<"Blastn Step is now running."<<endl;
    
    string sys_blast = WD_dir+"SEQ.masked";
    char *syst_blast =  new char[sys_blast.length()+1];
    strcpy(syst_blast, sys_blast.c_str());
    
    ifstream file1;
    file1.open(syst_blast);
    
    if (!file1.is_open())
    {
        cout <<"CANNOT OPEN FILE, 'SEQ.masked'"<< endl;
        //exit(1);
        return 0;
    }
    string sys_blastn;
    
    /*
    string sys_blastnrefine = WD_dir+"blastn_refine.txt";
    char *syst_blastnrefine =  new char[sys_blastnrefine.length()+1];
    strcpy(syst_blastnrefine, sys_blastnrefine.c_str());
    
    ofstream file2;
    file2.open(syst_blastnrefine);
    
    if(t=="LINE"){
         sys_blastn = "blastn -evalue 0.001 -task blastn -gapopen 4 -query "+direc+"/lib/L1.3.fasta -subject "+WD_dir+"SEQ.masked -outfmt \"7 qacc sacc evalue qstart qend sstart send\" |grep -v \"#\" >  "+WD_dir+"blastn_refine.txt";
    }
    else if(t=="ALU"){
        sys_blastn = "blastn -evalue 0.001 -task blastn -gapopen 4 -query "+direc+"/lib/AluY.fasta -subject "+WD_dir+"SEQ.masked -outfmt \"7 qacc sacc evalue qstart qend sstart send\" |grep -v \"#\" >  "+WD_dir+"blastn_refine.txt";
    }
    else if(t=="SVA"){
        sys_blastn = "blastn -evalue 0.001 -task blastn -gapopen 4 -query "+direc+"/lib/SVA_F.fasta -subject "+WD_dir+"SEQ.masked -outfmt \"7 qacc sacc evalue qstart qend sstart send\" |grep -v \"#\" >  "+WD_dir+"blastn_refine.txt";
    }
    else {
        sys_blastn = "blastn -evalue 0.001 -task blastn -gapopen 4 -query "+t+" -subject "+WD_dir+"SEQ.masked -outfmt \"7 qacc sacc evalue qstart qend sstart send\" |grep -v \"#\" >  "+WD_dir+"blastn_refine.txt";
    }
     */
    
    if(t=="LINE"){
        sys_blastn = "blastn -evalue 0.001 -task blastn -gapopen 4 -query "+direc+"/lib/L1.3.fasta -subject "+WD_dir+"SEQ.masked -outfmt \"7 qacc sacc evalue qstart qend sstart send\" >  "+WD_dir+"blastn.txt";
    }
    else if(t=="ALU"){
        sys_blastn = "blastn -evalue 0.001 -task blastn -gapopen 4 -query "+direc+"/lib/AluY.fasta -subject "+WD_dir+"SEQ.masked -outfmt \"7 qacc sacc evalue qstart qend sstart send\" >  "+WD_dir+"blastn.txt";
    }
    else if(t=="SVA"){
        sys_blastn = "blastn -evalue 0.001 -task blastn -gapopen 4 -query "+direc+"/lib/SVA_F.fasta -subject "+WD_dir+"SEQ.masked -outfmt \"7 qacc sacc evalue qstart qend sstart send\" >  "+WD_dir+"blastn.txt";
    }
    else if(t=="HERVK"){
        sys_blastn = "blastn -evalue 0.001 -task blastn -gapopen 4 -query "+direc+"/lib/HERVK.fasta -subject "+WD_dir+"SEQ.masked -outfmt \"7 qacc sacc evalue qstart qend sstart send\" >  "+WD_dir+"blastn.txt";
    }
    else {
        sys_blastn = "blastn -evalue 0.001 -task blastn -gapopen 4 -query "+t+" -subject "+WD_dir+"SEQ.masked -outfmt \"7 qacc sacc evalue qstart qend sstart send\" >  "+WD_dir+"blastn.txt";
    }
    
    char *syst_blastn = new char[sys_blastn.length()+1];
    strcpy(syst_blastn, sys_blastn.c_str());
    //cout<<sys_blastn<<endl;
    system(syst_blastn);
    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x21ea9(%rip), %rdx     # 0x25096
leaq 0xe0(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x23b6b
movq 0x8(%r12), %rdi
incq %rdi
callq 0x2030
movq %rax, %r12
movq 0xe0(%rsp), %rsi
movq %rax, %rdi
callq 0x2210
leaq 0x100(%rsp), %rdi
callq 0x2250
leaq 0x100(%rsp), %rdi
pushq $0x8
popq %rdx
movq %r12, %rsi
callq 0x21a0
leaq 0x178(%rsp), %rdi
callq 0x2090
testb %al, %al
je 0x3304
leaq 0xd0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x21e8c(%rip), %rsi     # 0x250fc
movq %r15, %rdi
callq 0x23ba3
testb %al, %al
je 0x3324
leaq 0x21e7a(%rip), %rsi     # 0x25101
movq %rsp, %rdi
movq %r14, %rdx
callq 0x23af5
leaq 0x21e9d(%rip), %rdx     # 0x25136
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x23ab7
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x23ad6
leaq 0x21e91(%rip), %rdx     # 0x25150
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x23ab7
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq %rbx, %rdx
callq 0x23ad6
leaq 0x22246(%rip), %rdx     # 0x25530
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x23ab7
jmp 0x3571
movq 0x29cc5(%rip), %rdi     # 0x2cfd0
leaq 0x21dcb(%rip), %rsi     # 0x250dd
callq 0x2230
movq %rax, %rdi
callq 0x2150
jmp 0x35fc
leaq 0x21e69(%rip), %rsi     # 0x25194
movq %r15, %rdi
callq 0x23ba3
testb %al, %al
je 0x33bf
leaq 0x21dbf(%rip), %rsi     # 0x25101
movq %rsp, %rdi
movq %r14, %rdx
callq 0x23af5
leaq 0x21e44(%rip), %rdx     # 0x25198
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x23ab7
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x23ad6
leaq 0x21dd6(%rip), %rdx     # 0x25150
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x23ab7
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq %rbx, %rdx
callq 0x23ad6
leaq 0x2218b(%rip), %rdx     # 0x25530
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x23ab7
jmp 0x3571
leaq 0x21dec(%rip), %rsi     # 0x251b2
movq %r15, %rdi
callq 0x23ba3
testb %al, %al
je 0x345a
leaq 0x21d24(%rip), %rsi     # 0x25101
movq %rsp, %rdi
movq %r14, %rdx
callq 0x23af5
leaq 0x21dc7(%rip), %rdx     # 0x251b6
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x23ab7
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x23ad6
leaq 0x21d3b(%rip), %rdx     # 0x25150
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x23ab7
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq %rbx, %rdx
callq 0x23ad6
leaq 0x220f0(%rip), %rdx     # 0x25530
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x23ab7
jmp 0x3571
leaq 0x22668(%rip), %rsi     # 0x25ac9
movq %r15, %rdi
callq 0x23ba3
testb %al, %al
je 0x34f2
leaq 0x21c89(%rip), %rsi     # 0x25101
movq %rsp, %rdi
movq %r14, %rdx
callq 0x23af5
leaq 0x21d47(%rip), %rdx     # 0x251d1
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x23ab7
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x23ad6
leaq 0x21ca0(%rip), %rdx     # 0x25150
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x23ab7
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq %rbx, %rdx
callq 0x23ad6
leaq 0x22055(%rip), %rdx     # 0x25530
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x23ab7
jmp 0x3571
leaq 0x21c08(%rip), %rsi     # 0x25101
movq %rsp, %rdi
movq %r15, %rdx
callq 0x23af5
leaq 0x220e3(%rip), %rdx     # 0x255ee
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x23ab7
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x23ad6
leaq 0x21c1f(%rip), %rdx     # 0x25150
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x23ab7
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq %rbx, %rdx
callq 0x23ad6
leaq 0x21fd4(%rip), %rdx     # 0x25530
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x23ab7
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rbx
movq %rbx, %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x2130
leaq 0x80(%rsp), %rdi
callq 0x2130
leaq 0x60(%rsp), %rdi
callq 0x2130
leaq 0x40(%rsp), %rdi
callq 0x2130
leaq 0x20(%rsp), %rdi
callq 0x2130
movq %rsp, %rdi
callq 0x2130
movq 0xc8(%rsp), %rdi
incq %rdi
callq 0x2030
movq %rax, %rbx
movq 0xc0(%rsp), %rsi
movq %rax, %rdi
callq 0x2210
movq %rbx, %rdi
callq 0x21e0
leaq 0xc0(%rsp), %rdi
callq 0x2130
leaq 0x100(%rsp), %rdi
callq 0x20a0
leaq 0xe0(%rsp), %rdi
callq 0x2130
xorl %eax, %eax
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x3657
jmp 0x3657
jmp 0x3669
jmp 0x3669
jmp 0x3678
jmp 0x3678
jmp 0x3687
jmp 0x3687
jmp 0x3696
jmp 0x3696
jmp 0x36a5
jmp 0x36a5
jmp 0x3657
jmp 0x3669
jmp 0x3678
jmp 0x3687
jmp 0x3696
jmp 0x36a5
jmp 0x3657
jmp 0x3669
jmp 0x3678
jmp 0x3687
jmp 0x3696
jmp 0x36a5
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x2130
jmp 0x366c
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x2130
jmp 0x367b
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x2130
jmp 0x368a
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2130
jmp 0x3699
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2130
jmp 0x36a8
jmp 0x36a5
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x2130
jmp 0x36c1
jmp 0x36b9
movq %rax, %rbx
jmp 0x36ce
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x20a0
leaq 0xe0(%rsp), %rdi
callq 0x2130
movq %rbx, %rdi
callq 0x23c0