// File: /workspace/github_cpp_makefile_star2_O2/yhwu[P]sam2psl/sam2psl.cpp
// Function: main
int main(int argc, char* argv[])
{
  
  if ( argc>=2 ) {
    for( int i=1; i<argc; ++i) {
      if( string( argv[i]).find("-h")!=string::npos) 
	cout << "matches\tmisMatches\trepMatches\tnCount\tqNumInsert\t"
	     << "qBaseInsert\ttNumInsert\ttBaseInsert\tstrand\tqName\t"
	     << "qSize\tqStart\tqEnd\ttName\ttSize\t"
	     << "tStart\ttEnd\tblockCount\tblockSizes\tqStarts\t"
	     << "tStarts\tqBlocks\ttBlocks\t"
	     << "RI\tRNEXT\tPNEXT\tTLEN\tMAPQ\t"
	     << "AS\tMAPS\tFPAIRED\tFPROPER_PAIR\tFSECONDARY\t"
	     << "FQC\tFDUP"
	     << "\n";
    } 
  }
  
  string line;
  map<string,int> targetLen;  
  
  while( getline(cin, line) ) {
    istringstream iss(line);
    if ( line[0]=='@' ) {
      if ( line.find("@SQ")==string::npos ) continue; 
      string tmps, SN, LN;
      iss >> tmps >> SN >> LN;
      size_t p1=SN.find("SN:");
      if ( p1==string::npos ) continue; 
      SN=SN.substr(p1+3);
      p1=LN.find("LN:");
      if ( p1==string::npos ) continue; 
      LN=LN.substr(p1+3);
      targetLen[SN]=atoi(LN.c_str());
    }
    vector<string> field(0);
    string tmps;
    while( iss>>tmps ) field.push_back(tmps); 
    if( field.size()<11 ) continue;
    if( field[0][0]=='@' ) continue;
    
    PSL_st psl;
    SAM_st sam;
    FLAG_st flag;
    PSLComment_st pslc;
    
    sam.QNAME=field[0];
    sam.FLAG=atoi(field[1].c_str());
    sam.RNAME=field[2];
    sam.POS=atoi(field[3].c_str());
    sam.MAPQ=atoi(field[4].c_str());
    sam.CIGAR=field[5];
    sam.RNEXT=field[6];
    sam.PNEXT=atoi(field[7].c_str());
    sam.TLEN=atoi(field[8].c_str());
    sam.SEQ=field[9];
    sam.QUAL=field[10];
    sam.AS=-sam.SEQ.length();
    sam.NM=sam.SEQ.length();
    sam.MD="";
    int optionalField=0;
    for(int i=11; i<(int)field.size(); ++i) {
      if( field[i].substr(0,3)=="AS:" ) {
	size_t p=field[i].rfind(':');
	sam.AS=atoi( field[i].substr(p+1).c_str() );
	optionalField+=1;
      }
      if( field[i].substr(0,3)=="NM:" ) {
	size_t p=field[i].rfind(':');
	sam.NM=atoi( field[i].substr(p+1).c_str() );
	optionalField+=1;
      }
      if( field[i].substr(0,3)=="MD:" ) {
	size_t p=field[i].rfind(':');
	sam.MD=field[i].substr(p+1);
	optionalField+=1;
      }
      if( optionalField==3 ) break;
    }
    
    flag.FPAIRED = bool(sam.FLAG & BAM_FPAIRED);
    flag.FPROPER_PAIR = bool(sam.FLAG & BAM_FPROPER_PAIR);
    flag.FUNMAP = bool(sam.FLAG & BAM_FUNMAP);
    flag.FMUNMAP = bool(sam.FLAG & BAM_FMUNMAP);
    flag.FREVERSE = bool(sam.FLAG & BAM_FREVERSE); 
    flag.FMREVERSE = bool(sam.FLAG & BAM_FMREVERSE);
    flag.FREAD1 = bool(sam.FLAG & BAM_FREAD1);
    flag.FREAD2 = bool(sam.FLAG & BAM_FREAD2);
    flag.FSECONDARY = bool(sam.FLAG & BAM_FSECONDARY);
    flag.FQCFAIL = bool(sam.FLAG & BAM_FQCFAIL);
    flag.FDUP = bool(sam.FLAG & BAM_FDUP);

    POSCIGAR_st m;
    resolve_cigar_pos(sam.POS-1, sam.CIGAR, m);  // sam is 1-based, psl is 0-based
    if ( sam.SEQ.size() != m.l_qseq && m.l_qseq>0 ) {
      cerr << "SEQ length not calculated correctly\t"
	   << line << endl
	   << sam.SEQ.size() << "\t" << m.l_qseq << endl;
      exit(1);
    }
    
    psl.matches=0;
    psl.misMatches=sam.NM;
    psl.repMatches=0;
    psl.nCount=0;
    psl.qNumInsert=0;
    psl.qBaseInsert=0;
    psl.tNumInsert=0;
    psl.tBaseInsert=0;
    psl.strand= (sam.FLAG & BAM_FREVERSE) > 0 ? "-":"+";
    psl.qName=sam.QNAME;
    psl.qSize=sam.SEQ.size();
    psl.qStart=m.qStart;
    psl.qEnd=m.qEnd+1;  // m is 0-base closed, psl is 0-base half open
    psl.tName=sam.RNAME;
    psl.tSize=targetLen[sam.RNAME];
    psl.tStart=m.tStart;
    psl.tEnd=m.tEnd+1;  // m is 0-base closed, psl is 0-base half open
    psl.blockCount=0;
    psl.blockSizes.resize(0);
    psl.qStarts.resize(0);
    psl.tStarts.resize(0);
    for( int i=0; i<sam.SEQ.size(); ++i) {
      if( sam.SEQ[i]=='N' || sam.SEQ[i]=='n' ) psl.nCount+=1;
    }
    for( int i=0; i<m.op.size(); ++i) {
      if ( m.op[i] == BAM_CMATCH || 
	   m.op[i] == BAM_CDEL || 
	   m.op[i] == BAM_CEQUAL || 
	   m.op[i] == BAM_CDIFF) psl.matches+=m.nop[i];
      
      if ( m.op[i] == BAM_CINS ) {
	psl.qNumInsert+=1;
	psl.qBaseInsert+=m.nop[i];
      }
      
      if ( m.op[i] == BAM_CDEL ) {
	psl.tNumInsert+=1;
	psl.tBaseInsert+=m.nop[i];
      }
      
      if ( m.op[i] == BAM_CMATCH ) {
	psl.blockCount+=1;
	psl.blockSizes.push_back( m.nop[i] );
	psl.qStarts.push_back( m.qop[i] );
	psl.tStarts.push_back( m.top[i] );
      }
    }
    // note so far it is assumed strand is +
    if ( psl.strand=="-" ) {
      psl.qStart=psl.qSize-psl.qEnd;
      psl.qEnd=psl.qSize-psl.qStart;
      for(int i=0; i<psl.blockSizes.size(); ++i) {
	int qEndOnPlus=psl.qStarts[i]+psl.blockSizes[i];
	psl.qStarts[i]=psl.qSize-qEndOnPlus;
	// note tStart remain same
      }
      reverse(psl.blockSizes.begin(), psl.blockSizes.end());
      reverse(psl.qStarts.begin(), psl.qStarts.end());
      reverse(psl.tStarts.begin(), psl.tStarts.end());
    }
    
    pslc.RI=1;
    pslc.RNEXT=sam.RNEXT;
    pslc.PNEXT=sam.PNEXT-1; //SAM is 1-based
    pslc.TLEN=sam.TLEN;
    pslc.MAPQ=sam.MAPQ;
    pslc.AS=sam.AS;
    pslc.MAPS=psl.matches-psl.misMatches;
    pslc.FPAIRED=flag.FPAIRED;
    pslc.FPROPER_PAIR=flag.FPROPER_PAIR;
    pslc.FSECONDARY=flag.FSECONDARY;
    pslc.FQCFAIL=flag.FQCFAIL;
    pslc.FDUP=flag.FDUP;
    if ( !flag.FPAIRED ) pslc.RI=1;
    else {
      pslc.RI=0;
      if( flag.FREAD1 ) pslc.RI=1;
      if( flag.FREAD2 ) pslc.RI=2;
      if( pslc.RI==0 | flag.FREAD1==flag.FREAD2 ) {
	cerr << "check flag" << endl
	     << line << endl;
	exit(1);
      }
    }
    
    cout << "#"<< line << "\n";
    cout << psl.matches << "\t"
	 << psl.misMatches << "\t"
	 << psl.repMatches << "\t"
	 << psl.nCount << "\t"
	 << psl.qNumInsert << "\t"
	 << psl.qBaseInsert << "\t"
	 << psl.tNumInsert << "\t"
	 << psl.tBaseInsert << "\t"
	 << psl.strand << "\t"
	 << psl.qName << "\t"
	 << psl.qSize << "\t"
	 << psl.qStart << "\t"
	 << psl.qEnd << "\t"
	 << psl.tName << "\t"
	 << psl.tSize << "\t"
	 << psl.tStart << "\t"
	 << psl.tEnd << "\t"
	 << psl.blockCount << "\t";
    for(int i=0; i<psl.blockSizes.size(); ++i) cout << psl.blockSizes[i] << ",";
    cout << "\t";
    for(int i=0; i<psl.qStarts.size(); ++i) cout << psl.qStarts[i] << ",";
    cout << "\t";
    for(int i=0; i<psl.tStarts.size(); ++i) cout << psl.tStarts[i] << ",";
    cout << "\t";
    
    cout << "," << "\t";  // reserve for pslx
    cout << "," << "\t";  // reserve for pslx
    
    cout << pslc.RI << "\t"
	 << pslc.RNEXT << "\t"
	 << pslc.PNEXT << "\t"
	 << pslc.TLEN << "\t"
	 << pslc.MAPQ << "\t"
	 << pslc.AS << "\t"
	 << pslc.MAPS << "\t"
	 << "SP"[pslc.FPAIRED] << "\t"
	 << "UP"[pslc.FPROPER_PAIR] << "\t"
	 << "PS"[pslc.FSECONDARY] << "\t"
	 << "PF"[pslc.FQCFAIL] << "\t"
	 << "PD"[pslc.FDUP];
    
    cout << endl;
  }
  
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x588, %rsp            # imm = 0x588
cmpl $0x2, %edi
jl 0x296b
movq %rsi, %rbx
movl %edi, %ebp
pushq $0x1
popq %r15
leaq 0x408(%rsp), %r14
leaq 0x27ed(%rip), %r12      # 0x5089
cmpq %r15, %rbp
je 0x296b
movq (%rbx,%r15,8), %rsi
movq %r14, %rdi
leaq 0x60(%rsp), %rdx
callq 0x3bfa
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x22e0
movq %rax, %r13
movq %r14, %rdi
callq 0x20b0
cmpq $-0x1, %r13
je 0x2963
movq 0x56e9(%rip), %rdi      # 0x7fc8
leaq 0x27a6(%rip), %rsi      # 0x508c
callq 0x2170
movq %rax, %rdi
leaq 0x27c8(%rip), %rsi      # 0x50bd
callq 0x2170
movq %rax, %rdi
leaq 0x27ea(%rip), %rsi      # 0x50ee
callq 0x2170
movq %rax, %rdi
leaq 0x27fa(%rip), %rsi      # 0x510d
callq 0x2170
movq %rax, %rdi
leaq 0x2816(%rip), %rsi      # 0x5138
callq 0x2170
movq %rax, %rdi
leaq 0x2820(%rip), %rsi      # 0x5151
callq 0x2170
movq %rax, %rdi
leaq 0x282b(%rip), %rsi      # 0x516b
callq 0x2170
movq %rax, %rdi
leaq 0x2845(%rip), %rsi      # 0x5194
callq 0x2170
movq %rax, %rdi
leaq 0x2713(%rip), %rsi      # 0x5071
callq 0x2170
incq %r15
jmp 0x289c
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0x3e0(%rsp), %rcx
andl $0x0, (%rcx)
andq $0x0, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
andq $0x0, 0x20(%rcx)
movb $0x0, (%rax)
movl $0x80, %eax
leaq 0x60(%rsp), %rbx
leaq (%rbx,%rax), %rcx
movq %rcx, 0x310(%rsp)
leaq 0x208(%rsp), %r14
addq %r14, %rax
movq %rax, 0x318(%rsp)
movl $0xb8, %eax
leaq (%r14,%rax), %rcx
movq %rcx, 0x308(%rsp)
addq %rbx, %rax
movq %rax, 0x38(%rsp)
movq 0x55f6(%rip), %r12      # 0x7fd8
leaq 0x340(%rsp), %r13
leaq 0x8(%rsp), %rbp
leaq 0x320(%rsp), %r15
movq %r12, %rdi
leaq 0x40(%rsp), %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3a55
leaq 0x408(%rsp), %rdi
leaq 0x40(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x2280
movq 0x40(%rsp), %rax
cmpb $0x40, (%rax)
jne 0x2bbf
leaq 0x40(%rsp), %rdi
leaq 0x2758(%rip), %rsi      # 0x519d
xorl %edx, %edx
callq 0x22e0
cmpq $-0x1, %rax
je 0x3a43
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
andq $0x0, 0x68(%rsp)
leaq 0x218(%rsp), %rax
movq %rax, 0x208(%rsp)
andq $0x0, 0x210(%rsp)
xorl %ecx, %ecx
movb %cl, 0x70(%rsp)
movb %cl, 0x218(%rsp)
leaq 0x188(%rsp), %rax
movq %rax, 0x178(%rsp)
andq $0x0, 0x180(%rsp)
movb %cl, 0x188(%rsp)
leaq 0x408(%rsp), %rdi
movq %rbx, %rsi
callq 0x21f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21f0
movq %rax, %rdi
leaq 0x178(%rsp), %rsi
callq 0x21f0
movq %r14, %rdi
leaq 0x26c0(%rip), %rsi      # 0x51a1
xorl %edx, %edx
callq 0x22e0
cmpq $-0x1, %rax
je 0x32c2
addq $0x3, %rax
movq %r13, %rdi
movq %r14, %rsi
movq %rax, %rdx
pushq $-0x1
popq %rcx
callq 0x21a0
movq %r14, %rdi
movq %r13, %rsi
callq 0x21e0
movq %r13, %rdi
callq 0x20b0
leaq 0x178(%rsp), %rdi
leaq 0x267c(%rip), %rsi      # 0x51a5
xorl %edx, %edx
callq 0x22e0
cmpq $-0x1, %rax
je 0x32c2
addq $0x3, %rax
movq %r13, %rdi
leaq 0x178(%rsp), %r12
movq %r12, %rsi
movq %rax, %rdx
pushq $-0x1
popq %rcx
callq 0x21a0
movq %r12, %rdi
movq %r13, %rsi
callq 0x21e0
movq %r13, %rdi
callq 0x20b0
movq 0x178(%rsp), %rdi
callq 0x2250
movl %eax, %r14d
leaq 0x3d8(%rsp), %rdi
movq %r12, %rbp
leaq 0x208(%rsp), %r12
movq %r12, %rsi
callq 0x3c68
movl %r14d, (%rax)
movq %rbp, %rdi
callq 0x20b0
movq %r12, %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x20b0
movq %r12, %r14
movq 0x541e(%rip), %r12      # 0x7fd8
leaq 0x8(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x3cce
leaq 0x330(%rsp), %rax
movq %rax, 0x320(%rsp)
andq $0x0, 0x328(%rsp)
movb $0x0, 0x330(%rsp)
leaq 0x408(%rsp), %rdi
movq %r15, %rsi
callq 0x21f0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2c18
movq %rbp, %rdi
movq %r15, %rsi
callq 0x3d20
jmp 0x2bed
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rax
subq %rsi, %rax
cmpq $0x160, %rax            # imm = 0x160
jb 0x3a33
movq (%rsi), %rax
cmpb $0x40, (%rax)
je 0x3a33
leaq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
andq $0x0, 0x88(%rsp)
xorl %edx, %edx
movb %dl, 0x90(%rsp)
leaq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
andq $0x0, 0xa8(%rsp)
movb %dl, 0xb0(%rsp)
movq 0x310(%rsp), %rax
movq %rax, 0xd0(%rsp)
andq $0x0, 0xd8(%rsp)
movb %dl, 0xe0(%rsp)
pxor %xmm0, %xmm0
leaq 0x100(%rsp), %rcx
movdqu %xmm0, 0x60(%rcx)
andq $0x0, 0x70(%rcx)
leaq 0x218(%rsp), %rax
movq %rax, 0x208(%rsp)
andq $0x0, 0x210(%rsp)
movb %dl, 0x218(%rsp)
leaq 0x240(%rsp), %rax
movq %rax, 0x230(%rsp)
andq $0x0, 0x238(%rsp)
movdqu %xmm0, 0x50(%rcx)
movdqu %xmm0, 0x40(%rcx)
movb %dl, 0x240(%rsp)
leaq 0x268(%rsp), %rax
movq %rax, 0x258(%rsp)
andq $0x0, 0x260(%rsp)
movb %dl, 0x268(%rsp)
movq 0x318(%rsp), %rax
movq %rax, 0x278(%rsp)
andq $0x0, 0x280(%rsp)
movdqu %xmm0, 0x30(%rcx)
movdqu %xmm0, 0x20(%rcx)
movb %dl, 0x288(%rsp)
leaq 0x2b0(%rsp), %rax
movq %rax, 0x2a0(%rsp)
andq $0x0, 0x2a8(%rsp)
movb %dl, 0x2b0(%rsp)
leaq 0x2d0(%rsp), %rax
movq %rax, 0x2c0(%rsp)
andq $0x0, 0x2c8(%rsp)
movdqu %xmm0, 0x10(%rcx)
movdqu %xmm0, (%rcx)
movb %dl, 0x2d0(%rsp)
leaq 0x2f8(%rsp), %rax
movq %rax, 0x2e8(%rsp)
andq $0x0, 0x2f0(%rsp)
movb %dl, 0x2f8(%rsp)
leaq 0x190(%rsp), %rax
movq %rax, 0x180(%rsp)
andq $0x0, 0x188(%rsp)
movb %dl, 0x190(%rsp)
leaq 0x188(%rsp), %rax
movdqu %xmm0, 0x68(%rax)
movdqu %xmm0, 0x58(%rax)
movdqu %xmm0, 0x48(%rax)
movdqu %xmm0, 0x38(%rax)
andq $0x0, 0x78(%rax)
movq %r14, %rdi
callq 0x20f0
movq 0x8(%rsp), %r14
movq 0x20(%r14), %rdi
callq 0x2250
movl %eax, 0x228(%rsp)
addq $0x40, %r14
leaq 0x230(%rsp), %rdi
movq %r14, %rsi
callq 0x20f0
movq 0x8(%rsp), %r14
movq 0x60(%r14), %rdi
callq 0x2250
movl %eax, 0x250(%rsp)
movq 0x80(%r14), %rdi
callq 0x2250
movl %eax, 0x254(%rsp)
addq $0xa0, %r14
leaq 0x258(%rsp), %rdi
movq %r14, %rsi
callq 0x20f0
movq 0x8(%rsp), %rsi
movl $0xc0, %eax
addq %rax, %rsi
leaq 0x278(%rsp), %rdi
callq 0x20f0
movq 0x8(%rsp), %r14
movq 0xe0(%r14), %rdi
callq 0x2250
movl %eax, 0x298(%rsp)
movq 0x100(%r14), %rdi
callq 0x2250
movl %eax, 0x29c(%rsp)
addq $0x120, %r14            # imm = 0x120
leaq 0x2a0(%rsp), %rdi
movq %r14, %rsi
callq 0x20f0
movq 0x8(%rsp), %rsi
movl $0x140, %eax            # imm = 0x140
addq %rax, %rsi
movq 0x308(%rsp), %rdi
callq 0x20f0
movl 0x2a8(%rsp), %eax
movl %eax, %ecx
negl %ecx
movl %ecx, 0x2e0(%rsp)
movl %eax, 0x2e4(%rsp)
leaq 0x2e8(%rsp), %rdi
leaq 0x216f(%rip), %rsi      # 0x5070
callq 0x22c0
xorl %ebp, %ebp
movl $0x160, %ebx            # imm = 0x160
pushq $0xa
popq %r12
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rax
subq %rsi, %rax
shrq $0x5, %rax
cltq
incq %r12
cmpq %rax, %r12
jge 0x30b4
addq %rbx, %rsi
movq %r13, %rdi
xorl %edx, %edx
pushq $0x3
popq %rcx
callq 0x21a0
movq %r13, %rdi
leaq 0x225f(%rip), %rsi      # 0x51a9
callq 0x3bed
movl %eax, %r14d
movq %r13, %rdi
callq 0x20b0
testb %r14b, %r14b
je 0x2fab
movq 0x8(%rsp), %rdi
addq %rbx, %rdi
pushq $0x3a
popq %rsi
pushq $-0x1
popq %r14
movq %r14, %rdx
callq 0x22d0
movq 0x8(%rsp), %rsi
addq %rbx, %rsi
leaq 0x1(%rax), %rdx
movq %r13, %rdi
movq %r14, %rcx
callq 0x21a0
movq 0x340(%rsp), %rdi
callq 0x2250
movl %eax, 0x2e0(%rsp)
movq %r13, %rdi
callq 0x20b0
incl %ebp
movq 0x8(%rsp), %rsi
addq %rbx, %rsi
movq %r13, %rdi
xorl %edx, %edx
pushq $0x3
popq %rcx
callq 0x21a0
movq %r13, %rdi
leaq 0x21e3(%rip), %rsi      # 0x51ad
callq 0x3bed
movl %eax, %r14d
movq %r13, %rdi
callq 0x20b0
testb %r14b, %r14b
je 0x302b
movq 0x8(%rsp), %rdi
addq %rbx, %rdi
pushq $0x3a
popq %rsi
pushq $-0x1
popq %r14
movq %r14, %rdx
callq 0x22d0
movq 0x8(%rsp), %rsi
addq %rbx, %rsi
leaq 0x1(%rax), %rdx
movq %r13, %rdi
movq %r14, %rcx
callq 0x21a0
movq 0x340(%rsp), %rdi
callq 0x2250
movl %eax, 0x2e4(%rsp)
movq %r13, %rdi
callq 0x20b0
incl %ebp
movq 0x8(%rsp), %rsi
addq %rbx, %rsi
movq %r13, %rdi
xorl %edx, %edx
pushq $0x3
popq %rcx
callq 0x21a0
movq %r13, %rdi
leaq 0x2167(%rip), %rsi      # 0x51b1
callq 0x3bed
movl %eax, %r14d
movq %r13, %rdi
callq 0x20b0
testb %r14b, %r14b
je 0x30a7
movq 0x8(%rsp), %rdi
addq %rbx, %rdi
pushq $0x3a
popq %rsi
pushq $-0x1
popq %r14
movq %r14, %rdx
callq 0x22d0
movq 0x8(%rsp), %rsi
addq %rbx, %rsi
leaq 0x1(%rax), %rdx
movq %r13, %rdi
movq %r14, %rcx
callq 0x21a0
leaq 0x2e8(%rsp), %rdi
movq %r13, %rsi
callq 0x21e0
movq %r13, %rdi
callq 0x20b0
incl %ebp
addq $0x20, %rbx
cmpl $0x3, %ebp
jne 0x2f11
movl 0x228(%rsp), %r14d
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x35c(%rsp)
movdqa %xmm0, 0x350(%rsp)
movdqa %xmm0, 0x340(%rsp)
pxor %xmm0, %xmm0
leaq 0x370(%rsp), %rax
movdqu %xmm0, 0x50(%rax)
movdqu %xmm0, 0x40(%rax)
movdqu %xmm0, 0x30(%rax)
movdqu %xmm0, 0x20(%rax)
movdqu %xmm0, 0x10(%rax)
movdqu %xmm0, (%rax)
movl 0x250(%rsp), %edi
decl %edi
leaq 0x258(%rsp), %rsi
movq %r13, %rdx
callq 0x241c
leaq 0x8(%rsp), %rbp
movslq 0x368(%rsp), %rax
testq %rax, %rax
jle 0x313d
cmpq %rax, 0x2a8(%rsp)
jne 0x3a80
andl $0x0, 0x60(%rsp)
movl 0x2e4(%rsp), %eax
movl %eax, 0x64(%rsp)
leaq 0x70(%rsp), %rax
andq $0x0, 0x8(%rax)
testb $0x10, 0x228(%rsp)
pxor %xmm0, %xmm0
movdqu %xmm0, -0x8(%rax)
leaq 0x206b(%rip), %rsi      # 0x51da
leaq 0x2066(%rip), %rax      # 0x51dc
cmoveq %rax, %rsi
leaq 0x80(%rsp), %rdi
callq 0x22c0
leaq 0xa0(%rsp), %rdi
leaq 0x208(%rsp), %rsi
callq 0x20f0
movl 0x2a8(%rsp), %eax
movl %eax, 0xc0(%rsp)
movl 0x34c(%rsp), %eax
movl 0x354(%rsp), %ecx
movl %eax, 0xc4(%rsp)
incl %ecx
movl %ecx, 0xc8(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0x230(%rsp), %rsi
callq 0x20f0
leaq 0x3d8(%rsp), %rdi
leaq 0x230(%rsp), %rsi
callq 0x3c68
movl (%rax), %eax
movl %eax, 0xf0(%rsp)
movl 0x350(%rsp), %eax
movl 0x358(%rsp), %ecx
movl %eax, 0xf4(%rsp)
incl %ecx
movl %ecx, 0xf8(%rsp)
andl $0x0, 0xfc(%rsp)
leaq 0x100(%rsp), %rdi
xorl %esi, %esi
callq 0x3c36
movq 0x38(%rsp), %rdi
xorl %esi, %esi
callq 0x3c36
leaq 0x130(%rsp), %rdi
xorl %esi, %esi
callq 0x3c36
movl %r14d, %eax
andl $0x1, %eax
movl %eax, 0x34(%rsp)
movl %r14d, %eax
shrb %al
andb $0x1, %al
movb %al, 0x7(%rsp)
movl %r14d, %eax
andl $0x80, %eax
movl %eax, 0x24(%rsp)
movl %r14d, %eax
shrl $0x8, %eax
andb $0x1, %al
movl %eax, 0x30(%rsp)
movl %r14d, %eax
shrl $0x9, %eax
andb $0x1, %al
movl %eax, 0x2c(%rsp)
movl %r14d, %eax
shrl $0xa, %eax
andb $0x1, %al
movl %eax, 0x28(%rsp)
movq 0x2a0(%rsp), %rax
movq 0x2a8(%rsp), %rcx
movl 0x6c(%rsp), %edx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x32e4
movzbl (%rax,%rsi), %edi
orl $0x20, %edi
cmpl $0x6e, %edi
jne 0x32bd
incl %edx
movl %edx, 0x6c(%rsp)
incq %rsi
jmp 0x32a6
leaq 0x178(%rsp), %rdi
callq 0x20b0
movq %r14, %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x20b0
jmp 0x3a43
xorl %ebx, %ebx
xorl %r12d, %r12d
movq 0x370(%rsp), %rax
movq 0x378(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r12, %rcx
jbe 0x33c6
movl (%rax,%r12,4), %ecx
cmpl $0x8, %ecx
ja 0x3330
movl $0x185, %edx            # imm = 0x185
btl %ecx, %edx
jae 0x3330
movq 0x388(%rsp), %rcx
movl (%rcx,%r12,4), %ecx
addl %ecx, 0x60(%rsp)
movl (%rax,%r12,4), %ecx
cmpl $0x1, %ecx
jne 0x334d
incl 0x70(%rsp)
movq 0x388(%rsp), %rcx
movl (%rcx,%r12,4), %ecx
addl %ecx, 0x74(%rsp)
movl (%rax,%r12,4), %ecx
cmpl $0x2, %ecx
jne 0x336a
incl 0x78(%rsp)
movq 0x388(%rsp), %rcx
movl (%rcx,%r12,4), %ecx
addl %ecx, 0x7c(%rsp)
movl (%rax,%r12,4), %ecx
testl %ecx, %ecx
jne 0x33ba
incl 0xfc(%rsp)
movq 0x388(%rsp), %rsi
addq %rbx, %rsi
leaq 0x100(%rsp), %rdi
callq 0x3d4c
movq 0x3a0(%rsp), %rsi
addq %rbx, %rsi
movq 0x38(%rsp), %rdi
callq 0x3d4c
movq 0x3b8(%rsp), %rsi
addq %rbx, %rsi
leaq 0x130(%rsp), %rdi
callq 0x3d4c
incq %r12
addq $0x4, %rbx
jmp 0x32e9
leaq 0x80(%rsp), %rdi
leaq 0x1e05(%rip), %rsi      # 0x51da
callq 0x3bed
testb %al, %al
movq 0x4bf5(%rip), %r12      # 0x7fd8
leaq 0x1c85(%rip), %rbx      # 0x506f
je 0x3479
movl 0xc0(%rsp), %eax
subl 0xc8(%rsp), %eax
movl %eax, 0xc4(%rsp)
movq 0x108(%rsp), %rsi
movq 0x100(%rsp), %rdi
movq %rsi, %rax
subq %rdi, %rax
sarq $0x2, %rax
movq 0x118(%rsp), %rcx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x344a
movl (%rdi,%rdx,4), %r8d
addl (%rcx,%rdx,4), %r8d
movl 0xc0(%rsp), %r9d
subl %r8d, %r9d
movl %r9d, (%rcx,%rdx,4)
incq %rdx
jmp 0x3429
callq 0x499e
movq 0x118(%rsp), %rdi
movq 0x120(%rsp), %rsi
callq 0x499e
movq 0x130(%rsp), %rdi
movq 0x138(%rsp), %rsi
callq 0x499e
movl $0x1, 0x178(%rsp)
leaq 0x180(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x20f0
movl 0x254(%rsp), %eax
movl 0x298(%rsp), %ecx
decl %ecx
movl %ecx, 0x1a0(%rsp)
movl 0x29c(%rsp), %ecx
movl %ecx, 0x1a4(%rsp)
movl %eax, 0x1a8(%rsp)
movl 0x2e0(%rsp), %eax
movl 0x60(%rsp), %ecx
subl 0x64(%rsp), %ecx
movl %eax, 0x1ac(%rsp)
movl %ecx, 0x1b0(%rsp)
movl 0x34(%rsp), %eax
movb %al, 0x1b4(%rsp)
movb 0x7(%rsp), %cl
movb %cl, 0x1b5(%rsp)
movl 0x30(%rsp), %ecx
movb %cl, 0x1b6(%rsp)
movl 0x2c(%rsp), %ecx
movb %cl, 0x1b7(%rsp)
movl 0x28(%rsp), %ecx
movb %cl, 0x1b8(%rsp)
testl %eax, %eax
jne 0x352a
movl $0x1, 0x178(%rsp)
jmp 0x355a
shrl $0x6, %r14d
andl $0x1, %r14d
movl 0x24(%rsp), %ecx
testl %ecx, %ecx
pushq $0x2
popq %rax
cmovel %r14d, %eax
movl %eax, 0x178(%rsp)
shrl $0x7, %ecx
cmpl %ecx, %r14d
je 0x3ae0
testl %eax, %eax
je 0x3ae0
movq 0x4a67(%rip), %rdi      # 0x7fc8
leaq 0x1c81(%rip), %rsi      # 0x51e9
callq 0x2170
movq %rax, %rdi
leaq 0x40(%rsp), %rsi
callq 0x2160
movq %rax, %rdi
leaq 0x1aed(%rip), %rsi      # 0x5071
callq 0x2170
movl 0x60(%rsp), %esi
movq 0x4a34(%rip), %rdi      # 0x7fc8
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x64(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x68(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x6c(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x70(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x74(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x78(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x7c(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %rdi
leaq 0x80(%rsp), %rsi
callq 0x2160
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x2160
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0xc0(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0xc4(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0xc8(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %rdi
leaq 0xd0(%rsp), %rsi
callq 0x2160
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0xf0(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0xf4(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0xf8(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0xfc(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
xorl %ebx, %ebx
movq 0x100(%rsp), %rax
movq 0x108(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
jbe 0x378d
movl (%rax,%rbx,4), %esi
movq 0x4854(%rip), %rdi      # 0x7fc8
callq 0x2290
movq %rax, %rdi
leaq 0x1a68(%rip), %rsi      # 0x51eb
callq 0x2170
incq %rbx
jmp 0x374e
movq 0x4834(%rip), %rdi      # 0x7fc8
leaq 0x18d4(%rip), %rsi      # 0x506f
callq 0x2170
xorl %ebx, %ebx
movq 0x118(%rsp), %rax
movq 0x120(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
jbe 0x37e1
movl (%rax,%rbx,4), %esi
movq 0x4800(%rip), %rdi      # 0x7fc8
callq 0x2290
movq %rax, %rdi
leaq 0x1a14(%rip), %rsi      # 0x51eb
callq 0x2170
incq %rbx
jmp 0x37a2
movq 0x47e0(%rip), %rdi      # 0x7fc8
leaq 0x1880(%rip), %rsi      # 0x506f
callq 0x2170
xorl %ebx, %ebx
movq 0x130(%rsp), %rax
movq 0x138(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
jbe 0x3835
movl (%rax,%rbx,4), %esi
movq 0x47ac(%rip), %rdi      # 0x7fc8
callq 0x2290
movq %rax, %rdi
leaq 0x19c0(%rip), %rsi      # 0x51eb
callq 0x2170
incq %rbx
jmp 0x37f6
movq 0x478c(%rip), %rdi      # 0x7fc8
leaq 0x182c(%rip), %rbx      # 0x506f
movq %rbx, %rsi
callq 0x2170
movq 0x4776(%rip), %rdi      # 0x7fc8
leaq 0x1992(%rip), %rsi      # 0x51eb
callq 0x2170
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movq 0x4758(%rip), %rdi      # 0x7fc8
leaq 0x1974(%rip), %rsi      # 0x51eb
callq 0x2170
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x178(%rsp), %esi
movq 0x4733(%rip), %rdi      # 0x7fc8
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %rdi
leaq 0x180(%rsp), %rsi
callq 0x2160
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x1a0(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x1a4(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x1a8(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x1ac(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x1b0(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movzbl 0x1b4(%rsp), %ecx
leaq 0x189c(%rip), %rdx      # 0x51ed
movsbl (%rcx,%rdx), %esi
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movzbl 0x1b5(%rsp), %ecx
leaq 0x1823(%rip), %rdx      # 0x519a
movsbl (%rcx,%rdx), %esi
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movzbl 0x1b6(%rsp), %ecx
leaq 0x1853(%rip), %rdx      # 0x51f0
movsbl (%rcx,%rdx), %esi
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movzbl 0x1b7(%rsp), %ecx
leaq 0x1830(%rip), %rdx      # 0x51f3
movsbl (%rcx,%rdx), %esi
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movzbl 0x1b8(%rsp), %ecx
leaq 0x180d(%rip), %rdx      # 0x51f6
movsbl (%rcx,%rdx), %esi
movq %rax, %rdi
callq 0x21c0
movq 0x45cc(%rip), %rdi      # 0x7fc8
callq 0x20d0
movq %r13, %rdi
callq 0x3d6a
leaq 0x178(%rsp), %rdi
callq 0x3d96
leaq 0x208(%rsp), %r14
movq %r14, %rdi
callq 0x3dc2
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
callq 0x3e0e
movq %r15, %rdi
callq 0x20b0
movq %rbp, %rdi
callq 0x3e6e
leaq 0x408(%rsp), %rdi
callq 0x20c0
jmp 0x29f7
leaq 0x3d8(%rsp), %rdi
callq 0x3ece
leaq 0x40(%rsp), %rdi
callq 0x20b0
xorl %eax, %eax
addq $0x588, %rsp            # imm = 0x588
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4569(%rip), %rdi      # 0x7ff0
leaq 0x1727(%rip), %rsi      # 0x51b5
callq 0x2170
leaq 0x40(%rsp), %rsi
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x20d0
movq 0x2a8(%rsp), %rsi
movq %rax, %rdi
callq 0x2100
leaq 0x15b0(%rip), %rsi      # 0x506f
movq %rax, %rdi
callq 0x2170
movl 0x368(%rsp), %esi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
callq 0x20d0
jmp 0x3b10
movq 0x4509(%rip), %rdi      # 0x7ff0
leaq 0x16f0(%rip), %rsi      # 0x51de
callq 0x2170
movq %rax, %rdi
callq 0x20d0
leaq 0x40(%rsp), %rsi
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x20d0
pushq $0x1
popq %rdi
callq 0x21d0
jmp 0x3b28
jmp 0x3b28
jmp 0x3b28
jmp 0x3b71
movq %rax, %rbx
jmp 0x3bc1
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x20b0
leaq 0x208(%rsp), %rdi
callq 0x20b0
leaq 0x60(%rsp), %rdi
callq 0x20b0
jmp 0x3bc1
jmp 0x3b53
movq %rax, %rbx
jmp 0x3bce
jmp 0x3b64
jmp 0x3b64
jmp 0x3b64
jmp 0x3b64
jmp 0x3b64
jmp 0x3b64
movq %rax, %rbx
jmp 0x3b81
jmp 0x3b71
jmp 0x3b71
jmp 0x3b71
jmp 0x3b71
movq %rax, %rbx
leaq 0x340(%rsp), %rdi
callq 0x3d6a
leaq 0x178(%rsp), %rdi
callq 0x3d96
leaq 0x208(%rsp), %rdi
callq 0x3dc2
leaq 0x60(%rsp), %rdi
callq 0x3e0e
jmp 0x3baa
movq %rax, %rbx
leaq 0x320(%rsp), %rdi
callq 0x20b0
leaq 0x8(%rsp), %rdi
callq 0x3e6e
leaq 0x408(%rsp), %rdi
callq 0x20c0
leaq 0x3d8(%rsp), %rdi
callq 0x3ece
leaq 0x40(%rsp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x22a0