// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
leaq 0x10(%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, 0x8(%rsp)
movq $0x0, 0x10(%rax)
leaq 0x8039(%rip), %rbx      # 0xd228
movslq (%rbx), %rax
leaq (,%rax,8), %r15
testq %rax, %rax
movq $-0x1, %r13
cmovsq %r13, %r15
movq %r15, %rdi
callq 0x2030
movq %rax, %r14
movq %r15, %rdi
callq 0x2030
movq %rax, %r15
movl $0x0, 0x4(%rsp)
movl (%rbx), %eax
testl %eax, %eax
jle 0x5299
cltq
leaq (,%rax,4), %r12
testl %eax, %eax
cmovsq %r13, %r12
movq %r12, %rdi
callq 0x2030
movslq %ebp, %rbp
movq %rax, (%r14,%rbp,8)
movq %r12, %rdi
callq 0x2030
movq %rax, (%r15,%rbp,8)
cmpl $0x0, (%rbx)
jle 0x5289
xorl %eax, %eax
movslq 0x4(%rsp), %rcx
movq (%r14,%rcx,8), %rcx
movl $0x0, (%rcx,%rax,4)
movslq 0x4(%rsp), %rcx
movq (%r15,%rcx,8), %rcx
movl $0xffffffff, (%rcx,%rax,4) # imm = 0xFFFFFFFF
incq %rax
movslq (%rbx), %rcx
cmpq %rcx, %rax
jl 0x525e
movl 0x4(%rsp), %ebp
incl %ebp
movl %ebp, 0x4(%rsp)
movl (%rbx), %eax
cmpl %eax, %ebp
jl 0x522c
movq 0x8110(%rip), %rdi      # 0xd3b0
callq 0x2fd4
movq 0x8104(%rip), %rdi      # 0xd3b0
callq 0x2a74
testl %eax, %eax
je 0x53b5
leaq 0x7f54(%rip), %r12      # 0xd214
leaq 0x7f5d(%rip), %rbp      # 0xd224
movq 0x80e2(%rip), %rdi      # 0xd3b0
callq 0x2d1e
movq 0x80d6(%rip), %rdi      # 0xd3b0
callq 0x302e
movl $0x0, 0x4(%rsp)
cmpl $0x0, (%r12)
jle 0x53a1
leaq 0x7f1f(%rip), %rax      # 0xd218
movq (%rax), %rax
movq 0x7edd(%rip), %rcx      # 0xd1e0
xorl %r8d, %r8d
movb 0x7ee0(%rip), %dl       # 0xd1ec
movslq %r8d, %rsi
movslq (%rax,%rsi,4), %rsi
cmpq %rsi, %rcx
sete %r9b
movq 0x7eb7(%rip), %rdi      # 0xd1d8
cmpq %rsi, %rdi
sete %r10b
orb %r9b, %r10b
jne 0x538a
incl %r8d
cmpl (%r12), %r8d
jge 0x538a
movslq %r8d, %r8
incq %r8
xorl %r9d, %r9d
movslq -0x4(%rax,%r8,4), %r10
cmpq %r10, %rdi
jne 0x534e
decl %r9d
jmp 0x5375
incl %r9d
cmpq %r10, %rcx
je 0x5375
testb $0x1, %dl
je 0x536d
movq (%r15,%rsi,8), %r11
movl (%rbp), %r13d
cmpl %r13d, (%r11,%r10,4)
je 0x5375
movl %r13d, (%r11,%r10,4)
movq (%r14,%rsi,8), %r11
incl (%r11,%r10,4)
testl %r9d, %r9d
js 0x538a
leaq 0x1(%r8), %r10
movslq (%r12), %r11
cmpq %r11, %r8
movq %r10, %r8
jl 0x533f
movl 0x4(%rsp), %r8d
incl %r8d
movl %r8d, 0x4(%rsp)
cmpl (%r12), %r8d
jl 0x530c
movq 0x8008(%rip), %rdi      # 0xd3b0
callq 0x2a74
testl %eax, %eax
jne 0x52c7
movl $0x0, 0x4(%rsp)
cmpl $0x0, (%rbx)
jle 0x5491
cmpl $0x0, (%rbx)
jle 0x5454
xorl %ebp, %ebp
xorl %r13d, %r13d
movslq 0x4(%rsp), %r12
movq (%r14,%r12,8), %rax
movl (%rax,%rbp,4), %eax
cmpl 0x7e02(%rip), %eax      # 0xd1e8
jl 0x5447
testq %r13, %r13
jne 0x5439
movl $0x30, %edi
callq 0x21d0
movq %rax, %r13
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x10(%rax)
addq $0x18, %rax
movq %rax, 0x20(%r13)
movq %rax, 0x18(%r13)
movq %rcx, 0x28(%r13)
movq 0x8(%r13), %rsi
testq %rsi, %rsi
je 0x542c
movl %r12d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r13)
jmp 0x5439
movq %r13, %rdi
leaq 0x4(%rsp), %rdx
callq 0x3ef0
movq %r13, %rdi
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x38f0
incq %rbp
movslq (%rbx), %rax
cmpq %rax, %rbp
jl 0x53d4
jmp 0x5457
xorl %r13d, %r13d
testq %r13, %r13
je 0x547f
movl $0x18, %edi
callq 0x21d0
movq %r13, 0x10(%rax)
movq %rax, %rdi
movq 0x8(%rsp), %r12
movq %r12, %rsi
callq 0x2050
incq 0x10(%r12)
movl 0x4(%rsp), %eax
incl %eax
movl %eax, 0x4(%rsp)
cmpl (%rbx), %eax
jl 0x53c6
movl $0x0, 0x4(%rsp)
cmpl $0x0, (%rbx)
jle 0x54d1
xorl %eax, %eax
cltq
movq (%r14,%rax,8), %rdi
testq %rdi, %rdi
je 0x54b0
callq 0x2260
movslq 0x4(%rsp), %rax
movq (%r15,%rax,8), %rdi
testq %rdi, %rdi
je 0x54c3
callq 0x2260
movl 0x4(%rsp), %eax
incl %eax
movl %eax, 0x4(%rsp)
cmpl (%rbx), %eax
jl 0x54a0
movq %r14, %rdi
callq 0x2260
movq %r15, %rdi
callq 0x2260
leaq 0x10(%rsp), %rdi
callq 0x696e
movl (%rbx), %esi
imull %esi, %esi
leaq 0x7ec1(%rip), %rdi      # 0xd3b8
xorps %xmm1, %xmm1
xorl %edx, %edx
callq 0x4190
movslq (%rbx), %rax
addq $0x64, %rax
movq %rax, 0x7cc9(%rip)      # 0xd1d8
movq 0x8(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq