// File: zakimjz[P]SLEUTH/treeminer.cpp
// Function: get_F2[abi:cxx11]()
list<Eqclass *> * get_F2()
{
  int i,j;
  int it1, it2;
  int scnt;
  
  TimeTracker tt;
  double te;

  tt.Start();

  list<Eqclass *> *F2list = new list<Eqclass *>;

  //itcnt2 is a matrix of pairs p, p.first is count, p.second is flag
  int **itcnt2 = new int*[DCB->NumF1];
  int **flgs = new int*[DCB->NumF1];
  //unsigned int **itcnt2 = new unsigned int *[DCB->NumF1];
  for (i=0; i < DCB->NumF1; i++){
    itcnt2[i] = new int [DCB->NumF1];
    flgs[i] = new int [DCB->NumF1];
    //cout << "alloc " << i << " " << itcnt2[i] << endl;
    for (j=0; j < DCB->NumF1; j++){
      itcnt2[i][j] = 0;
      flgs[i][j] = -1;
    }
  }
    
   DCB->alloc_idlists();
   
   while(DCB->get_next_trans())
   {
      DCB->get_valid_trans();
      DCB->make_vertical();
      //DCB->print_trans();
      //count a pair only once per cid
      for (i=0; i < DCB->TransSz; i++){
         it1 = DCB->TransAry[i];
	 if (it1 == InvalidIt) continue;
         if (it1 != BranchIt){
            scnt = 0;
            for (j=i+1; scnt >= 0 && j < DCB->TransSz; j++){
               it2 = DCB->TransAry[j];
               if (it2 != BranchIt){
		 scnt++;
		 if (it2 == InvalidIt) continue;
		 if (count_unique){
		   if (flgs[it1][it2] == DCB->Cid) continue;
		   else flgs[it1][it2] = DCB->Cid;
		 }
		 //cout << "cnt " << it1 << " " << it2 << endl;
		 itcnt2[it1][it2]++;
               }
               else scnt--;
            }
         }
      }
   }                           
   
   int F2cnt=0;

   // count frequent patterns and generate eqclass
   Eqclass *eq;
   for (i=0; i < DCB->NumF1; i++) {
      eq = NULL;
      for (j=0; j < DCB->NumF1; ++j) {
	//cout << "access " << i << " " << j << endl;
         if (itcnt2[i][j] >= MINSUPPORT){
            F2cnt++;
            if (eq == NULL){
               eq = new Eqclass;
               eq->prefix().push_back(i);
            }
	    eq->add_node(j,0);
            
	    //if (output) 
	    //  cout << DCB->FreqIdx[i] << " " << DCB->FreqIdx[j] 
	    //	   << " - " << itcnt2[i][j] << endl;
         }
      }   
      if (eq != NULL) F2list->push_back(eq);
   }
   
   for (i=0; i < DCB->NumF1; i++) {
     //cout << "dealloc " << i << " " << itcnt2[i] << endl;
     delete [] itcnt2[i];
     //cout << "dealloc " << i << " " << flgs[i] << endl;
     delete [] flgs[i];
   }

   delete [] itcnt2;
   delete [] flgs;
   
   
   //cout << "F2 - " << F2cnt << " " << DCB->NumF1 * DCB->NumF1 << endl;
   te = tt.Stop();
   stats.add(DCB->NumF1 * DCB->NumF1, 0, te);

   BranchIt = DCB->NumF1+100; //make branchit more than all other items
   return F2list;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
leaq -0x40(%rbp), %rdi
callq 0xbe90
leaq -0x40(%rbp), %rdi
callq 0xbf30
movl $0x18, %edi
callq 0x2170
movq %rax, %rdi
movq %rdi, -0x78(%rbp)
callq 0xc100
movq -0x78(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x14606(%rip), %rax     # 0x1e218
movslq (%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x58(%rbp)
leaq 0x145d7(%rip), %rax     # 0x1e218
movslq (%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x60(%rbp)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
leaq 0x1459e(%rip), %rcx     # 0x1e218
cmpl (%rcx), %eax
jge 0x9d54
leaq 0x1458f(%rip), %rax     # 0x1e218
movslq (%rax), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rdx
movq -0x58(%rbp), %rax
movslq -0x4(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
leaq 0x14555(%rip), %rax     # 0x1e218
movslq (%rax), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rdx
movq -0x60(%rbp), %rax
movslq -0x4(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x14511(%rip), %rcx     # 0x1e218
cmpl (%rcx), %eax
jge 0x9d44
movq -0x58(%rbp), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x8(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x60(%rbp), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x8(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x9cfd
jmp 0x9d46
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x9c70
movq 0x14645(%rip), %rdi     # 0x1e3a0
callq 0x3220
movq 0x14639(%rip), %rdi     # 0x1e3a0
callq 0x2a30
cmpl $0x0, %eax
je 0x9ee1
movq 0x14624(%rip), %rdi     # 0x1e3a0
callq 0x2e20
movq 0x14618(%rip), %rdi     # 0x1e3a0
callq 0x32a0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
leaq 0x14466(%rip), %rcx     # 0x1e204
cmpl (%rcx), %eax
jge 0x9edc
leaq 0x1445b(%rip), %rax     # 0x1e208
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rax
cmpq 0x14403(%rip), %rax     # 0x1e1c8
jne 0x9dcc
jmp 0x9ece
movslq -0xc(%rbp), %rax
cmpq 0x143e9(%rip), %rax     # 0x1e1c0
je 0x9ecc
movl $0x0, -0x14(%rbp)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0x79(%rbp)
jl 0x9e0a
movl -0x8(%rbp), %eax
leaq 0x14402(%rip), %rcx     # 0x1e204
cmpl (%rcx), %eax
setl %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x9e16
jmp 0x9eca
leaq 0x143eb(%rip), %rax     # 0x1e208
movq (%rax), %rax
movslq -0x8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x10(%rbp)
movslq -0x10(%rbp), %rax
cmpq 0x1438b(%rip), %rax     # 0x1e1c0
je 0x9eb1
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movslq -0x10(%rbp), %rax
cmpq 0x1437d(%rip), %rax     # 0x1e1c8
jne 0x9e4f
jmp 0x9ebc
testb $0x1, 0x1437e(%rip)     # 0x1e1d4
je 0x9e96
movq -0x60(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %eax
leaq 0x143a2(%rip), %rcx     # 0x1e214
cmpl (%rcx), %eax
jne 0x9e78
jmp 0x9ebc
leaq 0x14395(%rip), %rax     # 0x1e214
movl (%rax), %edx
movq -0x60(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x9e96
movq -0x58(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x9eba
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x9ebc
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x9ded
jmp 0x9ecc
jmp 0x9ece
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x9d94
jmp 0x9d60
movl $0x0, -0x64(%rbp)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
leaq 0x1431f(%rip), %rcx     # 0x1e218
cmpl (%rcx), %eax
jge 0x9fca
movq $0x0, -0x70(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x142fe(%rip), %rcx     # 0x1e218
cmpl (%rcx), %eax
jge 0x9fa6
movq -0x58(%rbp), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl 0x14295(%rip), %eax     # 0x1e1d0
jl 0x9f96
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x9f86
movl $0x30, %edi
callq 0x2170
movq %rax, %rdi
movq %rdi, -0x88(%rbp)
callq 0xc120
movq -0x88(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0xc150
movq %rax, %rdi
leaq -0x4(%rbp), %rsi
callq 0x67c0
movq -0x70(%rbp), %rdi
movl -0x8(%rbp), %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x5c60
jmp 0x9f98
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x9f10
cmpq $0x0, -0x70(%rbp)
je 0x9fba
movq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xc160
jmp 0x9fbc
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x9eef
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
leaq 0x1423d(%rip), %rcx     # 0x1e218
cmpl (%rcx), %eax
jge 0xa036
movq -0x58(%rbp), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0xa004
movq -0x90(%rbp), %rdi
callq 0x21f0
movq -0x60(%rbp), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, %rax
je 0xa029
movq -0x98(%rbp), %rdi
callq 0x21f0
jmp 0xa02b
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x9fd1
movq -0x58(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, %rax
je 0xa053
movq -0xa0(%rbp), %rdi
callq 0x21f0
movq -0x60(%rbp), %rax
movq %rax, -0xa8(%rbp)
cmpq $0x0, %rax
je 0xa070
movq -0xa8(%rbp), %rdi
callq 0x21f0
leaq -0x40(%rbp), %rdi
callq 0xc060
movsd %xmm0, -0x48(%rbp)
leaq 0x14193(%rip), %rax     # 0x1e218
movl (%rax), %esi
leaq 0x1418a(%rip), %rax     # 0x1e218
imull (%rax), %esi
movsd -0x48(%rbp), %xmm0
leaq 0x1430b(%rip), %rdi     # 0x1e3a8
xorl %edx, %edx
xorps %xmm1, %xmm1
callq 0x7dd0
leaq 0x1416a(%rip), %rax     # 0x1e218
movl (%rax), %eax
addl $0x64, %eax
cltq
movq %rax, 0x14104(%rip)     # 0x1e1c0
movq -0x50(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)