// File: 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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, 0x1b3ec(%rip)     # 0x1e220
jne 0x2e65
movslq 0x1b3c3(%rip), %rax     # 0x1e200
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, 0x1b3bb(%rip)     # 0x1e220
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl 0x1b38f(%rip), %eax     # 0x1e204
jge 0x2fc3
movq 0x1b386(%rip), %rax     # 0x1e208
movslq -0xc(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
leaq 0x1b337(%rip), %rcx     # 0x1e1c8
cmpq (%rcx), %rax
je 0x2fb3
movq 0x1b367(%rip), %rax     # 0x1e208
movslq -0xc(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
leaq 0x1b310(%rip), %rcx     # 0x1e1c0
cmpq (%rcx), %rax
je 0x2fb1
movq 0x1b338(%rip), %rax     # 0x1e1f8
movq 0x1b341(%rip), %rcx     # 0x1e208
movslq -0xc(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
cmpl $-0x1, (%rax,%rcx,4)
jne 0x2faf
leaq 0x1b2e8(%rip), %rax     # 0x1e1c8
movq (%rax), %rax
movl %eax, %edx
movq 0x1b31c(%rip), %rax     # 0x1e208
movslq -0xc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x18(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %ecx
xorl %eax, %eax
cmpl 0x1b2f6(%rip), %ecx     # 0x1e204
movb %al, -0x19(%rbp)
jge 0x2f1d
cmpl $0x0, -0x18(%rbp)
setge %al
movb %al, -0x19(%rbp)
movb -0x19(%rbp), %al
testb $0x1, %al
jne 0x2f26
jmp 0x2f7f
movq 0x1b2db(%rip), %rax     # 0x1e208
movslq -0x10(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
leaq 0x1b28c(%rip), %rcx     # 0x1e1c8
cmpq (%rcx), %rax
je 0x2f72
movq 0x1b2c0(%rip), %rax     # 0x1e208
movslq -0x10(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
leaq 0x1b269(%rip), %rcx     # 0x1e1c0
cmpq (%rcx), %rax
jne 0x2f67
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x2f70
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x2f72
jmp 0x2f74
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x2f03
leaq 0x1b44d(%rip), %rax     # 0x1e3d3
testb $0x1, (%rax)
jne 0x2fad
leaq 0x1b236(%rip), %rax     # 0x1e1c8
movq (%rax), %rax
movl %eax, %edx
movq 0x1b26a(%rip), %rax     # 0x1e208
movl -0x10(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x10(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x2faf
jmp 0x2fb1
jmp 0x2fb3
jmp 0x2fb5
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x2e6c
leaq 0x1b409(%rip), %rax     # 0x1e3d3
testb $0x1, (%rax)
je 0x3087
movl $0x0, -0xc(%rbp)
movl $0x0, -0x14(%rbp)
movl -0xc(%rbp), %eax
cmpl 0x1b21a(%rip), %eax     # 0x1e204
jge 0x3082
movq 0x1b211(%rip), %rax     # 0x1e208
movslq -0xc(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
leaq 0x1b1ba(%rip), %rcx     # 0x1e1c0
cmpq (%rcx), %rax
je 0x3026
movq 0x1b1f6(%rip), %rax     # 0x1e208
movslq -0xc(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
leaq 0x1b1a7(%rip), %rcx     # 0x1e1c8
cmpq (%rcx), %rax
jne 0x3044
movq 0x1b1db(%rip), %rax     # 0x1e208
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x1b1e5(%rip), %rax     # 0x1e220
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x306b
movq 0x1b1ad(%rip), %rax     # 0x1e1f8
movq 0x1b1b6(%rip), %rcx     # 0x1e208
movslq -0xc(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %edx
movq 0x1b1bc(%rip), %rax     # 0x1e220
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x2fe1
jmp 0x313a
movl $0x0, -0xc(%rbp)
movl $0x0, -0x14(%rbp)
movl -0xc(%rbp), %eax
cmpl 0x1b166(%rip), %eax     # 0x1e204
jge 0x3138
movq 0x1b15d(%rip), %rax     # 0x1e208
movslq -0xc(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
leaq 0x1b10e(%rip), %rcx     # 0x1e1c8
cmpq (%rcx), %rax
je 0x3128
movq 0x1b142(%rip), %rax     # 0x1e208
movslq -0xc(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
leaq 0x1b0eb(%rip), %rcx     # 0x1e1c0
cmpq (%rcx), %rax
jne 0x30f8
movq 0x1b127(%rip), %rax     # 0x1e208
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x1b131(%rip), %rax     # 0x1e220
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x311f
movq 0x1b0f9(%rip), %rax     # 0x1e1f8
movq 0x1b102(%rip), %rcx     # 0x1e208
movslq -0xc(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %edx
movq 0x1b108(%rip), %rax     # 0x1e220
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x312a
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x3095
jmp 0x313a
movq 0x1b0df(%rip), %rax     # 0x1e220
movq %rax, 0x1b0c0(%rip)     # 0x1e208
movl -0x14(%rbp), %eax
movl %eax, 0x1b0b3(%rip)     # 0x1e204
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)