// File: WeichenZhou[P]PALMER/./scp/3_read_masker.cpp
// Function: ReadMasker(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 ReadMasker(string WD_dir, string mode){
    
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    
    ifstream file1;
    //ifstream file2;
    ifstream file3;
    ofstream file5;
    ofstream file6;
    ofstream file7;
    
    string sys_regionsam = WD_dir+"region.sam";
    char *syst_regionsam = new char[sys_regionsam.length()+1];
    strcpy(syst_regionsam, sys_regionsam.c_str());
    
    file1.open(syst_regionsam);
    
    /*
    string sys_RMselec = WD_dir+"RM.selected";
    char *syst_RMselec = new char[sys_RMselec.length()+1];
    strcpy(syst_RMselec, sys_RMselec.c_str());
    
    file2.open(syst_RMselec);
    */
    
    string sys_cigar2 = WD_dir+"cigar.2";
    char *syst_cigar2 = new char[sys_cigar2.length()+1];
    strcpy(syst_cigar2, sys_cigar2.c_str());
    
    file5.open(syst_cigar2);
    
    string sys_SEQ = WD_dir+"SEQ.masked";
    char *syst_SEQ = new char[sys_SEQ.length()+1];
    strcpy(syst_SEQ, sys_SEQ.c_str());
    
    file6.open(syst_SEQ);
    
    string sys_selecinfo = WD_dir+"selected.reads.info";
    char *syst_selecinfo = new char[sys_selecinfo.length()+1];
    strcpy(syst_selecinfo, sys_selecinfo.c_str());
    
    file7.open(syst_selecinfo);
    
    if (!file1.is_open())
    {
        cout <<"CANNOT OPEN FILE, 'region.sam'"<< endl;
        //exit(1);
        return 0;
    }
    
    string input;
    int input_int;
    
    int line=0;
    
    for(int i=0;!file1.eof();++i){
        getline(file1,input);
        line=i;
    }
    file1.close();
    file1.clear();
    file1.open(syst_regionsam);

    string **sam_info;
    sam_info=new string*[line];
    for(int i=0;i!=line;++i) sam_info[i]=new string[6];
    
    int **sam_loc;
    sam_loc=new int*[line];
    for(int i=0;i!=line;++i) sam_loc[i]=new int[5];
    
    for(int i=0;i!=line;++i){
        file1>>sam_info[i][0];        //QNAME
        //getline(file1,sam_info[i][0],'\t'); //QNAME
        file1>>sam_loc[i][0];         //FLAG
        file1>>sam_info[i][1];        //RNAME
        file1>>sam_loc[i][1];         //POS
        file1>>sam_loc[i][2];         //MAPQ
        file1>>sam_info[i][2];        //CIGAR
        file1>>sam_info[i][3];        //RNEXT
        file1>>sam_loc[i][3];         //PNEXT
        file1>>sam_loc[i][4];         //TLEN
        file1>>sam_info[i][4];        //SEQ
        getline(file1,sam_info[i][5]);//QUAL
        
    }
    
    /*
    int line_rm;
    int **rm_loc;
    string **rm_info;
    
    if (!file2.is_open()){
        line_rm=1;
        
        rm_loc=new int*[line_rm];
        for(int i=0;i!=line_rm;++i) rm_loc[i]=new int[2];
        
        rm_info=new string*[line_rm];
        for(int i=0;i!=line_rm;++i) rm_info[i]=new string[4];
        
        rm_info[0][0]="null";           //chr
        rm_loc[0][0]=0;            //start
        rm_loc[0][1]=0;            //end
        rm_info[0][1]="null";           //class
        rm_info[0][2]="null";           //family
        rm_info[0][3]="null";          //name
        
    }
    else {
        line_rm=0;
        for(int i=0;!file2.eof();++i){
            getline(file2,input);
            line_rm=i;
        }
        file2.close();
        file2.clear();
        file2.open(syst_RMselec);
        
        rm_loc=new int*[line_rm];
        for(int i=0;i!=line_rm;++i) rm_loc[i]=new int[2];
        
        rm_info=new string*[line_rm];
        for(int i=0;i!=line_rm;++i) rm_info[i]=new string[4];
        
        for(int i=0;i!=line_rm;++i){
            file2>>rm_info[i][0];           //chr
            file2>>rm_loc[i][0];            //start
            file2>>rm_loc[i][1];            //end
            file2>>rm_info[i][1];           //class
            file2>>rm_info[i][2];           //family
            file2>>rm_info[i][3];           //name
        }
    }
     */
    
