// File: schneebergerlab[P]DrLink/separate_kb_molecule.cpp
// Function: separate_kb_molecule(int, char**)
bool separate_kb_molecule(int argc, char* argv[])
{
    std::stringstream usage;
    usage.str("");
    if(argc < 5)
    {
        usage << endl;
        usage << "   Given sets of molecule info (from DrLink molecule), "                         
              << endl;
        usage << "   this function samples molecules according to intersection of molecule sizes and base coverage"           
              << endl;
        const char *buildString = __DATE__", " __TIME__;
        usage << "   (compiled on " << buildString << ")"                                                   
              << endl << endl;
        usage << "   Usage: DrLink separate_kb mole1.gz,mole2.gz[,...] label1,label2[,...] outprefix" 
              << endl << endl;
        usage << "\twhere "                                                         << endl;
        usage << "\tmole*.gz  :   molecule meta info corresponding to molecule size of pools from DrLink molecule"  
              << endl;
        usage << "\tlabel*    :   sample-specific label of output files"            << endl;
        usage << "\toutprefix :   general label of output files"                    << endl;
        cout  << usage.str() << endl;
        return false;
    }
    double startT   = clock(); 
    // get inputs
    vector<string> mfileinfo  = split_string((string)argv[2], ',');
    vector<string> mlabelinfo = split_string((string)argv[3], ',');
    if(mfileinfo.size() != mlabelinfo.size())
    {
        cout << "   Error: number of molecule files does not match number of labels. Exited." << endl;
        return false;
    }
    string outprefix = (string)argv[4];
    if(outprefix.size()==0)
    {
        outprefix = "Enjo";
    }
    //
    vector<string>::iterator mfitr;
    vector<string>::iterator mfitr_end;
    mfitr     = mfileinfo.begin();
    mfitr_end = mfileinfo.end();
    int i = -1;
    string molheader = "#chr#barcode\tfirst_aligned\tlast_aligned\tmolecule_len\tmolecule_cov\tread_num\tUni_flag\tlast_aligned_end\treads_region\tR1R2\treads_id";
    map<int, map<string,  unsigned long> > molecule_cov; // map<kb, map<0.01x,0.02x,..., number of molecules> >
    while(mfitr != mfitr_end)
    {
        i ++;
        string molfile  = *mfitr;        
        string mollabel = mlabelinfo[i];
        cout << "   Info: building statistics for " << mollabel << ":" << molfile << endl;
        unsigned long raw_mole_num      = 0;
        unsigned long selected_mole_num = 0;
        // create an intermediate folder for collecting details about a CO-molecule
        string molfolder = outprefix+"_"+mollabel;
        DIR* dir = opendir(molfolder.c_str());
        if (dir)
        {
            /* Directory exists. */
            closedir(dir);
        }
        else if (ENOENT == errno)
        {
            /* Directory does not exist. */
            const int dir_err = mkdir(molfolder.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
            if (dir_err == -1)
            {
                cout << "   Error: cannot create directory " << molfolder << endl;
                return false;
            }        
        }
        else ;
        // read raw molecule meta info file
        igzstream molfp;
        molfp.open(molfile.c_str());
        if(!molfp.good())
        {
            cout << "   Error: cannot open file of raw molecule: " << molfile << endl;
            return false;
        }
        while(molfp.good())
        {
            string line("");
            getline(molfp, line);
            if(line.size()==0 || line[0]=='#') continue;            
            vector<string> lineinfo = split_string(line, '\t');
            raw_mole_num ++;
            // molecule size
            int mlen = atoi(lineinfo[3].c_str());
            if(mlen < 1000) continue;
            int mlkey = (int)round((double)mlen/1000);
            map<int, map<string, unsigned long> >::iterator mlitr;
            mlitr = molecule_cov.find(mlkey); // to check if key exists
            if(mlitr == molecule_cov.end())
            {
                map<string, unsigned long> tmpcovmap;
                molecule_cov.insert(std::pair<int, map<string, unsigned long> >(mlkey, tmpcovmap) );
            }
            mlitr = molecule_cov.find(mlkey); // to update key: value
            // molecule cov
            string mckey = lineinfo[4];
            map<string, unsigned long>::iterator mcitr = ((*mlitr).second).find(mckey);
            if(mcitr == (*mlitr).second.end())
            {
                ((*mlitr).second).insert(std::pair<string, unsigned long>(mckey, 1));
            }
            else
            {
                (*mcitr).second += 1;
            }
            // output x.kb molecule to x.kb file
            std::stringstream kbmfile;
            kbmfile.str(""); 
            kbmfile << "./" << molfolder << "/" << mollabel << "_" << mlkey << "kb.txt";
            ofstream outkbfp;
            outkbfp.open(kbmfile.str().c_str(), ios::out | ios::app);
            if(!outkbfp.good())
            {
                cout   << "   Error: cannot open file " << kbmfile.str() << endl;
                return false;
            }
            else
            {
                outkbfp << line << endl;
                outkbfp.close();
                selected_mole_num ++;
            }
            //
            if(raw_mole_num%1000000 == 0)
            {
                cout << "   Info: " 
                     << raw_mole_num 
                     << " raw molecules, where " 
                     << selected_mole_num 
                     << " selected. " 
                     << endl;
            }
        }
        // output sample kb molecule base coverage
        map<int, map<string, unsigned long> >::iterator kbitr;
        map<int, map<string, unsigned long> >::iterator kbitr_end;
        kbitr     = molecule_cov.begin();
        kbitr_end = molecule_cov.end();
        while(kbitr != kbitr_end)
        {
            if(!write_molecule_kbcov((*kbitr).second, molfolder, mollabel, (*kbitr).first))
            {
                cout << "   Error: cannot write molecule cov for " << (*kbitr).first << " kb." << endl;
                return false;
            }
            kbitr ++;
        }
        // next sample
        mfitr ++;
    }
    //
    double finishT= clock();
    cout << "   Time consumed: " << (finishT-startT)/1000000 << " seconds" << endl << endl;    
    return true;
}

// Assembly:
subq $0xea8, %rsp            # imm = 0xEA8
movl %edi, 0xea0(%rsp)
movq %rsi, 0xe98(%rsp)
leaq 0xd10(%rsp), %rdi
callq 0x5320
leaq 0xcef(%rsp), %rdi
movq %rdi, 0x240(%rsp)
callq 0x57c0
movq 0x240(%rsp), %rdx
leaq 0xe1fd(%rip), %rsi      # 0x6ab94
leaq 0xcf0(%rsp), %rdi
callq 0x6880
jmp 0x5c9a6
leaq 0xd10(%rsp), %rdi
leaq 0xcf0(%rsp), %rsi
callq 0x5510
jmp 0x5c9bd
leaq 0xcf0(%rsp), %rdi
callq 0x58b8
leaq 0xcef(%rsp), %rdi
callq 0x54d0
cmpl $0x5, 0xea0(%rsp)
jge 0x5cd1b
leaq 0xd20(%rsp), %rdi
movq 0x285bc(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5c9fb
leaq 0xd20(%rsp), %rdi
leaq 0xe202(%rip), %rsi      # 0x6ac0c
callq 0x5460
movq %rax, 0x238(%rsp)
jmp 0x5ca19
movq 0x238(%rsp), %rdi
movq 0x28588(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5ca2f
leaq 0xd20(%rsp), %rdi
leaq 0xe206(%rip), %rsi      # 0x6ac44
callq 0x5460
movq %rax, 0x230(%rsp)
jmp 0x5ca4d
movq 0x230(%rsp), %rdi
movq 0x28554(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5ca63
leaq 0xe23b(%rip), %rax      # 0x6aca5
movq %rax, 0xcd0(%rsp)
leaq 0xd20(%rsp), %rdi
leaq 0xd2e1(%rip), %rsi      # 0x69d62
callq 0x5460
movq %rax, 0x228(%rsp)
jmp 0x5ca90
movq 0x228(%rsp), %rdi
movq 0xcd0(%rsp), %rsi
callq 0x5460
movq %rax, 0x220(%rsp)
jmp 0x5caaf
movq 0x220(%rsp), %rdi
leaq 0xd912(%rip), %rsi      # 0x6a3d0
callq 0x5460
movq %rax, 0x218(%rsp)
jmp 0x5cacd
movq 0x218(%rsp), %rdi
movq 0x284d4(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x210(%rsp)
jmp 0x5caeb
movq 0x210(%rsp), %rdi
movq 0x284b6(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5cb01
leaq 0xd20(%rsp), %rdi
leaq 0xe1ab(%rip), %rsi      # 0x6acbb
callq 0x5460
movq %rax, 0x208(%rsp)
jmp 0x5cb1f
movq 0x208(%rsp), %rdi
movq 0x28482(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x200(%rsp)
jmp 0x5cb3d
movq 0x200(%rsp), %rdi
movq 0x28464(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5cb53
leaq 0xd20(%rsp), %rdi
leaq 0xd262(%rip), %rsi      # 0x69dc4
callq 0x5460
movq %rax, 0x1f8(%rsp)
jmp 0x5cb71
movq 0x1f8(%rsp), %rdi
movq 0x28430(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5cb87
leaq 0xd20(%rsp), %rdi
leaq 0xd61c(%rip), %rsi      # 0x6a1b2
callq 0x5460
movq %rax, 0x1f0(%rsp)
jmp 0x5cba5
movq 0x1f0(%rsp), %rdi
movq 0x283fc(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5cbbb
leaq 0xd20(%rsp), %rdi
leaq 0xe144(%rip), %rsi      # 0x6ad0e
callq 0x5460
movq %rax, 0x1e8(%rsp)
jmp 0x5cbd9
movq 0x1e8(%rsp), %rdi
movq 0x283c8(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5cbef
leaq 0xd20(%rsp), %rdi
leaq 0xd67f(%rip), %rsi      # 0x6a27d
callq 0x5460
movq %rax, 0x1e0(%rsp)
jmp 0x5cc0d
movq 0x1e0(%rsp), %rdi
movq 0x28394(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5cc23
leaq 0xcb0(%rsp), %rdi
leaq 0xd10(%rsp), %rsi
callq 0x5440
jmp 0x5cc3a
movq 0x28387(%rip), %rdi     # 0x84fc8
leaq 0xcb0(%rsp), %rsi
callq 0x53e0
movq %rax, 0x1d8(%rsp)
jmp 0x5cc58
movq 0x1d8(%rsp), %rdi
movq 0x28349(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5cc6e
leaq 0xcb0(%rsp), %rdi
callq 0x58b8
movb $0x0, 0xea7(%rsp)
movl $0x1, 0xcac(%rsp)
jmp 0x5e312
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5ccca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0xcf0(%rsp), %rdi
callq 0x58b8
leaq 0xcef(%rsp), %rdi
callq 0x54d0
jmp 0x5e330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5e330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0xcb0(%rsp), %rdi
callq 0x58b8
jmp 0x5e330
callq 0x52e0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0xca0(%rsp)
movq 0xe98(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x1c8(%rsp)
leaq 0xc67(%rsp), %rdi
movq %rdi, 0x1d0(%rsp)
callq 0x57c0
movq 0x1c8(%rsp), %rsi
movq 0x1d0(%rsp), %rdx
leaq 0xc68(%rsp), %rdi
callq 0x6880
jmp 0x5cd76
movb $0x2c, 0xc66(%rsp)
leaq 0xc88(%rsp), %rdi
leaq 0xc68(%rsp), %rsi
leaq 0xc66(%rsp), %rdx
callq 0x60790
jmp 0x5cd9d
leaq 0xc68(%rsp), %rdi
callq 0x58b8
leaq 0xc67(%rsp), %rdi
callq 0x54d0
movq 0xe98(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x1b8(%rsp)
leaq 0xc27(%rsp), %rdi
movq %rdi, 0x1c0(%rsp)
callq 0x57c0
movq 0x1b8(%rsp), %rsi
movq 0x1c0(%rsp), %rdx
leaq 0xc28(%rsp), %rdi
callq 0x6880
jmp 0x5cdff
movb $0x2c, 0xc26(%rsp)
leaq 0xc48(%rsp), %rdi
leaq 0xc28(%rsp), %rsi
leaq 0xc26(%rsp), %rdx
callq 0x60790
jmp 0x5ce26
leaq 0xc28(%rsp), %rdi
callq 0x58b8
leaq 0xc27(%rsp), %rdi
callq 0x54d0
leaq 0xc88(%rsp), %rdi
callq 0xfbb0
movq %rax, 0x1b0(%rsp)
leaq 0xc48(%rsp), %rdi
callq 0xfbb0
movq %rax, %rcx
movq 0x1b0(%rsp), %rax
cmpq %rcx, %rax
je 0x5cf6c
movq 0x2814b(%rip), %rdi     # 0x84fc8
leaq 0xdebf(%rip), %rsi      # 0x6ad43
callq 0x5460
movq %rax, 0x1a8(%rsp)
jmp 0x5ce93
movq 0x1a8(%rsp), %rdi
movq 0x2810e(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5cea9
movb $0x0, 0xea7(%rsp)
movl $0x1, 0xcac(%rsp)
jmp 0x5e2da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5cef8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0xc68(%rsp), %rdi
callq 0x58b8
leaq 0xc67(%rsp), %rdi
callq 0x54d0
jmp 0x5e330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5cf41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0xc28(%rsp), %rdi
callq 0x58b8
leaq 0xc27(%rsp), %rdi
callq 0x54d0
jmp 0x5e303
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5e2f6
movq 0xe98(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x198(%rsp)
leaq 0xbff(%rsp), %rdi
movq %rdi, 0x1a0(%rsp)
callq 0x57c0
movq 0x198(%rsp), %rsi
movq 0x1a0(%rsp), %rdx
leaq 0xc00(%rsp), %rdi
callq 0x6880
jmp 0x5cfb4
leaq 0xbff(%rsp), %rdi
callq 0x54d0
leaq 0xc00(%rsp), %rdi
callq 0x5310
cmpq $0x0, %rax
jne 0x5d02b
leaq 0xddb4(%rip), %rsi      # 0x6ad8f
leaq 0xc00(%rsp), %rdi
callq 0x55d0
jmp 0x5cfea
jmp 0x5d02b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0xbff(%rsp), %rdi
callq 0x54d0
jmp 0x5e2f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5e2cb
leaq 0xbf0(%rsp), %rdi
callq 0x2de30
leaq 0xbe8(%rsp), %rdi
callq 0x2de30
leaq 0xc88(%rsp), %rdi
movq %rdi, 0x188(%rsp)
callq 0x2d110
movq 0x188(%rsp), %rdi
movq %rax, 0xbe0(%rsp)
movq 0xbe0(%rsp), %rax
movq %rax, 0xbf0(%rsp)
callq 0x2d140
movq %rax, 0xbd8(%rsp)
movq 0xbd8(%rsp), %rax
movq %rax, 0xbe8(%rsp)
movl $0xffffffff, 0xbd4(%rsp) # imm = 0xFFFFFFFF
leaq 0xbaf(%rsp), %rdi
movq %rdi, 0x190(%rsp)
callq 0x57c0
movq 0x190(%rsp), %rdx
leaq 0x9abb(%rip), %rsi      # 0x66b81
leaq 0xbb0(%rsp), %rdi
callq 0x6880
jmp 0x5d0d5
leaq 0xbaf(%rsp), %rdi
callq 0x54d0
leaq 0xb78(%rsp), %rdi
callq 0x51960
leaq 0xbf0(%rsp), %rdi
leaq 0xbe8(%rsp), %rsi
callq 0x2d170
testb $0x1, %al
jne 0x5d10d
jmp 0x5e1d2
movl 0xbd4(%rsp), %eax
incl %eax
movl %eax, 0xbd4(%rsp)
leaq 0xbf0(%rsp), %rdi
callq 0x2d1b0
movq %rax, %rsi
leaq 0xb58(%rsp), %rdi
callq 0x51f0
jmp 0x5d13c
movslq 0xbd4(%rsp), %rsi
leaq 0xc48(%rsp), %rdi
callq 0x88f0
movq %rax, %rsi
leaq 0xb38(%rsp), %rdi
callq 0x51f0
jmp 0x5d163
movq 0x27e5e(%rip), %rdi     # 0x84fc8
leaq 0xdc23(%rip), %rsi      # 0x6ad94
callq 0x5460
movq %rax, 0x180(%rsp)
jmp 0x5d180
movq 0x180(%rsp), %rdi
leaq 0xb38(%rsp), %rsi
callq 0x53e0
movq %rax, 0x178(%rsp)
jmp 0x5d19f
movq 0x178(%rsp), %rdi
leaq 0x944d(%rip), %rsi      # 0x665fb
callq 0x5460
movq %rax, 0x170(%rsp)
jmp 0x5d1bd
movq 0x170(%rsp), %rdi
leaq 0xb58(%rsp), %rsi
callq 0x53e0
movq %rax, 0x168(%rsp)
jmp 0x5d1dc
movq 0x168(%rsp), %rdi
movq 0x27dc5(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5d1f2
movq $0x0, 0xb30(%rsp)
movq $0x0, 0xb28(%rsp)
leaq 0xa886(%rip), %rdx      # 0x67a97
leaq 0xae8(%rsp), %rdi
leaq 0xc00(%rsp), %rsi
callq 0xfae0
jmp 0x5d228
leaq 0xb08(%rsp), %rdi
leaq 0xae8(%rsp), %rsi
leaq 0xb38(%rsp), %rdx
callq 0xfbf0
jmp 0x5d247
leaq 0xae8(%rsp), %rdi
callq 0x58b8
leaq 0xb08(%rsp), %rdi
callq 0x51d0
movq %rax, %rdi
callq 0x5680
movq %rax, 0x160(%rsp)
jmp 0x5d273
movq 0x160(%rsp), %rax
movq %rax, 0xae0(%rsp)
cmpq $0x0, 0xae0(%rsp)
je 0x5d356
movq 0xae0(%rsp), %rdi
callq 0x5700
jmp 0x5d2a1
jmp 0x5d406
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0xbaf(%rsp), %rdi
callq 0x54d0
jmp 0x5e2cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5e2b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5e1c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5e1b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0xae8(%rsp), %rdi
callq 0x58b8
jmp 0x5e1b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5e1a6
callq 0x5060
movq %rax, %rcx
movl $0x2, %eax
cmpl (%rcx), %eax
jne 0x5d402
leaq 0xb08(%rsp), %rdi
callq 0x51d0
movq %rax, %rdi
movl $0x1fd, %esi            # imm = 0x1FD
callq 0x5230
movl %eax, 0xadc(%rsp)
cmpl $-0x1, 0xadc(%rsp)
jne 0x5d400
movq 0x27c2b(%rip), %rdi     # 0x84fc8
leaq 0xa827(%rip), %rsi      # 0x67bcb
callq 0x5460
movq %rax, 0x158(%rsp)
jmp 0x5d3b3
movq 0x158(%rsp), %rdi
leaq 0xb08(%rsp), %rsi
callq 0x53e0
movq %rax, 0x150(%rsp)
jmp 0x5d3d2
movq 0x150(%rsp), %rdi
movq 0x27bcf(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5d3e8
movb $0x0, 0xea7(%rsp)
movl $0x1, 0xcac(%rsp)
jmp 0x5e15c
jmp 0x5d404
jmp 0x5d404
jmp 0x5d406
leaq 0x838(%rsp), %rdi
callq 0xf8b0
jmp 0x5d415
leaq 0xb58(%rsp), %rdi
callq 0x51d0
movq %rax, %rsi
leaq 0x838(%rsp), %rdi
movl $0x8, %edx
callq 0xf9c0
jmp 0x5d439
movq 0x838(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x838(%rsp,%rax), %rdi
callq 0x5760
movb %al, 0x14f(%rsp)
jmp 0x5d45b
movb 0x14f(%rsp), %al
testb $0x1, %al
jne 0x5d4ef
jmp 0x5d46c
movq 0x27b55(%rip), %rdi     # 0x84fc8
leaq 0xd93c(%rip), %rsi      # 0x6adb6
callq 0x5460
movq %rax, 0x140(%rsp)
jmp 0x5d489
movq 0x140(%rsp), %rdi
leaq 0xb58(%rsp), %rsi
callq 0x53e0
movq %rax, 0x138(%rsp)
jmp 0x5d4a8
movq 0x138(%rsp), %rdi
movq 0x27af9(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5d4be
movb $0x0, 0xea7(%rsp)
movl $0x1, 0xcac(%rsp)
jmp 0x5e14f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5e199
jmp 0x5d4f1
movq 0x838(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x838(%rsp,%rax), %rdi
callq 0x5760
movb %al, 0x137(%rsp)
jmp 0x5d513
movb 0x137(%rsp), %al
testb $0x1, %al
jne 0x5d523
jmp 0x5dee5
leaq 0x817(%rsp), %rdi
movq %rdi, 0x128(%rsp)
callq 0x57c0
movq 0x128(%rsp), %rdx
leaq 0xd64d(%rip), %rsi      # 0x6ab94
leaq 0x818(%rsp), %rdi
callq 0x6880
jmp 0x5d556
leaq 0x817(%rsp), %rdi
callq 0x54d0
leaq 0x9c0(%rsp), %rdi
leaq 0x818(%rsp), %rsi
callq 0x50c0
jmp 0x5d57a
leaq 0x818(%rsp), %rdi
callq 0x5310
cmpq $0x0, %rax
je 0x5d5b8
xorl %eax, %eax
movl %eax, %esi
leaq 0x818(%rsp), %rdi
callq 0x5880
movq %rax, 0x120(%rsp)
jmp 0x5d5a8
movq 0x120(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x5d607
movl $0x4, 0xcac(%rsp)
jmp 0x5de6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0x817(%rsp), %rdi
callq 0x54d0
jmp 0x5e199
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5ded3
movb $0x9, 0x7f7(%rsp)
leaq 0x7f8(%rsp), %rdi
leaq 0x818(%rsp), %rsi
leaq 0x7f7(%rsp), %rdx
callq 0x60790
jmp 0x5d62e
movq 0xb30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb30(%rsp)
leaq 0x7f8(%rsp), %rdi
movl $0x3, %esi
callq 0x88f0
movq %rax, %rdi
callq 0x51d0
movq %rax, %rdi
callq 0x56a0
movl %eax, 0x7f0(%rsp)
cmpl $0x3e8, 0x7f0(%rsp) # imm = 0x3E8
jge 0x5d688
movl $0x4, 0xcac(%rsp)
jmp 0x5de5d
cvtsi2sdl 0x7f0(%rsp), %xmm0
movsd 0x9237(%rip), %xmm1     # 0x668d0
divsd %xmm1, %xmm0
callq 0x51e0
cvttsd2si %xmm0, %eax
movl %eax, 0x7ec(%rsp)
leaq 0x7e0(%rsp), %rdi
callq 0x5e830
leaq 0xb78(%rsp), %rdi
leaq 0x7ec(%rsp), %rsi
callq 0x5e850
movq %rax, 0x118(%rsp)
jmp 0x5d6d9
movq 0x118(%rsp), %rax
movq %rax, 0x7d8(%rsp)
movq 0x7d8(%rsp), %rax
movq %rax, 0x7e0(%rsp)
leaq 0xb78(%rsp), %rdi
callq 0x56eb0
movq %rax, 0x7d0(%rsp)
leaq 0x7e0(%rsp), %rdi
leaq 0x7d0(%rsp), %rsi
callq 0x56d70
testb $0x1, %al
jne 0x5d72c
jmp 0x5d822
leaq 0x7a0(%rsp), %rdi
movq %rdi, 0x110(%rsp)
callq 0xfb70
movq 0x110(%rsp), %rdx
leaq 0x768(%rsp), %rdi
leaq 0x7ec(%rsp), %rsi
callq 0x519c0
jmp 0x5d760
leaq 0xb78(%rsp), %rdi
leaq 0x768(%rsp), %rsi
callq 0x51970
movb %dl, 0x107(%rsp)
movq %rax, 0x108(%rsp)
jmp 0x5d786
movb 0x107(%rsp), %al
movq 0x108(%rsp), %rcx
movq %rcx, 0x758(%rsp)
movb %al, 0x760(%rsp)
leaq 0x768(%rsp), %rdi
callq 0x51a00
leaq 0x7a0(%rsp), %rdi
callq 0xfe40
jmp 0x5d822
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5dec6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5d810
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0x768(%rsp), %rdi
callq 0x51a00
leaq 0x7a0(%rsp), %rdi
callq 0xfe40
jmp 0x5dec6
leaq 0xb78(%rsp), %rdi
leaq 0x7ec(%rsp), %rsi
callq 0x5e850
movq %rax, 0xf8(%rsp)
jmp 0x5d841
movq 0xf8(%rsp), %rax
movq %rax, 0x750(%rsp)
movq 0x750(%rsp), %rax
movq %rax, 0x7e0(%rsp)
leaq 0x7f8(%rsp), %rdi
movl $0x4, %esi
callq 0x88f0
movq %rax, %rsi
leaq 0x730(%rsp), %rdi
callq 0x51f0
jmp 0x5d885
leaq 0x7e0(%rsp), %rdi
callq 0x56f00
movq %rax, %rdi
addq $0x8, %rdi
leaq 0x730(%rsp), %rsi
callq 0x10110
movq %rax, 0xf0(%rsp)
jmp 0x5d8b0
movq 0xf0(%rsp), %rax
movq %rax, 0x728(%rsp)
leaq 0x7e0(%rsp), %rdi
callq 0x56f00
movq %rax, %rdi
addq $0x8, %rdi
callq 0x10160
movq %rax, 0x720(%rsp)
leaq 0x728(%rsp), %rdi
leaq 0x720(%rsp), %rsi
callq 0x10140
testb $0x1, %al
jne 0x5d8ff
jmp 0x5d9d4
leaq 0x7e0(%rsp), %rdi
callq 0x56f00
addq $0x8, %rax
movq %rax, 0xe8(%rsp)
movl $0x1, 0x6f4(%rsp)
leaq 0x6f8(%rsp), %rdi
leaq 0x730(%rsp), %rsi
leaq 0x6f4(%rsp), %rdx
callq 0x5e880
jmp 0x5d942
movq 0xe8(%rsp), %rdi
leaq 0x6f8(%rsp), %rsi
callq 0x10190
movb %dl, 0xdf(%rsp)
movq %rax, 0xe0(%rsp)
jmp 0x5d968
movb 0xdf(%rsp), %al
movq 0xe0(%rsp), %rcx
movq %rcx, 0x6e0(%rsp)
movb %al, 0x6e8(%rsp)
leaq 0x6f8(%rsp), %rdi
callq 0x10220
jmp 0x5d9ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5deb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0x6f8(%rsp), %rdi
callq 0x10220
jmp 0x5deb9
leaq 0x728(%rsp), %rdi
callq 0x10230
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
leaq 0x558(%rsp), %rdi
callq 0x5320
jmp 0x5d9fc
leaq 0x537(%rsp), %rdi
movq %rdi, 0xd0(%rsp)
callq 0x57c0
movq 0xd0(%rsp), %rdx
leaq 0xd174(%rip), %rsi      # 0x6ab94
leaq 0x538(%rsp), %rdi
callq 0x6880
jmp 0x5da2f
leaq 0x558(%rsp), %rdi
leaq 0x538(%rsp), %rsi
callq 0x5510
jmp 0x5da46
leaq 0x538(%rsp), %rdi
callq 0x58b8
leaq 0x537(%rsp), %rdi
callq 0x54d0
leaq 0x568(%rsp), %rdi
leaq 0xd374(%rip), %rsi      # 0x6ade3
callq 0x5460
movq %rax, 0xc8(%rsp)
jmp 0x5da7e
movq 0xc8(%rsp), %rdi
leaq 0xb08(%rsp), %rsi
callq 0x53e0
movq %rax, 0xc0(%rsp)
jmp 0x5da9d
movq 0xc0(%rsp), %rdi
leaq 0xd338(%rip), %rsi      # 0x6ade4
callq 0x5460
movq %rax, 0xb8(%rsp)
jmp 0x5dabb
movq 0xb8(%rsp), %rdi
leaq 0xb38(%rsp), %rsi
callq 0x53e0
movq %rax, 0xb0(%rsp)
jmp 0x5dada
movq 0xb0(%rsp), %rdi
leaq 0x9fae(%rip), %rsi      # 0x67a97
callq 0x5460
movq %rax, 0xa8(%rsp)
jmp 0x5daf8
movq 0xa8(%rsp), %rdi
movl 0x7ec(%rsp), %esi
callq 0x5790
movq %rax, 0xa0(%rsp)
jmp 0x5db16
movq 0xa0(%rsp), %rdi
leaq 0xd07b(%rip), %rsi      # 0x6aba0
callq 0x5460
jmp 0x5db2c
leaq 0x330(%rsp), %rdi
callq 0x5770
jmp 0x5db3b
leaq 0x310(%rsp), %rdi
leaq 0x558(%rsp), %rsi
callq 0x5440
jmp 0x5db52
leaq 0x310(%rsp), %rdi
callq 0x51d0
movq %rax, 0x90(%rsp)
movl $0x10, %edi
movl $0x1, %esi
callq 0x2dd90
movl %eax, 0x9c(%rsp)
jmp 0x5db7f
movl 0x9c(%rsp), %edx
movq 0x90(%rsp), %rsi
leaq 0x330(%rsp), %rdi
callq 0x5070
jmp 0x5db9d
leaq 0x310(%rsp), %rdi
callq 0x58b8
movq 0x330(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x330(%rsp,%rax), %rdi
callq 0x5760
movb %al, 0x8f(%rsp)
jmp 0x5dbcc
movb 0x8f(%rsp), %al
testb $0x1, %al
jne 0x5dd2c
jmp 0x5dbdd
movq 0x273e4(%rip), %rdi     # 0x84fc8
leaq 0x8f6b(%rip), %rsi      # 0x66b56
callq 0x5460
movq %rax, 0x80(%rsp)
jmp 0x5dbfa
leaq 0x2f0(%rsp), %rdi
leaq 0x558(%rsp), %rsi
callq 0x5440
jmp 0x5dc11
movq 0x80(%rsp), %rdi
leaq 0x2f0(%rsp), %rsi
callq 0x53e0
movq %rax, 0x78(%rsp)
jmp 0x5dc2d
movq 0x78(%rsp), %rdi
movq 0x27377(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5dc40
leaq 0x2f0(%rsp), %rdi
callq 0x58b8
movb $0x0, 0xea7(%rsp)
movl $0x1, 0xcac(%rsp)
jmp 0x5de36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5dc9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0x538(%rsp), %rdi
callq 0x58b8
leaq 0x537(%rsp), %rdi
callq 0x54d0
jmp 0x5deac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5deac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5de9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x58b8
jmp 0x5de9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0x2f0(%rsp), %rdi
callq 0x58b8
jmp 0x5de9f
leaq 0x330(%rsp), %rdi
leaq 0x818(%rsp), %rsi
callq 0x53e0
movq %rax, 0x70(%rsp)
jmp 0x5dd48
movq 0x70(%rsp), %rdi
movq 0x2725c(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5dd5b
leaq 0x330(%rsp), %rdi
callq 0x5610
jmp 0x5dd6a
movq 0xb28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb28(%rsp)
movq 0xb30(%rsp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x5de2b
movq 0x27227(%rip), %rdi     # 0x84fc8
leaq 0x90fe(%rip), %rsi      # 0x66ea6
callq 0x5460
movq %rax, 0x68(%rsp)
jmp 0x5ddb4
movq 0x68(%rsp), %rdi
movq 0xb30(%rsp), %rsi
callq 0x50f0
movq %rax, 0x60(%rsp)
jmp 0x5ddcd
movq 0x60(%rsp), %rdi
leaq 0xd00d(%rip), %rsi      # 0x6ade6
callq 0x5460
movq %rax, 0x58(%rsp)
jmp 0x5dde5
movq 0x58(%rsp), %rdi
movq 0xb28(%rsp), %rsi
callq 0x50f0
movq %rax, 0x50(%rsp)
jmp 0x5ddfe
movq 0x50(%rsp), %rdi
leaq 0xcff3(%rip), %rsi      # 0x6adfd
callq 0x5460
movq %rax, 0x48(%rsp)
jmp 0x5de16
movq 0x48(%rsp), %rdi
movq 0x2718e(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5de29
jmp 0x5de2b
movl $0x0, 0xcac(%rsp)
leaq 0x330(%rsp), %rdi
callq 0x5670
leaq 0x558(%rsp), %rdi
callq 0x5350
leaq 0x730(%rsp), %rdi
callq 0x58b8
leaq 0x7f8(%rsp), %rdi
callq 0x8910
leaq 0x818(%rsp), %rdi
callq 0x58b8
movl 0xcac(%rsp), %eax
movl %eax, 0x44(%rsp)
testl %eax, %eax
je 0x5de9a
jmp 0x5de88
movl 0x44(%rsp), %eax
subl $0x4, %eax
je 0x5d4f1
jmp 0x5e14f
jmp 0x5d4f1
leaq 0x330(%rsp), %rdi
callq 0x5670
leaq 0x558(%rsp), %rdi
callq 0x5350
leaq 0x730(%rsp), %rdi
callq 0x58b8
leaq 0x7f8(%rsp), %rdi
callq 0x8910
leaq 0x818(%rsp), %rdi
callq 0x58b8
jmp 0x5e199
leaq 0x2e8(%rsp), %rdi
callq 0x5e830
leaq 0x2e0(%rsp), %rdi
callq 0x5e830
leaq 0xb78(%rsp), %rdi
callq 0x5e8c0
movq %rax, 0x2d8(%rsp)
movq 0x2d8(%rsp), %rax
movq %rax, 0x2e8(%rsp)
leaq 0xb78(%rsp), %rdi
callq 0x56eb0
movq %rax, 0x2d0(%rsp)
movq 0x2d0(%rsp), %rax
movq %rax, 0x2e0(%rsp)
leaq 0x2e8(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
callq 0x5e8f0
testb $0x1, %al
jne 0x5df67
jmp 0x5e12d
leaq 0x2e8(%rsp), %rdi
callq 0x56f00
movq %rax, %rsi
addq $0x8, %rsi
leaq 0x2a0(%rsp), %rdi
callq 0xfd90
jmp 0x5df8a
leaq 0x280(%rsp), %rdi
leaq 0xb08(%rsp), %rsi
callq 0x51f0
jmp 0x5dfa1
leaq 0x260(%rsp), %rdi
leaq 0xb38(%rsp), %rsi
callq 0x51f0
jmp 0x5dfb8
leaq 0x2e8(%rsp), %rdi
callq 0x56f00
movl (%rax), %ecx
leaq 0x2a0(%rsp), %rdi
leaq 0x280(%rsp), %rsi
leaq 0x260(%rsp), %rdx
callq 0x5e350
movb %al, 0x43(%rsp)
jmp 0x5dfea
movb 0x43(%rsp), %al
xorb $-0x1, %al
movb %al, 0x42(%rsp)
leaq 0x260(%rsp), %rdi
callq 0x58b8
leaq 0x280(%rsp), %rdi
callq 0x58b8
leaq 0x2a0(%rsp), %rdi
callq 0xfe40
movb 0x42(%rsp), %al
testb $0x1, %al
jne 0x5e028
jmp 0x5e111
movq 0x26f99(%rip), %rdi     # 0x84fc8
leaq 0xcdd3(%rip), %rsi      # 0x6ae09
callq 0x5460
movq %rax, 0x38(%rsp)
jmp 0x5e042
leaq 0x2e8(%rsp), %rdi
callq 0x56f00
movq 0x38(%rsp), %rdi
movl (%rax), %esi
callq 0x5790
movq %rax, 0x30(%rsp)
jmp 0x5e062
movq 0x30(%rsp), %rdi
leaq 0xcdc4(%rip), %rsi      # 0x6ae32
callq 0x5460
movq %rax, 0x28(%rsp)
jmp 0x5e07a
movq 0x28(%rsp), %rdi
movq 0x26f2a(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5e08d
movb $0x0, 0xea7(%rsp)
movl $0x1, 0xcac(%rsp)
jmp 0x5e14f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5e0ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
jmp 0x5e0f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xce0(%rsp)
movl %eax, 0xcdc(%rsp)
leaq 0x260(%rsp), %rdi
callq 0x58b8
leaq 0x280(%rsp), %rdi
callq 0x58b8
leaq 0x2a0(%rsp), %rdi
callq 0xfe40
jmp 0x5e199
leaq 0x2e8(%rsp), %rdi
xorl %esi, %esi
callq 0x5e910
movq %rax, 0x258(%rsp)
jmp 0x5df49
leaq 0xbf0(%rsp), %rdi
xorl %esi, %esi
callq 0x2d340
movq %rax, 0x250(%rsp)
movl $0x0, 0xcac(%rsp)
leaq 0x838(%rsp), %rdi
callq 0xfe60
leaq 0xb08(%rsp), %rdi
callq 0x58b8
leaq 0xb38(%rsp), %rdi
callq 0x58b8
leaq 0xb58(%rsp), %rdi
callq 0x58b8
movl 0xcac(%rsp), %eax
testl %eax, %eax
jne 0x5e288
jmp 0x5e194
jmp 0x5d0ef
leaq 0x838(%rsp), %rdi
callq 0xfe60
leaq 0xb08(%rsp), %rdi
callq 0x58b8
leaq 0xb38(%rsp), %rdi
callq 0x58b8
leaq 0xb58(%rsp), %rdi
callq 0x58b8
jmp 0x5e2b1
callq 0x52e0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x248(%rsp)
movq 0x26ddc(%rip), %rdi     # 0x84fc8
leaq 0x8152(%rip), %rsi      # 0x66345
callq 0x5460
movq %rax, 0x20(%rsp)
jmp 0x5e1ff
movq 0x20(%rsp), %rdi
movsd 0x248(%rsp), %xmm0
movsd 0xca0(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd 0x7de6(%rip), %xmm1     # 0x66008
divsd %xmm1, %xmm0
callq 0x5830
movq %rax, 0x18(%rsp)
jmp 0x5e232
movq 0x18(%rsp), %rdi
leaq 0x811a(%rip), %rsi      # 0x66358
callq 0x5460
movq %rax, 0x10(%rsp)
jmp 0x5e24a
movq 0x10(%rsp), %rdi
movq 0x26d5a(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x8(%rsp)
jmp 0x5e262
movq 0x8(%rsp), %rdi
movq 0x26d42(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x5e275
movb $0x1, 0xea7(%rsp)
movl $0x1, 0xcac(%rsp)
leaq 0xb78(%rsp), %rdi
callq 0x52460
leaq 0xbb0(%rsp), %rdi
callq 0x58b8
leaq 0xc00(%rsp), %rdi
callq 0x58b8
jmp 0x5e2da
leaq 0xb78(%rsp), %rdi
callq 0x52460
leaq 0xbb0(%rsp), %rdi
callq 0x58b8
leaq 0xc00(%rsp), %rdi
callq 0x58b8
jmp 0x5e2f6
leaq 0xc48(%rsp), %rdi
callq 0x8910
leaq 0xc88(%rsp), %rdi
callq 0x8910
jmp 0x5e312
leaq 0xc48(%rsp), %rdi
callq 0x8910
leaq 0xc88(%rsp), %rdi
callq 0x8910
jmp 0x5e330
leaq 0xd10(%rsp), %rdi
callq 0x5350
movb 0xea7(%rsp), %al
andb $0x1, %al
addq $0xea8, %rsp            # imm = 0xEA8
retq
leaq 0xd10(%rsp), %rdi
callq 0x5350
movq 0xce0(%rsp), %rdi
callq 0x57b0
nopw (%rax,%rax)