// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
leaq 0x30(%rsp), %rbx
movb $0x0, 0x20(%rbx)
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x22d0
movb $0x1, 0x20(%rbx)
movl $0x18, %edi
callq 0x21d0
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq %rax, 0x18(%rsp)
movq $0x0, 0x10(%rax)
leaq 0x8022(%rip), %rax      # 0xd228
movslq (%rax), %r13
leaq (,%r13,8), %r15
testq %r13, %r13
movq $-0x1, %rax
cmovsq %rax, %r15
movq %r15, %rdi
callq 0x2030
movq %rax, %r14
movq %r15, %rdi
callq 0x2030
movq %rax, 0x8(%rsp)
testq %r13, %r13
jle 0x52cb
leaq 0x7fe1(%rip), %rax      # 0xd228
movl (%rax), %eax
movl %eax, 0x14(%rsp)
movslq %eax, %rbx
movq %r13, 0x20(%rsp)
movslq %r13d, %r15
leaq (,%r15,4), %r13
testl %r15d, %r15d
movq $-0x1, %rax
cmovsq %rax, %r13
movq %r13, %rdi
callq 0x2030
movq %rax, %r12
movq %rbp, 0x28(%rsp)
movl %ebp, %ebp
movq %rax, (%r14,%rbp,8)
movq %r13, %rdi
movq 0x20(%rsp), %r13
callq 0x2030
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
testl %r15d, %r15d
jle 0x52bf
xorl %ecx, %ecx
movl $0x0, (%r12,%rcx,4)
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
incq %rcx
cmpq %rbx, %rcx
jl 0x52a1
movl 0x14(%rsp), %eax
movl %eax, %r13d
movq 0x28(%rsp), %rbp
incl %ebp
cmpl %r13d, %ebp
jl 0x5250
movq 0x80de(%rip), %rdi      # 0xd3b0
callq 0x2fa2
movq 0x80d2(%rip), %rdi      # 0xd3b0
callq 0x2a5e
testl %eax, %eax
je 0x53d2
leaq 0x7f22(%rip), %r12      # 0xd214
movq 0x80b7(%rip), %rdi      # 0xd3b0
callq 0x2d0c
movq 0x80ab(%rip), %rdi      # 0xd3b0
callq 0x2ffc
movl (%r12), %ecx
testl %ecx, %ecx
jle 0x53be
leaq 0x7efb(%rip), %rax      # 0xd218
movq (%rax), %rax
movq 0x7eb9(%rip), %rdx      # 0xd1e0
xorl %esi, %esi
movl $0x2, %edi
movb 0x7eb7(%rip), %r8b      # 0xd1ec
movl %esi, %r9d
movslq (%rax,%r9,4), %r9
incl %esi
cmpq %r9, %rdx
je 0x53b3
movq 0x7e8e(%rip), %r10      # 0xd1d8
cmpq %r9, %r10
je 0x53b3
cmpl %ecx, %esi
jge 0x53b3
xorl %r11d, %r11d
movq %rdi, %rbx
movslq -0x4(%rax,%rbx,4), %r13
cmpq %r13, %r10
jne 0x5368
decl %r11d
jmp 0x539f
incl %r11d
cmpq %r13, %rdx
je 0x539f
testb $0x1, %r8b
je 0x5393
movq 0x8(%rsp), %r15
movq (%r15,%r9,8), %r15
leaq 0x7e9e(%rip), %rbp      # 0xd224
movl (%rbp), %ebp
cmpl %ebp, (%r15,%r13,4)
je 0x539f
movl %ebp, (%r15,%r13,4)
movq (%r14,%r9,8), %rcx
incl (%rcx,%r13,4)
movl (%r12), %ecx
testl %r11d, %r11d
js 0x53b3
leaq 0x1(%rbx), %r15
movslq %ecx, %r13
cmpq %r13, %rbx
movq %r15, %rbx
jl 0x5359
incq %rdi
cmpl %ecx, %esi
jl 0x5335
movq 0x7feb(%rip), %rdi      # 0xd3b0
callq 0x2a5e
testl %eax, %eax
jne 0x52f2
movl $0x0, 0x4(%rsp)
leaq 0x7e47(%rip), %rax      # 0xd228
movl (%rax), %eax
testl %eax, %eax
jle 0x5504
xorl %ebx, %ebx
leaq 0x4(%rsp), %r12
movq 0x18(%rsp), %r15
testl %eax, %eax
jle 0x54a4
movl 0x7de3(%rip), %ecx      # 0xd1e8
xorl %ebp, %ebp
xorl %r13d, %r13d
movslq 0x4(%rsp), %rdx
movq (%r14,%rdx,8), %rdx
cmpl %ecx, (%rdx,%rbp,4)
jl 0x546e
testq %r13, %r13
jne 0x5451
movl $0x30, %edi
callq 0x21d0
movq %rax, %r13
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rbx, 0x10(%rax)
addq $0x18, %rax
movq %rax, 0x20(%r13)
movq %rax, 0x18(%r13)
movq %rbx, 0x28(%r13)
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x3e9a
movq %r13, %rdi
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3890
movl 0x7d83(%rip), %ecx      # 0xd1e8
leaq 0x7dbc(%rip), %rax      # 0xd228
movl (%rax), %eax
incq %rbp
movslq %eax, %rdx
cmpq %rdx, %rbp
jl 0x540a
testq %r13, %r13
je 0x54a4
movl $0x18, %edi
callq 0x21d0
movq %r13, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2050
incq 0x10(%r15)
leaq 0x7d86(%rip), %rax      # 0xd228
movl (%rax), %eax
movl 0x4(%rsp), %ecx
incl %ecx
movl %ecx, 0x4(%rsp)
cmpl %eax, %ecx
jl 0x53f7
movl $0x0, 0x4(%rsp)
testl %eax, %eax
jle 0x5504
xorl %eax, %eax
movslq %eax, %rcx
movq (%r14,%rcx,8), %rdi
testq %rdi, %rdi
je 0x54dc
callq 0x2260
movl 0x4(%rsp), %eax
movslq %eax, %rcx
movq 0x8(%rsp), %rdx
movq (%rdx,%rcx,8), %rdi
testq %rdi, %rdi
je 0x54f3
callq 0x2260
movl 0x4(%rsp), %eax
incl %eax
movl %eax, 0x4(%rsp)
leaq 0x7d28(%rip), %rcx      # 0xd228
cmpl (%rcx), %eax
jl 0x54c4
movq %r14, %rdi
callq 0x2260
movq 0x8(%rsp), %rdi
callq 0x2260
leaq 0x30(%rsp), %rdi
callq 0x6994
leaq 0x7d01(%rip), %rbx      # 0xd228
movl (%rbx), %esi
imull %esi, %esi
leaq 0x7e85(%rip), %rdi      # 0xd3b8
xorps %xmm1, %xmm1
xorl %edx, %edx
callq 0x4140
movslq (%rbx), %rax
addq $0x64, %rax
movq %rax, 0x7c8d(%rip)      # 0xd1d8
movq 0x18(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq