// File: /workspace/github_cpp_makefile_star2_O3/schneebergerlab[P]DrLink/convert_bam.cpp
// Function: convertBam(int, char**)
bool convertBam(int argc, char* argv[])
{
    if(argc < 4)
    {
        cout << "\n   DrLink preprocess\t"
             << "Usage: samtools view longranger_wgs.bam | DrLink preprocess - out_prefix_str " << endl;  
        return false;
    }
    clock_t tbeg;
    tbeg = clock();
    bool verbose = true; // to add future option    
    //
    cout << "   Info: converting streaming bam info started..." << endl;
    // prepare output gzipped file
    string ofilename = (string)argv[3] + "_bamInfo_trashme.gz";
    ogzstream  ofp;
    ofp.open(ofilename.c_str());
    if ( ! ofp.good()) {
        std::cerr << "ERROR: Opening file `" << ofilename << "' failed.\n";
	return 1;
    }
    ofp << "#chr\tpos\tbamCIGAR\tbarcode\tlrMI\tread-order:bamFLAG\treversed-align\tread-id\tpnext" << endl;
    // pnext: where its pair is aligned: must be the same-chr-position - only concordant alignments kept.
    //
    unsigned long numraw  = 0;
    unsigned long numcov  = 0;
    unsigned long numNoBX = 0;
    unsigned long numNoCG = 0; // no cigar string    
    unsigned long numNoMI = 0;
    unsigned long numNoMA = 0; // number of reads showing multiple alignment: only one kept.    
    unsigned long numDiscordant = 0; // read pairs aligned not in the same chr-region.
    string exampleNoBX("");
    string exampleNoCG("");    
    string exampleNoMI("");
    string exampleNoMA("");
    string exampleDiscordant("");
    bool out = false;
    std::string line;
    while (std::getline(std::cin, line)) 
    {
        if(line.compare("quit")==0 || line.compare("q")==0 || line.compare("exit")==0) break;
        if(line.size()==0 || line[0]=='#') continue;
        numraw ++;
        if(numraw%10000000 == 0)
        {
            cout << "   info: " << numraw << "th aligm..." << endl;
        }
        //
        vector<string> lineinfo = split_string(line, '\t');
        
        // cigar string
        if(lineinfo[5].compare("*") == 0) 
        {
            if(exampleNoCG.size()==0)
            {
                exampleNoCG = line;
                cout << "   Warning: there are alignments without explicit CIGAR string, skipped., e.g.: " 
                     << line 
                     << endl;
                cout << "   Info: you will get a total number of such alignments in the end of program. " 
                     << endl;
            }
            numNoCG ++;
            continue;
        }
        // discordant read pairs
        if(lineinfo[6].compare("=") != 0)
        {
            // case 1: not on the same chr
            if(exampleDiscordant.size()==0)
            {
                exampleDiscordant = line;
                cout << "   Warning: there are discordant alignments, skipped., e.g.: " 
                     << line 
                     << endl;
                cout << "   Info: you will get a total number of such alignments in the end of program. " 
                     << endl;
            }  
            numDiscordant ++;
            continue;                      
        }
        else
        {
            // case 2: on the same read, but unexpected template length 
            string tmplen;
            if(lineinfo[8].find("-") != std::string::npos)
            {
                tmplen = lineinfo[8].substr(1);
            }
            else
            {
                tmplen = lineinfo[8].substr(0);
            }
            unsigned long templateLen = strtoul(tmplen.c_str(), NULL, 0);
            if(templateLen==0 || templateLen>2000) // caution: fragment size
            {
                if(exampleDiscordant.size()==0)
                {
                    exampleDiscordant = line;
                    cout << "   Warning: there are discordant alignments, skipped., e.g.: " 
                         << line 
                         << endl;
                    cout << "   Info: you will get a total number of such alignments in the end of program. " 
                         << endl;
                }
                numDiscordant ++;
                continue;    
            }
        }
        //
        /* BX: Chromium barcode sequence that is error-corrected and confirmed against 
           a list of known-good barcode sequences. Use this for analysis, e.g., '\tBX:Z:TTTGTGTGTATGACTC-1' */        
        size_t pos1  = line.find("\tBX:");
        if(pos1 == std::string::npos) 
        {
            if(exampleNoBX.size()==0)
            {
                exampleNoBX = line;
                cout << "   Warning: there are alignments without BX info, skipped., e.g.: " 
                     << line 
                     << endl;
                cout << "   Info: you will get a total number of such alignments in the end of program. " 
                     << endl;                
            }
            numNoBX ++;
            continue;
        }
        pos1 += 1; // from 'BX:Z:...'
        size_t pos2  = line.find("\t", pos1);
        if(pos2 == std::string::npos)
        {
            pos2 = line.size();
        }        
        string rawbx = line.substr(pos1, pos2-pos1);
        //
        /* MI: Global molecule identifier for molecule that generated this read,
           e.g.,  '\tMI:i:29' */
        size_t pos3  = line.find("\tMI:");
        bool foundmi = true;
        if(pos3 == std::string::npos)
        {
            if(exampleNoMI.size()==0)
            {
                exampleNoMI = line;
                cout << "   Warning: there are alignments without MI info, but kept, e.g.: " 
                     << line 
                     << endl;
                cout << "   Info: you will get a total number of such alignments in the end of program. " 
                     << endl;                
            }
            numNoMI ++;
            foundmi = false;
        }
        pos3 += 1; // from 'MI:i:...'
        size_t pos4;
        string rawmi("-1");
        if(foundmi)
        {
            pos4 = line.find("\t", pos3);
            if(pos4 == std::string::npos)
            {
                pos4 = line.size();
            }
            rawmi = line.substr(pos3+5, pos4-pos3-5); // without "MI:i:"
        }
        //
        // check if it is read 1 or read 2
        int hexflag = strtol(lineinfo[1].c_str(), NULL, 0);
        if(hexflag > 255) 
        {
            numNoMA ++;
            if(exampleNoMA.size()==0)
            {
                exampleNoMA = line;
                cout << "   Warning: there are alignments being secondary/supplementary or not passing filters, skipped, e.g.: " 
                     << line 
                     << endl;
                cout << "   Info: you will get a total number of such alignments in the end of program. " 
                     << endl;                
            }
            continue;
        }

        string readflag = "U";
        
        if((hexflag & 0x40) == 0x40 && (hexflag & 0x80) == 0)
        {
            readflag = "R1";
        }
        else
        if((hexflag & 0x40) == 0    && (hexflag & 0x80) == 0x80)
        {
            readflag = "R2";
        }
        else
        {
            readflag = "U0";
            cout << "   hexflag=" << hexflag << endl;
            cout << "   hexflag & 0x40 == 0x40= " << (hexflag & 0x40) << endl;
            cout << "   hexflag & 0x80 == 0   = " << (hexflag & 0x80) << endl;            
        }
        string reversed = "nrc";
        if((hexflag & 0x10) == 0x10) reversed = "rc";
        // chr	pos	CIGAR	barcode	MI	read-ordering:R1/R2	reversed	read-id	pnext
        // caution!!! code below also works for reversed-cases of alignment!
        // in bam/sam, it is always pos + CIGAR"M" ==> spanning of a read!!!
        ofp << lineinfo[2]                     << "\t" 
            << lineinfo[3]                     << "\t" 
            << lineinfo[5]                     << "\t" 
            << rawbx.substr(5, rawbx.size()-7) << "\t"
            << rawmi                           << "\t"
            << readflag  << ":" << lineinfo[1] << "\t" 
            << reversed                        << "\t"
            << lineinfo[0]                     << "\t"
            << lineinfo[7]                     << endl; // with read id and pnext
        //
        numcov ++;            
        if(!out) out = true;
        line.clear();
    }    
    //
    ofp.close();

    if(numNoBX > 0)
    {
        cout << "   Warning: there are "<< numNoBX 
             << " alignments without BX info, skipped. "              
             << endl;
    }
    if(numNoCG > 0)
    {
        cout << "   Warning: there are "<< numNoCG 
             << " alignments without explicit CIAGR info, skipped."   
             << endl;     
    }    
    if(numNoMI > 0)
    {
        cout << "   Warning: there are "<< numNoMI 
             << " alignments without MI info, but kept."              
             << endl;     
    }
    if(numNoMA > 0)
    {
        cout << "   Warning: there are "<< numNoMA 
             << " alignments being secondary/supplementary alignment"
             << " or not passing filters, skipped." 
             << endl;     
    }  
    if(numDiscordant > 0)
    {
        cout << "   Warning: there are "<< numDiscordant 
             << " alignments being discordant (pairs not on same chr or distance>2kb), skipped." 
             << endl;         
    }  
    cout << "   Info: in total " 
         << numraw  
         << " alignment lines, of which " 
         << numcov               
         << " with barcode info converted." 
         <<  endl;
    cout << "   Info: time on converting streaming bam info: " 
         << (float)(clock()-tbeg)/CLOCKS_PER_SEC 
         << " seconds.\n" 
         << endl;
    if(!out) return false;
    else return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
cmpl $0x3, %edi
jg 0x548f
movq 0x46b8f(%rip), %rbx     # 0x4bfc8
leaq 0x34f50(%rip), %rsi     # 0x3a390
movl $0x16, %edx
movq %rbx, %rdi
callq 0x43a0
leaq 0x34f53(%rip), %rsi     # 0x3a3a7
movl $0x4d, %edx
movq %rbx, %rdi
callq 0x43a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
xorl %ebp, %ebp
jmp 0x673c
movq %rsi, %rbx
callq 0x4200
movq %rax, %r14
movq 0x46b27(%rip), %r13     # 0x4bfc8
leaq 0x34f4d(%rip), %rsi     # 0x3a3f5
movl $0x31, %edx
movq %r13, %rdi
callq 0x43a0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r13, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movq 0x18(%rbx), %rsi
leaq 0x1e0(%rsp), %rdi
leaq 0x130(%rsp), %rdx
callq 0x5346
leaq 0x34f2a(%rip), %rsi     # 0x3a427
leaq 0x1e0(%rsp), %rdi
callq 0x45e0
leaq 0xb8(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x553a
movq %rdx, 0xa8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xb8(%rsp)
jmp 0x5540
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, 0xb0(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x1f0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x557c
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x1e0(%rsp), %rdi
callq 0x69ce
movq 0xa8(%rsp), %rsi
leaq 0x1e0(%rsp), %rdi
movl $0x10, %edx
callq 0x39022
movq 0x1e0(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x200(%rsp,%rax)
je 0x5609
movq 0x46a30(%rip), %rdi     # 0x4bff0
leaq 0x34e74(%rip), %rsi     # 0x3a43b
movl $0x15, %edx
callq 0x43a0
movq 0xa8(%rsp), %rsi
movq 0xb0(%rsp), %rdx
movq 0x46a08(%rip), %rdi     # 0x4bff0
callq 0x43a0
movb $0x1, %bpl
leaq 0x34e5a(%rip), %rsi     # 0x3a451
movl $0xa, %edx
movq %rax, %rdi
callq 0x43a0
jmp 0x66fe
leaq 0x368(%rsp), %rbx
leaq 0x34e44(%rip), %rsi     # 0x3a45c
movl $0x4e, %edx
movq %rbx, %rdi
callq 0x43a0
movq 0x368(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
leaq 0x140(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x394a6(%rip), %rdx     # 0x3eb0a
leaq 0x130(%rsp), %rdi
movq %rdx, %rsi
callq 0x5384
leaq 0x1a0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x39483(%rip), %rdx     # 0x3eb0a
leaq 0x190(%rsp), %rdi
movq %rdx, %rsi
callq 0x5384
leaq 0x180(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x39460(%rip), %rdx     # 0x3eb0a
leaq 0x170(%rsp), %rdi
movq %rdx, %rsi
callq 0x5384
leaq 0x160(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3943d(%rip), %rdx     # 0x3eb0a
leaq 0x150(%rsp), %rdi
movq %rdx, %rsi
callq 0x5384
movq %r14, 0x1d8(%rsp)
leaq 0x120(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x39412(%rip), %rdx     # 0x3eb0a
leaq 0x110(%rsp), %rdi
movq %rdx, %rsi
callq 0x5384
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq $0x0, 0x40(%rsp)
movq 0x468ac(%rip), %r12     # 0x4bfd8
movq %rsp, %r14
leaq 0x34d75(%rip), %rbx     # 0x3a4ab
movq $0x0, 0xd0(%rsp)
movq $0x0, 0xe0(%rsp)
movq $0x0, 0xe8(%rsp)
movq $0x0, 0xc8(%rsp)
movq $0x0, 0xd8(%rsp)
movq $0x0, 0xa0(%rsp)
xorl %ebp, %ebp
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x45c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x62b9
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4100
testl %eax, %eax
je 0x62b9
movq %r14, %rdi
leaq 0x34cde(%rip), %rsi     # 0x3a4b0
callq 0x4100
testl %eax, %eax
je 0x62b9
movq %r14, %rdi
leaq 0x34cc9(%rip), %rsi     # 0x3a4b2
callq 0x4100
testl %eax, %eax
je 0x62b9
cmpq $0x0, 0x8(%rsp)
je 0x5780
movq (%rsp), %rax
cmpb $0x23, (%rax)
je 0x5780
movq 0x40(%rsp), %rcx
incq %rcx
movq %rcx, %rax
movq %rcx, 0x40(%rsp)
movabsq $-0x1afcdb885172b95b, %rcx # imm = 0xE5032477AE8D46A5
imulq %rcx, %rax
rorq $0x7, %rax
movabsq $0x1ad7f29abca, %rcx    # imm = 0x1AD7F29ABCA
cmpq %rcx, %rax
ja 0x589b
movl $0x9, %edx
movq %r13, %rdi
leaq 0x34c6c(%rip), %rsi     # 0x3a4b7
callq 0x43a0
movq %r13, %rdi
movq 0x40(%rsp), %rsi
callq 0x4210
movq %rax, %r15
movl $0xb, %edx
movq %rax, %rdi
leaq 0x34c52(%rip), %rsi     # 0x3a4c1
callq 0x43a0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r15, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movb $0x9, 0x20(%rsp)
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
leaq 0x20(%rsp), %rdx
callq 0x367c0
movq 0x68(%rsp), %rdi
movl $0xa0, %eax
addq %rax, %rdi
leaq 0x34c07(%rip), %rsi     # 0x3a4cd
callq 0x4100
testl %eax, %eax
je 0x59ab
movq 0x68(%rsp), %rdi
movl $0xc0, %eax
addq %rax, %rdi
leaq 0x371b9(%rip), %rsi     # 0x3caa0
callq 0x4100
testl %eax, %eax
je 0x5a62
cmpq $0x0, 0x118(%rsp)
jne 0x599e
leaq 0x110(%rsp), %rdi
movq %r14, %rsi
callq 0x41c0
movl $0x3d, %edx
movq %r13, %rdi
leaq 0x34c4e(%rip), %rsi     # 0x3a570
callq 0x43a0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r13, %rdi
callq 0x43a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r15, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movl $0x4f, %edx
movq %r13, %rdi
leaq 0x34baf(%rip), %rsi     # 0x3a520
callq 0x43a0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r13, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
incq 0xa0(%rsp)
jmp 0x62aa
cmpq $0x0, 0x198(%rsp)
jne 0x5a55
leaq 0x190(%rsp), %rdi
movq %r14, %rsi
callq 0x41c0
movl $0x50, %edx
movq %r13, %rdi
leaq 0x34af6(%rip), %rsi     # 0x3a4cf
callq 0x43a0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r13, %rdi
callq 0x43a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r15, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movl $0x4f, %edx
movq %r13, %rdi
leaq 0x34af8(%rip), %rsi     # 0x3a520
callq 0x43a0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r13, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
incq 0xe8(%rsp)
jmp 0x62aa
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
movq 0x68(%rsp), %rdi
movl $0x100, %r15d           # imm = 0x100
addq %r15, %rdi
movl $0x1, %ecx
leaq 0x34b1a(%rip), %rsi     # 0x3a5ae
xorl %edx, %edx
callq 0x4590
cmpq $-0x1, %rax
je 0x5ac4
movq 0x68(%rsp), %rsi
addq %r15, %rsi
movl $0x1, %edx
leaq 0x48(%rsp), %r15
movq %r15, %rdi
movq $-0x1, %rcx
callq 0x4360
jmp 0x5ae2
movq 0x68(%rsp), %rsi
addq %r15, %rsi
leaq 0x48(%rsp), %r15
movq %r15, %rdi
xorl %edx, %edx
movq $-0x1, %rcx
callq 0x4360
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x43e0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x5b0b
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x20(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4130
decq %rax
movq %rax, 0x1d0(%rsp)
cmpq $0x7d0, %rax            # imm = 0x7D0
jb 0x5be2
cmpq $0x0, 0x118(%rsp)
jne 0x5bda
leaq 0x110(%rsp), %rdi
movq %r14, %rsi
callq 0x41c0
movl $0x3d, %edx
movq %r13, %rdi
leaq 0x34a12(%rip), %rsi     # 0x3a570
callq 0x43a0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r13, %rdi
callq 0x43a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r15, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movl $0x4f, %edx
movq %r13, %rdi
leaq 0x34973(%rip), %rsi     # 0x3a520
callq 0x43a0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r13, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
incq 0xa0(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x5bfe
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4340
cmpq $0x7d0, 0x1d0(%rsp) # imm = 0x7D0
jae 0x62aa
movl $0x4, %ecx
movq %r14, %rdi
leaq 0x34991(%rip), %rsi     # 0x3a5b0
xorl %edx, %edx
callq 0x4590
cmpq $-0x1, %rax
je 0x5e31
movq %rax, %r15
incq %r15
movl $0x1, %ecx
movq %r14, %rdi
leaq 0x38ec4(%rip), %rsi     # 0x3eb09
movq %r15, %rdx
callq 0x4590
cmpq $-0x1, %rax
jne 0x5c58
movq 0x8(%rsp), %rax
subq %r15, %rax
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0x4360
movl $0x4, %ecx
movq %r14, %rdi
leaq 0x3497b(%rip), %rsi     # 0x3a5f8
xorl %edx, %edx
callq 0x4590
movq %rax, %r15
cmpq $-0x1, %rax
jne 0x5cf9
cmpq $0x0, 0x178(%rsp)
jne 0x5cf1
leaq 0x170(%rsp), %rdi
movq %r14, %rsi
callq 0x41c0
movl $0x42, %edx
movq %r13, %rdi
leaq 0x34946(%rip), %rsi     # 0x3a5fd
callq 0x43a0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r13, %rdi
callq 0x43a0
movq %rax, %rdi
callq 0x41a0
movl $0x4f, %edx
movq %r13, %rdi
leaq 0x3483c(%rip), %rsi     # 0x3a520
callq 0x43a0
movq %r13, %rdi
callq 0x41a0
incq 0xc8(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x34931(%rip), %rsi     # 0x3a640
leaq 0x3492c(%rip), %rdx     # 0x3a642
callq 0x5384
cmpq $-0x1, %r15
je 0x5d9a
leaq 0x1(%r15), %rdx
movl $0x1, %ecx
movq %r14, %rdi
leaq 0x38dd5(%rip), %rsi     # 0x3eb09
callq 0x4590
cmpq $-0x1, %rax
jne 0x5d44
movq 0x8(%rsp), %rax
subq %r15, %rax
addq $0x6, %r15
addq $-0x6, %rax
movq %r15, %rdx
leaq 0x80(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rcx
callq 0x4360
leaq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0x43e0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x5d9a
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x68(%rsp), %rax
movq 0x20(%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4420
movq %rax, %r15
cmpl $0x100, %r15d           # imm = 0x100
jl 0x5ea2
incq 0xd8(%rsp)
cmpq $0x0, 0x158(%rsp)
jne 0x6272
leaq 0x150(%rsp), %rdi
movq %r14, %rsi
callq 0x41c0
movl $0x66, %edx
movq %r13, %rdi
leaq 0x34851(%rip), %rsi     # 0x3a643
callq 0x43a0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r13, %rdi
callq 0x43a0
movq %rax, %rdi
callq 0x41a0
movl $0x4f, %edx
movq %r13, %rdi
leaq 0x34701(%rip), %rsi     # 0x3a520
callq 0x43a0
movq %r13, %rdi
callq 0x41a0
jmp 0x6272
cmpq $0x0, 0x138(%rsp)
jne 0x5e95
leaq 0x130(%rsp), %rdi
movq %r14, %rsi
callq 0x41c0
movl $0x42, %edx
movq %r13, %rdi
leaq 0x3475a(%rip), %rsi     # 0x3a5b5
callq 0x43a0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r13, %rdi
callq 0x43a0
movq %rax, %rdi
callq 0x41a0
movl $0x4f, %edx
movq %r13, %rdi
leaq 0x34698(%rip), %rsi     # 0x3a520
callq 0x43a0
movq %r13, %rdi
callq 0x41a0
incq 0xe0(%rsp)
jmp 0x62aa
leaq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0x347e9(%rip), %rsi     # 0x3a6aa
leaq 0x347e3(%rip), %rdx     # 0x3a6ab
callq 0x5384
movl %r15d, %eax
andb $-0x40, %al
negb %al
leaq 0x347d4(%rip), %rsi     # 0x3a6af
jo 0x5ef1
movl %r15d, %eax
andl $0xc0, %eax
cmpl $0x40, %eax
jne 0x5f03
leaq 0x347bb(%rip), %rsi     # 0x3a6ac
leaq 0x80(%rsp), %rdi
callq 0x4410
jmp 0x5f95
leaq 0x80(%rsp), %rdi
leaq 0x347a0(%rip), %rsi     # 0x3a6b2
callq 0x4410
movl $0xb, %edx
movq %r13, %rdi
leaq 0x3478f(%rip), %rsi     # 0x3a6b5
callq 0x43a0
movq %r13, %rdi
movl %r15d, %esi
callq 0x4580
movq %rax, %rdi
callq 0x41a0
movl $0x1b, %edx
movq %r13, %rdi
leaq 0x34774(%rip), %rsi     # 0x3a6c1
callq 0x43a0
movl %r15d, %esi
andl $0x40, %esi
movq %r13, %rdi
callq 0x4580
movq %rax, %rdi
callq 0x41a0
movl $0x1b, %edx
movq %r13, %rdi
leaq 0x34766(%rip), %rsi     # 0x3a6dd
callq 0x43a0
movl %r15d, %esi
andl $0x80, %esi
movq %r13, %rdi
callq 0x4580
movq %rax, %rdi
callq 0x41a0
leaq 0x100(%rsp), %rax
movq %rax, 0xf0(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0x34745(%rip), %rsi     # 0x3a6f9
leaq 0x34741(%rip), %rdx     # 0x3a6fc
callq 0x5384
testb $0x10, %r15b
je 0x5fda
leaq 0xf0(%rsp), %rdi
leaq 0x34725(%rip), %rsi     # 0x3a6fa
callq 0x4410
movq 0x68(%rsp), %rax
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
leaq 0x368(%rsp), %rdi
callq 0x43a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x38b03(%rip), %rsi     # 0x3eb09
callq 0x43a0
movq 0x68(%rsp), %rax
movq 0x60(%rax), %rsi
movq 0x68(%rax), %rdx
movq %r15, %rdi
callq 0x43a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x38ad7(%rip), %rsi     # 0x3eb09
callq 0x43a0
movq 0x68(%rsp), %rax
movq 0xa0(%rax), %rsi
movq 0xa8(%rax), %rdx
movq %r15, %rdi
callq 0x43a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x38aa5(%rip), %rsi     # 0x3eb09
callq 0x43a0
movq 0x28(%rsp), %rcx
addq $-0x7, %rcx
movl $0x5, %edx
leaq 0x1b0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x4360
movq 0x1b0(%rsp), %rsi
movq 0x1b8(%rsp), %rdx
movq %r15, %rdi
callq 0x43a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x38a56(%rip), %rsi     # 0x3eb09
callq 0x43a0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %r15, %rdi
callq 0x43a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x38a2d(%rip), %rsi     # 0x3eb09
callq 0x43a0
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %r15, %rdi
callq 0x43a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x344f0(%rip), %rsi     # 0x3a5fb
callq 0x43a0
movq 0x68(%rsp), %rax
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
movq %r15, %rdi
callq 0x43a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x389d2(%rip), %rsi     # 0x3eb09
callq 0x43a0
movq 0xf0(%rsp), %rsi
movq 0xf8(%rsp), %rdx
movq %r15, %rdi
callq 0x43a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x389a3(%rip), %rsi     # 0x3eb09
callq 0x43a0
movq 0x68(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r15, %rdi
callq 0x43a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x38978(%rip), %rsi     # 0x3eb09
callq 0x43a0
movq 0x68(%rsp), %rax
movq 0xe0(%rax), %rsi
movq 0xe8(%rax), %rdx
movq %r15, %rdi
callq 0x43a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r15, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movq 0x1b0(%rsp), %rdi
leaq 0x1c0(%rsp), %rax
cmpq %rax, %rdi
je 0x6200
movq 0x1c0(%rsp), %rsi
incq %rsi
callq 0x4340
movzbl %bpl, %ebp
testb $0x1, %bpl
movl $0x1, %eax
cmovel %eax, %ebp
movq $0x0, 0x8(%rsp)
movq (%rsp), %rax
movb $0x0, (%rax)
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x6245
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x626a
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4340
incq 0xd0(%rsp)
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x628e
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x62aa
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x68(%rsp), %rdi
callq 0x6aac
jmp 0x5780
leaq 0x1e0(%rsp), %rdi
callq 0x392ca
movq 0xa0(%rsp), %r14
movq 0xd8(%rsp), %r15
movq 0xc8(%rsp), %r12
movq 0xe8(%rsp), %r13
movq 0xe0(%rsp), %rbx
testq %rbx, %rbx
je 0x6358
movq 0x45cce(%rip), %rdi     # 0x4bfc8
leaq 0x343fc(%rip), %rsi     # 0x3a6fd
movl $0x16, %edx
callq 0x43a0
movq 0x45cb6(%rip), %rdi     # 0x4bfc8
movq %rbx, %rsi
callq 0x4210
movq %rax, %rbx
leaq 0x343f0(%rip), %rsi     # 0x3a714
movl $0x26, %edx
movq %rax, %rdi
callq 0x43a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
testq %r13, %r13
je 0x63c2
movq 0x45c64(%rip), %rdi     # 0x4bfc8
leaq 0x34392(%rip), %rsi     # 0x3a6fd
movl $0x16, %edx
callq 0x43a0
movq 0x45c4c(%rip), %rdi     # 0x4bfc8
movq %r13, %rsi
callq 0x4210
movq %rax, %rbx
leaq 0x343ad(%rip), %rsi     # 0x3a73b
movl $0x31, %edx
movq %rax, %rdi
callq 0x43a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
testq %r12, %r12
je 0x642c
movq 0x45bfa(%rip), %rdi     # 0x4bfc8
leaq 0x34328(%rip), %rsi     # 0x3a6fd
movl $0x16, %edx
callq 0x43a0
movq 0x45be2(%rip), %rdi     # 0x4bfc8
movq %r12, %rsi
callq 0x4210
movq %rax, %rbx
leaq 0x34375(%rip), %rsi     # 0x3a76d
movl $0x26, %edx
movq %rax, %rdi
callq 0x43a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
testq %r15, %r15
je 0x64aa
movq 0x45b90(%rip), %rdi     # 0x4bfc8
leaq 0x342be(%rip), %rsi     # 0x3a6fd
movl $0x16, %edx
callq 0x43a0
movq 0x45b78(%rip), %rdi     # 0x4bfc8
movq %r15, %rsi
callq 0x4210
movq %rax, %rbx
leaq 0x34332(%rip), %rsi     # 0x3a794
movl $0x33, %edx
movq %rax, %rdi
callq 0x43a0
leaq 0x34352(%rip), %rsi     # 0x3a7c8
movl $0x21, %edx
movq %rbx, %rdi
callq 0x43a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
testq %r14, %r14
je 0x6514
movq 0x45b12(%rip), %rdi     # 0x4bfc8
leaq 0x34240(%rip), %rsi     # 0x3a6fd
movl $0x16, %edx
callq 0x43a0
movq 0x45afa(%rip), %rdi     # 0x4bfc8
movq %r14, %rsi
callq 0x4210
movq %rax, %rbx
leaq 0x3430a(%rip), %rsi     # 0x3a7ea
movl $0x4e, %edx
movq %rax, %rdi
callq 0x43a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movq 0x45aad(%rip), %rdi     # 0x4bfc8
leaq 0x34317(%rip), %rsi     # 0x3a839
movl $0x12, %edx
callq 0x43a0
movq 0x45a95(%rip), %rdi     # 0x4bfc8
movq 0x40(%rsp), %rsi
callq 0x4210
movq %rax, %rbx
leaq 0x34305(%rip), %rsi     # 0x3a84c
movl $0x1b, %edx
movq %rax, %rdi
callq 0x43a0
movq %rbx, %rdi
movq 0xd0(%rsp), %rsi
callq 0x4210
movq %rax, %rbx
leaq 0x342fa(%rip), %rsi     # 0x3a868
movl $0x1d, %edx
movq %rax, %rdi
callq 0x43a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movq 0x45a1f(%rip), %rdi     # 0x4bfc8
leaq 0x342d6(%rip), %rsi     # 0x3a886
movl $0x30, %edx
callq 0x43a0
callq 0x4200
subq 0x1d8(%rsp), %rax
cvtsi2ss %rax, %xmm0
divss 0x33db8(%rip), %xmm0    # 0x3a38c
cvtss2sd %xmm0, %xmm0
movq 0x459e9(%rip), %rdi     # 0x4bfc8
callq 0x4510
movq %rax, %rbx
leaq 0x342c9(%rip), %rsi     # 0x3a8b7
movl $0xa, %edx
movq %rax, %rdi
callq 0x43a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
leaq 0xb8(%rsp), %rbx
leaq 0x140(%rsp), %r14
je 0x664d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x6672
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x150(%rsp), %rdi
leaq 0x160(%rsp), %rax
cmpq %rax, %rdi
je 0x6697
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x170(%rsp), %rdi
leaq 0x180(%rsp), %rax
cmpq %rax, %rdi
je 0x66bc
movq 0x180(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x66e1
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x130(%rsp), %rdi
cmpq %r14, %rdi
je 0x66fe
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x4531b(%rip), %rsi     # 0x4ba20
leaq 0x1e0(%rsp), %rdi
callq 0x38fcc
leaq 0x370(%rsp), %rdi
callq 0x4140
movq 0xa8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x673c
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x4340
andb $0x1, %bpl
movl %ebp, %eax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x677b
jmp 0x6774
jmp 0x6765
jmp 0x6765
jmp 0x6780
jmp 0x6780
jmp 0x6838
movq %rax, %rbx
jmp 0x67fa
jmp 0x6780
jmp 0x6838
movq %rax, %rbx
jmp 0x67d5
jmp 0x6780
movq %rax, %rbx
jmp 0x67b0
movq %rax, %rbx
jmp 0x6816
movq %rax, %rbx
movq 0x1b0(%rsp), %rdi
leaq 0x1c0(%rsp), %rax
cmpq %rax, %rdi
je 0x67b0
movq 0x1c0(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x67d5
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x67fa
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x6816
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x683b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4340
jmp 0x683b
jmp 0x68a8
jmp 0x68a8
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x6aac
jmp 0x68ab
movq %rax, %rbx
jmp 0x68eb
movq %rax, %rbx
jmp 0x6910
movq %rax, %rbx
jmp 0x6935
movq %rax, %rbx
jmp 0x695a
jmp 0x689e
movq %rax, %rbx
jmp 0x69a0
movq %rax, %rbx
leaq 0x1f0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x69c5
movq 0x1f0(%rsp), %rsi
jmp 0x69bd
movq %rax, %rbx
jmp 0x69c5
movq %rax, %rbx
jmp 0x697f
jmp 0x68a8
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x68c6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x68eb
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x150(%rsp), %rdi
leaq 0x160(%rsp), %rax
cmpq %rax, %rdi
je 0x6910
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x170(%rsp), %rdi
leaq 0x180(%rsp), %rax
cmpq %rax, %rdi
je 0x6935
movq 0x180(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x695a
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x697f
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x4509a(%rip), %rsi     # 0x4ba20
leaq 0x1e0(%rsp), %rdi
callq 0x38fcc
leaq 0x370(%rsp), %rdi
callq 0x4140
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x69c5
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x4340
movq %rbx, %rdi
callq 0x45a0
nop