// File: /workspace/github_cpp_makefile_star2_O1/zakimjz[P]SLEUTH/calcdb.cpp
// Function: Dbase_Ctrl_Blk::get_valid_trans()
void Dbase_Ctrl_Blk::get_valid_trans()
{
   int i, j;
   int newTransSz;
   //const int invalid=-3; //-3 does not appear in original trans
   
   if (PvtTransAry == NULL)
      PvtTransAry = new int [MaxTransSz];
   
   //remove infreq items
   //cout << "ORIG " << endl;
   //for (i=0; i < TransSz; i++)
   //   cout << TransAry[i] << " ";
   //cout << endl;
   //cout << "ORIGV " << endl;
   //for (i=0; i < TransSz; i++)
   //   if (TransAry[i] != -1 && theFreqMap[TransAry[i]] == -1)
   //      cout << "-3 ";
   //   else   cout << TransAry[i] << " ";
   //cout << endl;
   

   for (i=0; i < TransSz; i++){      
      if (TransAry[i] != InvalidIt){
         if (TransAry[i] != BranchIt){   
            if (FreqMap[TransAry[i]] == -1){
               //set item to invalid and the next -1 to invalid
               TransAry[i] = InvalidIt;
               int cnt=0;
               
               for(j=i+1; j < TransSz && cnt >= 0; j++){
                  if (TransAry[j] != InvalidIt){
                     if (TransAry[j] == BranchIt) cnt--;
                     else cnt++;
                  }
               }
               if (!mine_induced) TransAry[--j] = InvalidIt;
            }
         }
      }
   }
   
   //cout << "VALID " << endl;
   //for (i=0; i < TransSz; i++)
   //   cout << TransAry[i] << " ";
   //cout << endl;

   //copy valid items to PvtTransAry
   if (mine_induced){
      //just copy all items (invalid, branch, regular) since we do not
      //want to count embedded occurrences as induced.
      for (i=0, newTransSz=0; i < TransSz; i++){
	 if (TransAry[i] == BranchIt || TransAry[i] == InvalidIt) 
	    PvtTransAry[newTransSz] = TransAry[i]; 
	 else PvtTransAry[newTransSz] = FreqMap[TransAry[i]];
	 newTransSz++;
      }
   }
   else{
      //eliminate invalid items and compress the tree
      for (i=0,newTransSz=0; i < TransSz; i++){
	 if (TransAry[i] != InvalidIt){
	    if (TransAry[i] == BranchIt) PvtTransAry[newTransSz] = TransAry[i];
	    else PvtTransAry[newTransSz] = FreqMap[TransAry[i]];
	    newTransSz++;
	 }
      }
   }
   TransAry = PvtTransAry;
   TransSz = newTransSz;

   //cout << "NEW " << endl;
   //for (i=0; i < TransSz; i++)
   //   cout << TransAry[i] << " ";
   //cout << endl;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
cmpq $0x0, 0xa506(%rip)      # 0xd230
jne 0x2d55
movslq 0xa4dd(%rip), %rax      # 0xd210
leaq (,%rax,4), %rcx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x2030
movq %rax, 0xa4db(%rip)      # 0xd230
cmpl $0x0, 0xa4b8(%rip)      # 0xd214
jle 0x2e09
movq 0xa4af(%rip), %rax      # 0xd218
leaq 0xa470(%rip), %rcx      # 0xd1e0
movq (%rcx), %rcx
movq 0xa48e(%rip), %rdx      # 0xd208
leaq 0xa662(%rip), %rsi      # 0xd3e3
movb (%rsi), %sil
xorl %edi, %edi
leaq 0xa44b(%rip), %r8       # 0xd1d8
movslq (%rax,%rdi,4), %r10
cmpq %r10, %rcx
sete %r11b
movq (%r8), %r9
cmpq %r10, %r9
sete %bl
orb %r11b, %bl
jne 0x2dfa
cmpl $-0x1, (%rdx,%r10,4)
jne 0x2dfa
movl %ecx, (%rax,%rdi,4)
movslq 0xa45d(%rip), %r11      # 0xd214
leaq 0x1(%rdi), %rbx
movq %rdi, %r10
cmpq %r11, %rbx
jge 0x2ded
xorl %ebx, %ebx
movq %rdi, %r10
movslq 0x4(%rax,%r10,4), %r14
cmpq %r14, %rcx
je 0x2ddd
cmpq %r14, %r9
jne 0x2ddb
decl %ebx
jmp 0x2ddd
incl %ebx
leal 0x2(%r10), %ebp
incq %r10
cmpl %ebp, %r11d
jle 0x2ded
testl %ebx, %ebx
jns 0x2dc8
testb $0x1, %sil
jne 0x2dfa
movl %r10d, %r9d
movl %ecx, (%rax,%r9,4)
incq %rdi
movslq 0xa410(%rip), %r9       # 0xd214
cmpq %r9, %rdi
jl 0x2d8d
leaq 0xa5d3(%rip), %rcx      # 0xd3e3
movl 0xa3fe(%rip), %eax      # 0xd214
cmpb $0x0, (%rcx)
je 0x2e75
testl %eax, %eax
jle 0x2ed5
movq 0xa3ee(%rip), %rcx      # 0xd218
leaq 0xa3a7(%rip), %rax      # 0xd1d8
movq (%rax), %rdx
movq 0xa3cd(%rip), %rsi      # 0xd208
movq 0xa3ee(%rip), %rdi      # 0xd230
xorl %eax, %eax
leaq 0xa395(%rip), %r8       # 0xd1e0
movl (%rcx,%rax,4), %r9d
movslq %r9d, %r10
cmpq %r10, %rdx
je 0x2e60
cmpq %r10, (%r8)
je 0x2e60
movl (%rsi,%r10,4), %r9d
movl %r9d, (%rdi,%rax,4)
incq %rax
movslq 0xa3a6(%rip), %r9       # 0xd214
cmpq %r9, %rax
jl 0x2e4b
jmp 0x2ed7
testl %eax, %eax
jle 0x2ed5
movq 0xa398(%rip), %rcx      # 0xd218
leaq 0xa359(%rip), %rax      # 0xd1e0
movq (%rax), %rdx
leaq 0xa347(%rip), %rax      # 0xd1d8
movq (%rax), %rsi
movq 0xa36d(%rip), %rdi      # 0xd208
xorl %r8d, %r8d
movq 0xa38b(%rip), %r9       # 0xd230
xorl %eax, %eax
movl (%rcx,%r8,4), %r10d
movslq %r10d, %r11
cmpq %r11, %rdx
je 0x2ec4
cmpq %r11, %rsi
je 0x2ebc
movl (%rdi,%r11,4), %r10d
cltq
movl %r10d, (%r9,%rax,4)
incl %eax
incq %r8
movslq 0xa346(%rip), %r10      # 0xd214
cmpq %r10, %r8
jl 0x2ea7
jmp 0x2ed7
xorl %eax, %eax
movq 0xa352(%rip), %rcx      # 0xd230
movq %rcx, 0xa333(%rip)      # 0xd218
movl %eax, 0xa329(%rip)      # 0xd214
popq %rbx
popq %r14
popq %rbp
retq