// File: /workspace/github_cpp_makefile_star2_O2/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), %rdi
movb $0x0, 0x20(%rdi)
callq 0x605c
pushq $0x18
popq %rdi
callq 0x2170
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq %rax, 0x10(%rsp)
andq $0x0, 0x10(%rax)
leaq 0x85fc(%rip), %r12      # 0xd1f8
movslq (%r12), %r13
leaq (,%r13,8), %rax
testq %r13, %r13
pushq $-0x1
popq %rbx
cmovnsq %rax, %rbx
movq %rbx, %rdi
callq 0x2030
movq %rax, %r14
movq %rbx, %rdi
callq 0x2030
movq %rax, %r15
movl (%r12), %ebp
xorl %eax, %eax
movq %r14, 0x18(%rsp)
cmpl %r13d, %eax
jge 0x4c97
movslq %r13d, %r12
shlq $0x2, %r12
movq %r12, %rdi
movq %rax, %r14
callq 0x2030
movq %rax, %rbx
movq %r14, 0x28(%rsp)
movl %r14d, %eax
movq %rax, 0x20(%rsp)
movq 0x18(%rsp), %r14
movq %rbx, (%r14,%rax,8)
movq %r12, %rdi
callq 0x2030
movq 0x20(%rsp), %rcx
movq %rax, (%r15,%rcx,8)
xorl %ecx, %ecx
movslq %r13d, %rdx
cmpq %rdx, %rcx
jge 0x4c8e
andl $0x0, (%rbx,%rcx,4)
orl $-0x1, (%rax,%rcx,4)
incq %rcx
movl %ebp, %r13d
jmp 0x4c76
movq 0x28(%rsp), %rax
incl %eax
jmp 0x4c33
movq 0x86e2(%rip), %rdi      # 0xd380
callq 0x2c32
movq 0x86d6(%rip), %rdi      # 0xd380
callq 0x2790
testl %eax, %eax
je 0x4d79
movq 0x86c2(%rip), %rdi      # 0xd380
callq 0x29fa
movq 0x86b6(%rip), %rdi      # 0xd380
callq 0x2c92
leaq 0x8512(%rip), %rax      # 0xd1e8
movq (%rax), %rax
movq 0x84c8(%rip), %rcx      # 0xd1a8
movb 0x84ce(%rip), %dl       # 0xd1b4
leaq 0x84f7(%rip), %rsi      # 0xd1e4
movl (%rsi), %edi
xorl %esi, %esi
movl %esi, 0x4(%rsp)
cmpl %edi, %esi
jge 0x4ca3
movl %esi, %r8d
movslq (%rax,%r8,4), %r9
cmpq %r9, %rcx
sete %r11b
movq 0x8492(%rip), %r10      # 0xd1a0
cmpq %r9, %r10
sete %bl
orb %r11b, %bl
je 0x4d1d
incl %esi
jmp 0x4cf1
xorl %r11d, %r11d
movslq %edi, %rbx
leaq 0x84ca(%rip), %r12      # 0xd1f4
movl (%r12), %ebp
incq %r8
testl %r11d, %r11d
js 0x4d19
cmpq %rbx, %r8
jge 0x4d19
movslq (%rax,%r8,4), %r12
cmpq %r12, %r10
jne 0x4d49
decl %r11d
jmp 0x4d2e
incl %r11d
cmpq %r12, %rcx
je 0x4d2e
testb $0x1, %dl
je 0x4d66
movq (%r15,%r9,8), %r13
cmpl %ebp, (%r13,%r12,4)
je 0x4d2e
movl %ebp, (%r13,%r12,4)
movq (%r14,%r9,8), %rdi
incl (%rdi,%r12,4)
leaq 0x846f(%rip), %rdi      # 0xd1e4
movl (%rdi), %edi
jmp 0x4d20
leaq 0x8478(%rip), %rax      # 0xd1f8
movl (%rax), %eax
xorl %ecx, %ecx
pushq $0x30
popq %r12
leaq 0x4(%rsp), %r13
leaq 0x8(%rsp), %rbp
movl %ecx, 0x4(%rsp)
cmpl %eax, %ecx
jge 0x4e47
andq $0x0, 0x8(%rsp)
xorl %ebx, %ebx
movslq %eax, %rcx
cmpq %rcx, %rbx
jge 0x4e1e
movslq 0x4(%rsp), %rcx
movq (%r14,%rcx,8), %rcx
movl (%rcx,%rbx,4), %ecx
cmpl 0x83f0(%rip), %ecx      # 0xd1b0
jl 0x4e19
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
jne 0x4e05
movq %r12, %rdi
callq 0x2170
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
leaq 0x18(%rax), %rcx
movq %rcx, 0x20(%rax)
movq %rcx, 0x18(%rax)
andq $0x0, 0x28(%rax)
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %r13, %rsi
callq 0x3a04
movq 0x8(%rsp), %rdi
movl %ebx, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3548
leaq 0x83e1(%rip), %rax      # 0xd1f8
movl (%rax), %eax
incq %rbx
jmp 0x4da6
cmpq $0x0, 0x8(%rsp)
je 0x4e3c
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x6100
leaq 0x83be(%rip), %rax      # 0xd1f8
movl (%rax), %eax
movl 0x4(%rsp), %ecx
incl %ecx
jmp 0x4d92
xorl %ecx, %ecx
movl %ecx, 0x4(%rsp)
cmpl %eax, %ecx
jge 0x4e88
movslq %ecx, %rax
movq (%r14,%rax,8), %rdi
testq %rdi, %rdi
je 0x4e69
callq 0x21e0
movl 0x4(%rsp), %ecx
movslq %ecx, %rax
movq (%r15,%rax,8), %rdi
testq %rdi, %rdi
je 0x4e7b
callq 0x21e0
movl 0x4(%rsp), %ecx
incl %ecx
leaq 0x8374(%rip), %rax      # 0xd1f8
movl (%rax), %eax
jmp 0x4e49
movq %r14, %rdi
callq 0x21e0
movq %r15, %rdi
callq 0x21e0
leaq 0x30(%rsp), %rdi
callq 0x60a2
leaq 0x834f(%rip), %rbx      # 0xd1f8
movl (%rbx), %esi
imull %esi, %esi
leaq 0x84d3(%rip), %rdi      # 0xd388
xorps %xmm1, %xmm1
xorl %edx, %edx
callq 0x3e16
movslq (%rbx), %rax
addq $0x64, %rax
movq %rax, 0x82d3(%rip)      # 0xd1a0
movq 0x10(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq