// File: 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:
subq $0x6a8, %rsp            # imm = 0x6A8
movq %rsi, %rax
movq %rdi, %rsi
movq %rsi, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movq %rsi, 0x698(%rsp)
movq %rax, 0x690(%rsp)
movq %rdx, 0x688(%rsp)
leaq 0x3ef8b(%rip), %rdx     # 0x44086
leaq 0x668(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x42680
movq 0x48(%rsp), %rdi
callq 0x33c0
movq %rax, %rdi
incq %rdi
callq 0x3030
movq %rax, 0x50(%rsp)
jmp 0x5129
movq 0x50(%rsp), %rax
movq %rax, 0x660(%rsp)
movq 0x660(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x668(%rsp), %rdi
callq 0x3110
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x3250
leaq 0x448(%rsp), %rdi
callq 0x32c0
jmp 0x516c
movq 0x660(%rsp), %rsi
leaq 0x448(%rsp), %rdi
movl $0x8, %edx
callq 0x31c0
jmp 0x5188
leaq 0x448(%rsp), %rdi
callq 0x3400
movb %al, 0x27(%rsp)
jmp 0x519b
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x521f
jmp 0x51a5
movq 0x44e24(%rip), %rdi     # 0x49fd0
leaq 0x3ef1a(%rip), %rsi     # 0x440cd
callq 0x3280
movq %rax, 0x18(%rsp)
jmp 0x51bf
movq 0x18(%rsp), %rdi
movq 0x44df5(%rip), %rsi     # 0x49fc0
callq 0x32a0
jmp 0x51d2
movl $0x0, 0x6a4(%rsp)
movl $0x1, 0x444(%rsp)
jmp 0x5c4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x5c82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x5c75
leaq 0x420(%rsp), %rdi
callq 0x3370
movq 0x38(%rsp), %rdi
leaq 0x3eeb4(%rip), %rsi     # 0x440ec
callq 0x42710
movb %al, 0x17(%rsp)
jmp 0x5243
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x5250
jmp 0x5433
movq 0x40(%rsp), %rdx
leaq 0x3ee95(%rip), %rsi     # 0x440f1
leaq 0x360(%rsp), %rdi
callq 0x42550
jmp 0x526b
leaq 0x3eeb4(%rip), %rdx     # 0x44126
leaq 0x380(%rsp), %rdi
leaq 0x360(%rsp), %rsi
callq 0x424b0
jmp 0x5289
movq 0x30(%rsp), %rdx
leaq 0x3a0(%rsp), %rdi
leaq 0x380(%rsp), %rsi
callq 0x42500
jmp 0x52a5
leaq 0x3ee94(%rip), %rdx     # 0x44140
leaq 0x3c0(%rsp), %rdi
leaq 0x3a0(%rsp), %rsi
callq 0x424b0
jmp 0x52c3
movq 0x30(%rsp), %rdx
leaq 0x3e0(%rsp), %rdi
leaq 0x3c0(%rsp), %rsi
callq 0x42500
jmp 0x52df
leaq 0x3f23a(%rip), %rdx     # 0x44520
leaq 0x400(%rsp), %rdi
leaq 0x3e0(%rsp), %rsi
callq 0x424b0
jmp 0x52fd
leaq 0x420(%rsp), %rdi
leaq 0x400(%rsp), %rsi
callq 0x3300
leaq 0x400(%rsp), %rdi
callq 0x31b0
leaq 0x3e0(%rsp), %rdi
callq 0x31b0
leaq 0x3c0(%rsp), %rdi
callq 0x31b0
leaq 0x3a0(%rsp), %rdi
callq 0x31b0
leaq 0x380(%rsp), %rdi
callq 0x31b0
leaq 0x360(%rsp), %rdi
callq 0x31b0
jmp 0x5bc1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x5c3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x5421
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x5414
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x5407
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x53fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
leaq 0x3e0(%rsp), %rdi
callq 0x31b0
leaq 0x3c0(%rsp), %rdi
callq 0x31b0
leaq 0x3a0(%rsp), %rdi
callq 0x31b0
leaq 0x380(%rsp), %rdi
callq 0x31b0
leaq 0x360(%rsp), %rdi
callq 0x31b0
jmp 0x5c3d
movq 0x38(%rsp), %rdi
leaq 0x3ed45(%rip), %rsi     # 0x44184
callq 0x42710
movb %al, 0x16(%rsp)
jmp 0x544a
movb 0x16(%rsp), %al
testb $0x1, %al
jne 0x5457
jmp 0x5621
movq 0x40(%rsp), %rdx
leaq 0x3ec8e(%rip), %rsi     # 0x440f1
leaq 0x2a0(%rsp), %rdi
callq 0x42550
jmp 0x5472
leaq 0x3ed0f(%rip), %rdx     # 0x44188
leaq 0x2c0(%rsp), %rdi
leaq 0x2a0(%rsp), %rsi
callq 0x424b0
jmp 0x5490
movq 0x30(%rsp), %rdx
leaq 0x2e0(%rsp), %rdi
leaq 0x2c0(%rsp), %rsi
callq 0x42500
jmp 0x54ac
leaq 0x3ec8d(%rip), %rdx     # 0x44140
leaq 0x300(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
callq 0x424b0
jmp 0x54ca
movq 0x30(%rsp), %rdx
leaq 0x320(%rsp), %rdi
leaq 0x300(%rsp), %rsi
callq 0x42500
jmp 0x54e6
leaq 0x3f033(%rip), %rdx     # 0x44520
leaq 0x340(%rsp), %rdi
leaq 0x320(%rsp), %rsi
callq 0x424b0
jmp 0x5504
leaq 0x420(%rsp), %rdi
leaq 0x340(%rsp), %rsi
callq 0x3300
leaq 0x340(%rsp), %rdi
callq 0x31b0
leaq 0x320(%rsp), %rdi
callq 0x31b0
leaq 0x300(%rsp), %rdi
callq 0x31b0
leaq 0x2e0(%rsp), %rdi
callq 0x31b0
leaq 0x2c0(%rsp), %rdi
callq 0x31b0
leaq 0x2a0(%rsp), %rdi
callq 0x31b0
jmp 0x5bbf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x560f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x5602
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x55f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x55e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
leaq 0x320(%rsp), %rdi
callq 0x31b0
leaq 0x300(%rsp), %rdi
callq 0x31b0
leaq 0x2e0(%rsp), %rdi
callq 0x31b0
leaq 0x2c0(%rsp), %rdi
callq 0x31b0
leaq 0x2a0(%rsp), %rdi
callq 0x31b0
jmp 0x5c3d
movq 0x38(%rsp), %rdi
leaq 0x3eb75(%rip), %rsi     # 0x441a2
callq 0x42710
movb %al, 0x15(%rsp)
jmp 0x5638
movb 0x15(%rsp), %al
testb $0x1, %al
jne 0x5645
jmp 0x580f
movq 0x40(%rsp), %rdx
leaq 0x3eaa0(%rip), %rsi     # 0x440f1
leaq 0x1e0(%rsp), %rdi
callq 0x42550
jmp 0x5660
leaq 0x3eb3f(%rip), %rdx     # 0x441a6
leaq 0x200(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x424b0
jmp 0x567e
movq 0x30(%rsp), %rdx
leaq 0x220(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x42500
jmp 0x569a
leaq 0x3ea9f(%rip), %rdx     # 0x44140
leaq 0x240(%rsp), %rdi
leaq 0x220(%rsp), %rsi
callq 0x424b0
jmp 0x56b8
movq 0x30(%rsp), %rdx
leaq 0x260(%rsp), %rdi
leaq 0x240(%rsp), %rsi
callq 0x42500
jmp 0x56d4
leaq 0x3ee45(%rip), %rdx     # 0x44520
leaq 0x280(%rsp), %rdi
leaq 0x260(%rsp), %rsi
callq 0x424b0
jmp 0x56f2
leaq 0x420(%rsp), %rdi
leaq 0x280(%rsp), %rsi
callq 0x3300
leaq 0x280(%rsp), %rdi
callq 0x31b0
leaq 0x260(%rsp), %rdi
callq 0x31b0
leaq 0x240(%rsp), %rdi
callq 0x31b0
leaq 0x220(%rsp), %rdi
callq 0x31b0
leaq 0x200(%rsp), %rdi
callq 0x31b0
leaq 0x1e0(%rsp), %rdi
callq 0x31b0
jmp 0x5bbd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x57fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x57f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x57e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x57d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
leaq 0x260(%rsp), %rdi
callq 0x31b0
leaq 0x240(%rsp), %rdi
callq 0x31b0
leaq 0x220(%rsp), %rdi
callq 0x31b0
leaq 0x200(%rsp), %rdi
callq 0x31b0
leaq 0x1e0(%rsp), %rdi
callq 0x31b0
jmp 0x5c3d
movq 0x38(%rsp), %rdi
leaq 0x3f29e(%rip), %rsi     # 0x44ab9
callq 0x42710
movb %al, 0x14(%rsp)
jmp 0x5826
movb 0x14(%rsp), %al
testb $0x1, %al
jne 0x5833
jmp 0x59fd
movq 0x40(%rsp), %rdx
leaq 0x3e8b2(%rip), %rsi     # 0x440f1
leaq 0x120(%rsp), %rdi
callq 0x42550
jmp 0x584e
leaq 0x3e96c(%rip), %rdx     # 0x441c1
leaq 0x140(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x424b0
jmp 0x586c
movq 0x30(%rsp), %rdx
leaq 0x160(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x42500
jmp 0x5888
leaq 0x3e8b1(%rip), %rdx     # 0x44140
leaq 0x180(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x424b0
jmp 0x58a6
movq 0x30(%rsp), %rdx
leaq 0x1a0(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x42500
jmp 0x58c2
leaq 0x3ec57(%rip), %rdx     # 0x44520
leaq 0x1c0(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x424b0
jmp 0x58e0
leaq 0x420(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x3300
leaq 0x1c0(%rsp), %rdi
callq 0x31b0
leaq 0x1a0(%rsp), %rdi
callq 0x31b0
leaq 0x180(%rsp), %rdi
callq 0x31b0
leaq 0x160(%rsp), %rdi
callq 0x31b0
leaq 0x140(%rsp), %rdi
callq 0x31b0
leaq 0x120(%rsp), %rdi
callq 0x31b0
jmp 0x5bbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x59eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x59de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x59d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x59c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x31b0
leaq 0x180(%rsp), %rdi
callq 0x31b0
leaq 0x160(%rsp), %rdi
callq 0x31b0
leaq 0x140(%rsp), %rdi
callq 0x31b0
leaq 0x120(%rsp), %rdi
callq 0x31b0
jmp 0x5c3d
movq 0x38(%rsp), %rdx
leaq 0x3e6e8(%rip), %rsi     # 0x440f1
leaq 0x60(%rsp), %rdi
callq 0x42550
jmp 0x5a15
leaq 0x3ebc2(%rip), %rdx     # 0x445de
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x424b0
jmp 0x5a30
movq 0x30(%rsp), %rdx
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x42500
jmp 0x5a4c
leaq 0x3e6ed(%rip), %rdx     # 0x44140
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x424b0
jmp 0x5a6a
movq 0x30(%rsp), %rdx
leaq 0xe0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x42500
jmp 0x5a86
leaq 0x3ea93(%rip), %rdx     # 0x44520
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x424b0
jmp 0x5aa4
leaq 0x420(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x3300
leaq 0x100(%rsp), %rdi
callq 0x31b0
leaq 0xe0(%rsp), %rdi
callq 0x31b0
leaq 0xc0(%rsp), %rdi
callq 0x31b0
leaq 0xa0(%rsp), %rdi
callq 0x31b0
leaq 0x80(%rsp), %rdi
callq 0x31b0
leaq 0x60(%rsp), %rdi
callq 0x31b0
jmp 0x5bbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x5bac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x5b9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x5b92
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
jmp 0x5b85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x658(%rsp)
movl %eax, 0x654(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x31b0
leaq 0xc0(%rsp), %rdi
callq 0x31b0
leaq 0xa0(%rsp), %rdi
callq 0x31b0
leaq 0x80(%rsp), %rdi
callq 0x31b0
leaq 0x60(%rsp), %rdi
callq 0x31b0
jmp 0x5c3d
jmp 0x5bbd
jmp 0x5bbf
jmp 0x5bc1
leaq 0x420(%rsp), %rdi
callq 0x33c0
movq %rax, %rdi
incq %rdi
callq 0x3030
movq %rax, 0x8(%rsp)
jmp 0x5be0
movq 0x8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq %rax, (%rsp)
leaq 0x420(%rsp), %rdi
callq 0x3110
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x3250
movq 0x58(%rsp), %rdi
callq 0x3220
jmp 0x5c18
movl $0x0, 0x6a4(%rsp)
movl $0x1, 0x444(%rsp)
leaq 0x420(%rsp), %rdi
callq 0x31b0
jmp 0x5c4c
leaq 0x420(%rsp), %rdi
callq 0x31b0
jmp 0x5c75
leaq 0x448(%rsp), %rdi
callq 0x30a0
leaq 0x668(%rsp), %rdi
callq 0x31b0
movl 0x6a4(%rsp), %eax
addq $0x6a8, %rsp            # imm = 0x6A8
retq
leaq 0x448(%rsp), %rdi
callq 0x30a0
leaq 0x668(%rsp), %rdi
callq 0x31b0
movq 0x658(%rsp), %rdi
callq 0x3450
nopl (%rax)