//cout<<"region reading complete"<<endl;
    for(int i=0;i!=line;++i){
        //cout<<i<<endl;
        int number=0;
        int sc1, sc2, I, M, D, F, h1, h2, eq;
        sc1=sc2=I=M=D=F=h1=h2=eq=0;
        char cig;
        int read_s, read_e;
        read_s=sam_loc[i][1];
       
        string cigar1;
        cigar1=sam_info[i][2]+"0E";
        stringstream ss_cigar1;
        ss_cigar1.clear();
        ss_cigar1.str(cigar1);
        
//reads cigar&seq
        int le=sam_info[i][4].length();
        char *seq =new char[sam_info[i][4].length()+1];
        strcpy(seq,sam_info[i][4].c_str());
        
        /*
        int le=sam_info[i][4].length();
        char seq[le];
        char *cseq=sam_info[i][4].c_str();
        strcpy(seq,cseq);
        */
        ss_cigar1>>number;
        ss_cigar1>>cig;
        
        for(;!(cig=='E'&&number==0);){
            if(cig=='S'&&F==0) {sc1=sc1+number;F=1;}
            else if(cig=='H'&&F==0) h1=h1+number;
            else if (cig=='M') {M=M+number;F=1;}
            else if (cig=='='||cig=='X') {eq=eq+number;F=1;}
            else if (cig=='I') {I=I+number;F=1;}
            else if (cig=='D'||cig=='N') {D=D+number;F=1;}
            else if (cig=='S'&&F==1) sc2=sc2+number;
            else if (cig=='H'&&F==1) h2=h2+number;
            ss_cigar1>>number;
            ss_cigar1>>cig;
        }
        read_e=sam_loc[i][1]+M+D+eq-1;
        
        
        //if(sc1>=50||sc2>=50||I>=50){
            
//mask
            int start=0;
            int end=0;
            
            /*
            for(int j=0;j!=line_rm;++j){
                if(!((read_s>rm_loc[j][1])||(read_e<rm_loc[j][0]))){
                    
                    stringstream ss_cigar1;
                    ss_cigar1.clear();
                    ss_cigar1.str(cigar1);
                    
                    //file3.open(syst_cigar1);
                    if(read_s>rm_loc[j][0]) start=read_s;
                    else start= rm_loc[j][0];
                    if(read_e>rm_loc[j][1]) end=rm_loc[j][1];
                    else end=read_e;
                    
                    ss_cigar1>>number;
                    ss_cigar1>>cig;
                    int bit=read_s; //bit = reference location
                    int k=0;        //k = read seq location
                    
                    
                    for(;!(cig=='E'&&number==0);){
                        if(cig=='M'||cig=='='||cig=='X') {
                            bit=bit+number;
                            
                            if(bit>=start&&bit<=end&&(bit-number)>=start){
                                for(int x=0;x!=number;++x){
                                    seq[k+x]='N';
                                }
                            }
                            else if(bit>=start&&bit<=end&&(bit-number)<start){
                                for(int x=start-bit+number;x!=number;++x){
                                    seq[k+x]='N';
                                }
                            }
                            else if((bit-number)>=start&&(bit-number)<=end&&bit>end){
                                for(int x=0;x!=end-bit+number+1;++x){
                                    seq[k+x]='N';
                                }
                            }
                            else if((bit-number)<start&&bit>end){
                                for(int x=start-bit+number;x!=end-bit+number+1;++x){
                                    seq[k+x]='N';
                                }
                            }
                            k=k+number;
                        }
                        else if(cig=='D'||cig=='N') {bit=bit+number;
                        }
                        else if(cig=='S'||cig=='I') {k=k+number;
                        }
                        ss_cigar1>>number;
                        ss_cigar1>>cig;
                    }
                }
            }
            */
            
            stringstream ss_cigar2;
            ss_cigar2.clear();
            ss_cigar2.str(cigar1);
            
            //file3.open(syst_cigar1);
            start=read_s;
            end=read_e;
            
            ss_cigar2>>number;
            ss_cigar2>>cig;
            
            int bit_s=0;
            int k_s=0;
            for(;!(cig=='E'&&number==0);){
                /*if(cig=='S') {
                   
                    for(int x=0;x!=number;++x){
                        seq[k_s+x]='N';
                    }
                    
                    k_s=k_s+number;
                }
                
                ss_cigar1>>number;
                ss_cigar1>>cig;
                */
                
                if(cig=='M'||cig=='=') {
                    
                    for(int x=0;x!=number;++x){
                        seq[k_s+x]='N';
                    }
                    
                    bit_s=bit_s+number;
                    k_s=k_s+number;
                }
                else if(cig=='X') {
                    bit_s=bit_s+number;
                    k_s=k_s+number;
                }
                else if(cig=='D'||cig=='N') {bit_s=bit_s+number;
                }
                
                else if(cig=='I') {k_s=k_s+number;
                }
                
                else if(cig=='S'&&mode=="asm") {
                   
                    for(int x=0;x!=number;++x){
                        seq[k_s+x]='N';
                    }
                    
                    k_s=k_s+number;
                }
                
                else if(cig=='S'){
                    k_s=k_s+number;
                }
                
                ss_cigar2>>number;
                ss_cigar2>>cig;
                
            }
            
            
            
            
//output
            file5<<sam_info[i][2]<<"0E"<<'\t'<<i<<endl;
            file6<<">"<<sam_info[i][0]<<"_"<<sam_loc[i][1]<<"_"<<i<<endl;
            for(int x=0;x!=le;++x) file6<<seq[x];
            file6<<endl;
            file7<<sam_info[i][0]<<'\t'<<sam_info[i][1]<<'\t'<<sam_loc[i][1]<<'\t'<<le<<'\t'<<i<<endl;
        //}
        delete [] seq;
    }
    
    for(int i=0;i!=line;++i){
        delete [] sam_info[i];
        delete [] sam_loc[i];
    }
    delete [] sam_info;
    delete [] sam_loc;
    
    /*
    for(int i=0;i!=line_rm;++i){
        delete [] rm_info[i];
        delete [] rm_loc[i];
    }
    delete [] rm_info;
    delete [] rm_loc;
    */
    return 0;
}

// Assembly:
subq $0x1088, %rsp           # imm = 0x1088
movq %rdi, 0x190(%rsp)
movq %rsi, 0x198(%rsp)
movq %rdi, 0x1078(%rsp)
movq %rsi, 0x1070(%rsp)
leaq 0xe68(%rsp), %rdi
callq 0x32c0
leaq 0xc60(%rsp), %rdi
callq 0x32c0
jmp 0x3a93
leaq 0xa50(%rsp), %rdi
callq 0x3420
jmp 0x3aa2
leaq 0x850(%rsp), %rdi
callq 0x3420
jmp 0x3ab1
leaq 0x650(%rsp), %rdi
callq 0x3420
jmp 0x3ac0
movq 0x190(%rsp), %rsi
leaq 0x405a4(%rip), %rdx     # 0x44073
leaq 0x630(%rsp), %rdi
callq 0x42680
jmp 0x3ade
leaq 0x630(%rsp), %rdi
callq 0x33c0
movq %rax, %rdi
incq %rdi
callq 0x3030
movq %rax, 0x188(%rsp)
jmp 0x3b00
movq 0x188(%rsp), %rax
movq %rax, 0x628(%rsp)
movq 0x628(%rsp), %rax
movq %rax, 0x180(%rsp)
leaq 0x630(%rsp), %rdi
callq 0x3110
movq 0x180(%rsp), %rdi
movq %rax, %rsi
callq 0x3250
movq 0x628(%rsp), %rsi
leaq 0xe68(%rsp), %rdi
movl $0x8, %edx
callq 0x31c0
jmp 0x3b59
movq 0x190(%rsp), %rsi
leaq 0x40516(%rip), %rdx     # 0x4407e
leaq 0x608(%rsp), %rdi
callq 0x42680
jmp 0x3b77
leaq 0x608(%rsp), %rdi
callq 0x33c0
movq %rax, %rdi
incq %rdi
callq 0x3030
movq %rax, 0x178(%rsp)
jmp 0x3b99
movq 0x178(%rsp), %rax
movq %rax, 0x600(%rsp)
movq 0x600(%rsp), %rax
movq %rax, 0x170(%rsp)
leaq 0x608(%rsp), %rdi
callq 0x3110
movq 0x170(%rsp), %rdi
movq %rax, %rsi
callq 0x3250
movq 0x600(%rsp), %rsi
leaq 0xa50(%rsp), %rdi
movl $0x10, %edx
callq 0x3060
jmp 0x3bf2
movq 0x190(%rsp), %rsi
leaq 0x40485(%rip), %rdx     # 0x44086
leaq 0x5e0(%rsp), %rdi
callq 0x42680
jmp 0x3c10
leaq 0x5e0(%rsp), %rdi
callq 0x33c0
movq %rax, %rdi
incq %rdi
callq 0x3030
movq %rax, 0x168(%rsp)
jmp 0x3c32
movq 0x168(%rsp), %rax
movq %rax, 0x5d8(%rsp)
movq 0x5d8(%rsp), %rax
movq %rax, 0x160(%rsp)
leaq 0x5e0(%rsp), %rdi
callq 0x3110
movq 0x160(%rsp), %rdi
movq %rax, %rsi
callq 0x3250
movq 0x5d8(%rsp), %rsi
leaq 0x850(%rsp), %rdi
movl $0x10, %edx
callq 0x3060
jmp 0x3c8b
movq 0x190(%rsp), %rsi
leaq 0x403f7(%rip), %rdx     # 0x44091
leaq 0x5b8(%rsp), %rdi
callq 0x42680
jmp 0x3ca9
leaq 0x5b8(%rsp), %rdi
callq 0x33c0
movq %rax, %rdi
incq %rdi
callq 0x3030
movq %rax, 0x158(%rsp)
jmp 0x3ccb
movq 0x158(%rsp), %rax
movq %rax, 0x5b0(%rsp)
movq 0x5b0(%rsp), %rax
movq %rax, 0x150(%rsp)
leaq 0x5b8(%rsp), %rdi
callq 0x3110
movq 0x150(%rsp), %rdi
movq %rax, %rsi
callq 0x3250
movq 0x5b0(%rsp), %rsi
leaq 0x650(%rsp), %rdi
movl $0x10, %edx
callq 0x3060
jmp 0x3d24
leaq 0xe68(%rsp), %rdi
callq 0x3400
movb %al, 0x14f(%rsp)
jmp 0x3d3a
movb 0x14f(%rsp), %al
testb $0x1, %al
jne 0x3e7a
jmp 0x3d4b
movq 0x4627e(%rip), %rdi     # 0x49fd0
leaq 0x4034c(%rip), %rsi     # 0x440a5
callq 0x3280
movq %rax, 0x140(%rsp)
jmp 0x3d68
movq 0x140(%rsp), %rdi
movq 0x46249(%rip), %rsi     # 0x49fc0
callq 0x32a0
jmp 0x3d7e
movl $0x0, 0x1084(%rsp)
movl $0x1, 0x5ac(%rsp)
jmp 0x4fb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x509e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x5091
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x5084
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x5077
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x506a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x505d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x5050
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x5043
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x5036
leaq 0x588(%rsp), %rdi
callq 0x3370
movl $0x0, 0x580(%rsp)
movl $0x0, 0x57c(%rsp)
movq 0xe68(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0xe68(%rsp,%rax), %rdi
callq 0x3470
movb %al, 0x13f(%rsp)
jmp 0x3ebf
movb 0x13f(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3ece
jmp 0x3f1f
leaq 0xe68(%rsp), %rdi
leaq 0x588(%rsp), %rsi
callq 0x3080
jmp 0x3ee5
movl 0x57c(%rsp), %eax
movl %eax, 0x580(%rsp)
movl 0x57c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x57c(%rsp)
jmp 0x3e9d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x4fa0
leaq 0xe68(%rsp), %rdi
callq 0x3090
jmp 0x3f2e
movq 0xe68(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0xe68(%rsp,%rax), %rdi
xorl %esi, %esi
callq 0x3410
jmp 0x3f4b
movq 0x628(%rsp), %rsi
leaq 0xe68(%rsp), %rdi
movl $0x8, %edx
callq 0x31c0
jmp 0x3f67
movslq 0x580(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x3030
movq %rax, 0x130(%rsp)
jmp 0x3f94
movq 0x130(%rsp), %rax
movq %rax, 0x570(%rsp)
movl $0x0, 0x56c(%rsp)
movl 0x56c(%rsp), %eax
cmpl 0x580(%rsp), %eax
je 0x4074
movl $0xc8, %edi
callq 0x3030
movq %rax, 0x128(%rsp)
jmp 0x3fd7
movq 0x128(%rsp), %rax
movq $0x6, (%rax)
addq $0x8, %rax
movq %rax, 0x110(%rsp)
movq %rax, %rcx
addq $0xc0, %rcx
movq %rcx, 0x118(%rsp)
movq %rax, 0x120(%rsp)
movq 0x120(%rsp), %rdi
movq %rdi, 0x108(%rsp)
callq 0x3370
movq 0x108(%rsp), %rax
movq 0x118(%rsp), %rcx
addq $0x20, %rax
cmpq %rcx, %rax
movq %rax, 0x120(%rsp)
jne 0x400c
movq 0x110(%rsp), %rdx
movq 0x570(%rsp), %rax
movslq 0x56c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x56c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x56c(%rsp)
jmp 0x3faf
movslq 0x580(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x3030
movq %rax, 0x100(%rsp)
jmp 0x40a1
movq 0x100(%rsp), %rax
movq %rax, 0x560(%rsp)
movl $0x0, 0x55c(%rsp)
movl 0x55c(%rsp), %eax
cmpl 0x580(%rsp), %eax
je 0x410f
movl $0x14, %edi
callq 0x3030
movq %rax, 0xf8(%rsp)
jmp 0x40e0
movq 0xf8(%rsp), %rdx
movq 0x560(%rsp), %rax
movslq 0x55c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x55c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x55c(%rsp)
jmp 0x40bc
movl $0x0, 0x558(%rsp)
movl 0x558(%rsp), %eax
cmpl 0x580(%rsp), %eax
je 0x42ee
movq 0x570(%rsp), %rax
movslq 0x558(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xe68(%rsp), %rdi
callq 0x3310
jmp 0x4151
movq 0x560(%rsp), %rax
movslq 0x558(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xe68(%rsp), %rdi
callq 0x31a0
jmp 0x4174
movq 0x570(%rsp), %rax
movslq 0x558(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x20, %rsi
leaq 0xe68(%rsp), %rdi
callq 0x3310
jmp 0x419b
movq 0x560(%rsp), %rax
movslq 0x558(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x4, %rsi
leaq 0xe68(%rsp), %rdi
callq 0x31a0
jmp 0x41c2
movq 0x560(%rsp), %rax
movslq 0x558(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x8, %rsi
leaq 0xe68(%rsp), %rdi
callq 0x31a0
jmp 0x41e9
movq 0x570(%rsp), %rax
movslq 0x558(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x40, %rsi
leaq 0xe68(%rsp), %rdi
callq 0x3310
jmp 0x4210
movq 0x570(%rsp), %rax
movslq 0x558(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x60, %rsi
leaq 0xe68(%rsp), %rdi
callq 0x3310
jmp 0x4237
movq 0x560(%rsp), %rax
movslq 0x558(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0xc, %rsi
leaq 0xe68(%rsp), %rdi
callq 0x31a0
jmp 0x425e
movq 0x560(%rsp), %rax
movslq 0x558(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x10, %rsi
leaq 0xe68(%rsp), %rdi
callq 0x31a0
jmp 0x4285
movq 0x570(%rsp), %rax
movslq 0x558(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
subq $-0x80, %rsi
leaq 0xe68(%rsp), %rdi
callq 0x3310
jmp 0x42ac
movq 0x570(%rsp), %rax
movslq 0x558(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0xa0, %rsi
leaq 0xe68(%rsp), %rdi
callq 0x3080
jmp 0x42d6
jmp 0x42d8
movl 0x558(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x558(%rsp)
jmp 0x411a
movl $0x0, 0x554(%rsp)
movl 0x554(%rsp), %eax
cmpl 0x580(%rsp), %eax
je 0x4e6a
movl $0x0, 0x550(%rsp)
movl $0x0, 0x52c(%rsp)
movl $0x0, 0x530(%rsp)
movl $0x0, 0x534(%rsp)
movl $0x0, 0x538(%rsp)
movl $0x0, 0x53c(%rsp)
movl $0x0, 0x540(%rsp)
movl $0x0, 0x544(%rsp)
movl $0x0, 0x548(%rsp)
movl $0x0, 0x54c(%rsp)
movq 0x560(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %eax
movl %eax, 0x524(%rsp)
leaq 0x500(%rsp), %rdi
callq 0x3370
movq 0x570(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x40, %rsi
leaq 0x3fcff(%rip), %rdx     # 0x440c4
leaq 0x4e0(%rsp), %rdi
callq 0x42680
jmp 0x43d4
leaq 0x500(%rsp), %rdi
leaq 0x4e0(%rsp), %rsi
movq %rsi, 0xf0(%rsp)
callq 0x3300
movq 0xf0(%rsp), %rdi
callq 0x31b0
leaq 0x358(%rsp), %rdi
callq 0x31f0
jmp 0x440d
movq 0x358(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x358(%rsp,%rax), %rdi
xorl %esi, %esi
callq 0x3410
jmp 0x442a
leaq 0x358(%rsp), %rdi
leaq 0x500(%rsp), %rsi
callq 0x32d0
jmp 0x4441
movq 0x570(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
subq $-0x80, %rdi
callq 0x33c0
movl %eax, 0x354(%rsp)
movq 0x570(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
subq $-0x80, %rdi
callq 0x33c0
movq %rax, %rdi
incq %rdi
callq 0x3030
movq %rax, 0xe8(%rsp)
jmp 0x4497
movq 0xe8(%rsp), %rax
movq %rax, 0x348(%rsp)
movq 0x348(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x570(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
subq $-0x80, %rdi
callq 0x3110
movq 0xe0(%rsp), %rdi
movq %rax, %rsi
callq 0x3250
leaq 0x358(%rsp), %rdi
leaq 0x550(%rsp), %rsi
callq 0x31a0
jmp 0x44fb
leaq 0x358(%rsp), %rdi
leaq 0x52b(%rsp), %rsi
callq 0x3340
jmp 0x4512
jmp 0x4514
movsbl 0x52b(%rsp), %ecx
xorl %eax, %eax
cmpl $0x45, %ecx
movb %al, 0xdf(%rsp)
jne 0x453c
cmpl $0x0, 0x550(%rsp)
sete %al
movb %al, 0xdf(%rsp)
movb 0xdf(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x454e
jmp 0x4767
movsbl 0x52b(%rsp), %eax
cmpl $0x53, %eax
jne 0x45bc
cmpl $0x0, 0x538(%rsp)
jne 0x45bc
movl 0x54c(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x54c(%rsp)
movl $0x1, 0x538(%rsp)
jmp 0x4734
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x4e58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
jmp 0x4e4b
movsbl 0x52b(%rsp), %eax
cmpl $0x48, %eax
jne 0x45ed
cmpl $0x0, 0x538(%rsp)
jne 0x45ed
movl 0x534(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x534(%rsp)
jmp 0x4732
movsbl 0x52b(%rsp), %eax
cmpl $0x4d, %eax
jne 0x461f
movl 0x540(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x540(%rsp)
movl $0x1, 0x538(%rsp)
jmp 0x4730
movsbl 0x52b(%rsp), %eax
cmpl $0x3d, %eax
je 0x4639
movsbl 0x52b(%rsp), %eax
cmpl $0x58, %eax
jne 0x465e
movl 0x52c(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x52c(%rsp)
movl $0x1, 0x538(%rsp)
jmp 0x472e
movsbl 0x52b(%rsp), %eax
cmpl $0x49, %eax
jne 0x4690
movl 0x544(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x544(%rsp)
movl $0x1, 0x538(%rsp)
jmp 0x472c
movsbl 0x52b(%rsp), %eax
cmpl $0x44, %eax
je 0x46aa
movsbl 0x52b(%rsp), %eax
cmpl $0x4e, %eax
jne 0x46cc
movl 0x53c(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x53c(%rsp)
movl $0x1, 0x538(%rsp)
jmp 0x472a
movsbl 0x52b(%rsp), %eax
cmpl $0x53, %eax
jne 0x46fa
cmpl $0x1, 0x538(%rsp)
jne 0x46fa
movl 0x548(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x548(%rsp)
jmp 0x4728
movsbl 0x52b(%rsp), %eax
cmpl $0x48, %eax
jne 0x4726
cmpl $0x1, 0x538(%rsp)
jne 0x4726
movl 0x530(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x530(%rsp)
jmp 0x4728
jmp 0x472a
jmp 0x472c
jmp 0x472e
jmp 0x4730
jmp 0x4732
jmp 0x4734
leaq 0x358(%rsp), %rdi
leaq 0x550(%rsp), %rsi
callq 0x31a0
jmp 0x474b
leaq 0x358(%rsp), %rdi
leaq 0x52b(%rsp), %rsi
callq 0x3340
jmp 0x4762
jmp 0x4514
movq 0x560(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %edx
movl 0x540(%rsp), %eax
addl %eax, %edx
movl 0x53c(%rsp), %eax
addl %eax, %edx
movl 0x52c(%rsp), %ecx
movl %ecx, %eax
movl %edx, %ecx
leal -0x1(%rax,%rcx), %eax
movl %eax, 0x520(%rsp)
movl $0x0, 0x344(%rsp)
movl $0x0, 0x340(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x31f0
jmp 0x47cb
movq 0x1b8(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x1b8(%rsp,%rax), %rdi
xorl %esi, %esi
callq 0x3410
jmp 0x47e8
leaq 0x1b8(%rsp), %rdi
leaq 0x500(%rsp), %rsi
callq 0x32d0
jmp 0x47ff
movl 0x524(%rsp), %eax
movl %eax, 0x344(%rsp)
movl 0x520(%rsp), %eax
movl %eax, 0x340(%rsp)
leaq 0x1b8(%rsp), %rdi
leaq 0x550(%rsp), %rsi
callq 0x31a0
jmp 0x4832
leaq 0x1b8(%rsp), %rdi
leaq 0x52b(%rsp), %rsi
callq 0x3340
jmp 0x4849
movl $0x0, 0x1b4(%rsp)
movl $0x0, 0x1b0(%rsp)
movsbl 0x52b(%rsp), %ecx
xorl %eax, %eax
cmpl $0x45, %ecx
movb %al, 0xde(%rsp)
jne 0x4887
cmpl $0x0, 0x550(%rsp)
sete %al
movb %al, 0xde(%rsp)
movb 0xde(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x4899
jmp 0x4aea
movsbl 0x52b(%rsp), %eax
cmpl $0x4d, %eax
je 0x48b7
movsbl 0x52b(%rsp), %eax
cmpl $0x3d, %eax
jne 0x4957
movl $0x0, 0x1ac(%rsp)
movl 0x1ac(%rsp), %eax
cmpl 0x550(%rsp), %eax
je 0x4928
movq 0x348(%rsp), %rax
movl 0x1b0(%rsp), %ecx
addl 0x1ac(%rsp), %ecx
movslq %ecx, %rcx
movb $0x4e, (%rax,%rcx)
movl 0x1ac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1ac(%rsp)
jmp 0x48c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc58(%rsp)
movl %eax, 0xc54(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x3200
jmp 0x4e4b
movl 0x1b4(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x1b4(%rsp)
movl 0x1b0(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x1b0(%rsp)
jmp 0x4ab7
movsbl 0x52b(%rsp), %eax
cmpl $0x58, %eax
jne 0x4993
movl 0x1b4(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x1b4(%rsp)
movl 0x1b0(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x1b0(%rsp)
jmp 0x4ab5
movsbl 0x52b(%rsp), %eax
cmpl $0x44, %eax
je 0x49ad
movsbl 0x52b(%rsp), %eax
cmpl $0x4e, %eax
jne 0x49c7
movl 0x1b4(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x1b4(%rsp)
jmp 0x4ab3
movsbl 0x52b(%rsp), %eax
cmpl $0x49, %eax
jne 0x49ee
movl 0x1b0(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x1b0(%rsp)
jmp 0x4ab1
movsbl 0x52b(%rsp), %eax
cmpl $0x53, %eax
jne 0x4a8b
movq 0x198(%rsp), %rdi
leaq 0x3f6b9(%rip), %rsi     # 0x440c7
callq 0x42710
movb %al, 0xdd(%rsp)
jmp 0x4a1c
movb 0xdd(%rsp), %al
testb $0x1, %al
jne 0x4a29
jmp 0x4a8b
movl $0x0, 0x1a8(%rsp)
movl 0x1a8(%rsp), %eax
cmpl 0x550(%rsp), %eax
je 0x4a74
movq 0x348(%rsp), %rax
movl 0x1b0(%rsp), %ecx
addl 0x1a8(%rsp), %ecx
movslq %ecx, %rcx
movb $0x4e, (%rax,%rcx)
movl 0x1a8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a8(%rsp)
jmp 0x4a34
movl 0x1b0(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x1b0(%rsp)
jmp 0x4aaf
movsbl 0x52b(%rsp), %eax
cmpl $0x53, %eax
jne 0x4aad
movl 0x1b0(%rsp), %eax
addl 0x550(%rsp), %eax
movl %eax, 0x1b0(%rsp)
jmp 0x4aaf
jmp 0x4ab1
jmp 0x4ab3
jmp 0x4ab5
jmp 0x4ab7
leaq 0x1b8(%rsp), %rdi
leaq 0x550(%rsp), %rsi
callq 0x31a0
jmp 0x4ace
leaq 0x1b8(%rsp), %rdi
leaq 0x52b(%rsp), %rsi
callq 0x3340
jmp 0x4ae5
jmp 0x485f
movq 0x570(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x40, %rsi
leaq 0xa50(%rsp), %rdi
callq 0x3240
movq %rax, 0xd0(%rsp)
jmp 0x4b19
movq 0xd0(%rsp), %rdi
leaq 0x3f59c(%rip), %rsi     # 0x440c4
callq 0x3280
movq %rax, 0xc8(%rsp)
jmp 0x4b37
movq 0xc8(%rsp), %rdi
movl $0x9, %esi
callq 0x32e0
movq %rax, 0xc0(%rsp)
jmp 0x4b53
movq 0xc0(%rsp), %rdi
movl 0x554(%rsp), %esi
callq 0x3440
movq %rax, 0xb8(%rsp)
jmp 0x4b71
movq 0xb8(%rsp), %rdi
movq 0x45440(%rip), %rsi     # 0x49fc0
callq 0x32a0
jmp 0x4b87
leaq 0x40c61(%rip), %rsi     # 0x457ef
leaq 0x850(%rsp), %rdi
callq 0x3280
movq %rax, 0xb0(%rsp)
jmp 0x4ba5
movq 0xb0(%rsp), %rdi
movq 0x570(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x3240
movq %rax, 0xa8(%rsp)
jmp 0x4bd0
movq 0xa8(%rsp), %rdi
leaq 0x3f4ec(%rip), %rsi     # 0x440cb
callq 0x3280
movq %rax, 0xa0(%rsp)
jmp 0x4bee
movq 0xa0(%rsp), %rdi
movq 0x560(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %esi
callq 0x3440
movq %rax, 0x98(%rsp)
jmp 0x4c1c
movq 0x98(%rsp), %rdi
leaq 0x3f4a0(%rip), %rsi     # 0x440cb
callq 0x3280
movq %rax, 0x90(%rsp)
jmp 0x4c3a
movq 0x90(%rsp), %rdi
movl 0x554(%rsp), %esi
callq 0x3440
movq %rax, 0x88(%rsp)
jmp 0x4c58
movq 0x88(%rsp), %rdi
movq 0x45359(%rip), %rsi     # 0x49fc0
callq 0x32a0
jmp 0x4c6e
movl $0x0, 0x1a4(%rsp)
movl 0x1a4(%rsp), %eax
cmpl 0x354(%rsp), %eax
je 0x4cc1
movq 0x348(%rsp), %rax
movslq 0x1a4(%rsp), %rcx
movsbl (%rax,%rcx), %esi
leaq 0x850(%rsp), %rdi
callq 0x32e0
jmp 0x4cac
jmp 0x4cae
movl 0x1a4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a4(%rsp)
jmp 0x4c79
movq 0x452f8(%rip), %rsi     # 0x49fc0
leaq 0x850(%rsp), %rdi
callq 0x32a0
jmp 0x4cd7
movq 0x570(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x650(%rsp), %rdi
callq 0x3240
movq %rax, 0x80(%rsp)
jmp 0x4d02
movq 0x80(%rsp), %rdi
movl $0x9, %esi
callq 0x32e0
movq %rax, 0x78(%rsp)
jmp 0x4d1b
movq 0x78(%rsp), %rdi
movq 0x570(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x20, %rsi
callq 0x3240
movq %rax, 0x70(%rsp)
jmp 0x4d44
movq 0x70(%rsp), %rdi
movl $0x9, %esi
callq 0x32e0
movq %rax, 0x68(%rsp)
jmp 0x4d5a
movq 0x68(%rsp), %rdi
movq 0x560(%rsp), %rax
movslq 0x554(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %esi
callq 0x3440
movq %rax, 0x60(%rsp)
jmp 0x4d82
movq 0x60(%rsp), %rdi
movl $0x9, %esi
callq 0x32e0
movq %rax, 0x58(%rsp)
jmp 0x4d98
movq 0x58(%rsp), %rdi
movl 0x354(%rsp), %esi
callq 0x3440
movq %rax, 0x50(%rsp)
jmp 0x4db0
movq 0x50(%rsp), %rdi
movl $0x9, %esi
callq 0x32e0
movq %rax, 0x48(%rsp)
jmp 0x4dc6
movq 0x48(%rsp), %rdi
movl 0x554(%rsp), %esi
callq 0x3440
movq %rax, 0x40(%rsp)
jmp 0x4dde
movq 0x40(%rsp), %rdi
movq 0x451d6(%rip), %rsi     # 0x49fc0
callq 0x32a0
jmp 0x4df1
movq 0x348(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpq $0x0, %rax
je 0x4e0e
movq 0x38(%rsp), %rdi
callq 0x3320
leaq 0x1b8(%rsp), %rdi
callq 0x3200
leaq 0x358(%rsp), %rdi
callq 0x3200
leaq 0x500(%rsp), %rdi
callq 0x31b0
movl 0x554(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x554(%rsp)
jmp 0x42f9
leaq 0x358(%rsp), %rdi
callq 0x3200
leaq 0x500(%rsp), %rdi
callq 0x31b0
jmp 0x4fa0
movl $0x0, 0x1a0(%rsp)
movl 0x1a0(%rsp), %eax
cmpl 0x580(%rsp), %eax
je 0x4f43
movq 0x570(%rsp), %rax
movslq 0x1a0(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, %rax
je 0x4f02
movq 0x30(%rsp), %rcx
movq %rcx, %rax
addq $-0x8, %rax
movq %rax, 0x20(%rsp)
movq -0x8(%rcx), %rdx
shlq $0x5, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, 0x28(%rsp)
je 0x4ef8
movq 0x28(%rsp), %rdi
addq $-0x20, %rdi
movq %rdi, 0x18(%rsp)
callq 0x31b0
movq 0x30(%rsp), %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
movq %rax, 0x28(%rsp)
jne 0x4ed1
movq 0x20(%rsp), %rdi
callq 0x3320
movq 0x560(%rsp), %rax
movslq 0x1a0(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x4f2b
movq 0x10(%rsp), %rdi
callq 0x3320
jmp 0x4f2d
movl 0x1a0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a0(%rsp)
jmp 0x4e75
movq 0x570(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x4f60
movq 0x8(%rsp), %rdi
callq 0x3320
movq 0x560(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x4f7b
movq (%rsp), %rdi
callq 0x3320
movl $0x0, 0x1084(%rsp)
movl $0x1, 0x5ac(%rsp)
leaq 0x588(%rsp), %rdi
callq 0x31b0
jmp 0x4fb2
leaq 0x588(%rsp), %rdi
callq 0x31b0
jmp 0x5036
leaq 0x5b8(%rsp), %rdi
callq 0x31b0
leaq 0x5e0(%rsp), %rdi
callq 0x31b0
leaq 0x608(%rsp), %rdi
callq 0x31b0
leaq 0x630(%rsp), %rdi
callq 0x31b0
leaq 0x650(%rsp), %rdi
callq 0x33b0
leaq 0x850(%rsp), %rdi
callq 0x33b0
leaq 0xa50(%rsp), %rdi
callq 0x33b0
leaq 0xc60(%rsp), %rdi
callq 0x30a0
leaq 0xe68(%rsp), %rdi
callq 0x30a0
movl 0x1084(%rsp), %eax
addq $0x1088, %rsp           # imm = 0x1088
retq
leaq 0x5b8(%rsp), %rdi
callq 0x31b0
leaq 0x5e0(%rsp), %rdi
callq 0x31b0
leaq 0x608(%rsp), %rdi
callq 0x31b0
leaq 0x630(%rsp), %rdi
callq 0x31b0
leaq 0x650(%rsp), %rdi
callq 0x33b0
leaq 0x850(%rsp), %rdi
callq 0x33b0
leaq 0xa50(%rsp), %rdi
callq 0x33b0
leaq 0xc60(%rsp), %rdi
callq 0x30a0
leaq 0xe68(%rsp), %rdi
callq 0x30a0
movq 0xc58(%rsp), %rdi
callq 0x3450
nopl (%rax,%rax)