// File: zakimjz[P]SLEUTH/treeminer.cpp
// Function: get_F1()
void get_F1()
{
  TimeTracker tt;
  double te;

  int i, j, it;
  const int arysz = 10;
  
  vector<int> itcnt(arysz,0); //count item frequency
  vector<int> flgs(arysz,-1);

  tt.Start();

  DBASE_MAXITEM=0;
  DBASE_NUM_TRANS = 0;
  
   while(DCB->get_next_trans())
   {
      //cout << "TRANS " << DCB->Cid << " " << DCB->Tid
      //     << " " << DCB->TransSz << " -- ";
      //for (i=0; i < DCB->TransSz; i++)
      //   cout << " " << DCB->TransAry[i];
      //cout << endl;
      
      for (i=0; i < DCB->TransSz; i++){
         it = DCB->TransAry[i];
         if (it == BranchIt) continue;
         
         if (it >= DBASE_MAXITEM){
            itcnt.resize(it+1,0);
            flgs.resize(it+1,-1);
            DBASE_MAXITEM = it+1;
            //cout << "IT " << DBASE_MAXITEM << endl;
         }
         
         if (count_unique){
            if(flgs[it] == DCB->Cid) continue;
            else flgs[it] = DCB->Cid;
         }
         itcnt[it]++;
      }
      
      if (DCB->MaxTransSz < DCB->TransSz) DCB->MaxTransSz = DCB->TransSz;     
      DBASE_NUM_TRANS++;
   }
   
   //for (i=0; i < DCB->TransSz; i++){
   //   it = DCB->TransAry[i];
   //   if (it != BranchIt){
   //      cout << it << " " << itcnt[it] << endl;
   //   }
   //}

   //set the value of MINSUPPORT
   if (MINSUPPORT == -1)
     MINSUPPORT = (int) (MINSUP_PER*DBASE_NUM_TRANS+0.5);
   
   if (MINSUPPORT<1) MINSUPPORT=1;
   cout<<"DBASE_NUM_TRANS : "<< DBASE_NUM_TRANS << endl;
   cout<<"DBASE_MAXITEM : "<< DBASE_MAXITEM << endl;
   cout<<"MINSUPPORT : "<< MINSUPPORT << " (" << MINSUP_PER << ")" << endl;

   //count number of frequent items
   DCB->NumF1 = 0;
   for (i=0; i < DBASE_MAXITEM; i++)
     if (itcnt[i] >= MINSUPPORT)
       DCB->NumF1++;

   int *it_order = new int[DBASE_MAXITEM];
   for (i=0; i < DBASE_MAXITEM; i++)
      it_order[i] = i;
   
   if (sort_type != nosort){
      ITCNT = &itcnt;
      sort(&it_order[0], &it_order[DBASE_MAXITEM], F1cmp);
   }

   //construct forward and reverse mapping from items to freq items
   DCB->FreqIdx = new int [DCB->NumF1];
   DCB->FreqMap = new int [DBASE_MAXITEM];
   for (i=0,j=0; i < DBASE_MAXITEM; i++) {
      if (itcnt[it_order[i]] >= MINSUPPORT) {
         //if (output) cout << i << " " << it_order[i] 
         //                 << " - " << itcnt[it_order[i]] << endl;
         if (output) cout << it_order[i] 
                          << " - " << itcnt[it_order[i]] << endl;
         DCB->FreqIdx[j] = it_order[i];
         DCB->FreqMap[it_order[i]] = j;
         j++;
      }
      else DCB->FreqMap[it_order[i]] = -1;
   }
   
   //cout<< "F1 - " << DCB->NumF1 << " " << DBASE_MAXITEM << endl;  
   
   if (sort_type != nosort){
      ITCNT = NULL;
      delete [] it_order;
   }
   
   te = tt.Stop();
   stats.add(DBASE_MAXITEM, DCB->NumF1, te);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
leaq -0x28(%rbp), %rdi
callq 0xbe90
movl $0xa, -0x40(%rbp)
movl $0x0, -0x5c(%rbp)
leaq -0x5d(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x39d0
movq -0xa8(%rbp), %rcx
leaq -0x58(%rbp), %rdi
movl $0xa, %esi
leaq -0x5c(%rbp), %rdx
callq 0xbeb0
jmp 0x94ad
leaq -0x5d(%rbp), %rdi
callq 0x4c40
movl $0xffffffff, -0x8c(%rbp) # imm = 0xFFFFFFFF
leaq -0x8d(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x39d0
movq -0xb0(%rbp), %rcx
leaq -0x88(%rbp), %rdi
movl $0xa, %esi
leaq -0x8c(%rbp), %rdx
callq 0xbeb0
jmp 0x94f4
leaq -0x8d(%rbp), %rdi
callq 0x4c40
leaq -0x28(%rbp), %rdi
callq 0xbf30
jmp 0x950b
movl $0x0, 0x14eb3(%rip)     # 0x1e3c8
movl $0x0, 0x14ead(%rip)     # 0x1e3cc
movq 0x14e7a(%rip), %rdi     # 0x1e3a0
callq 0x2a30
movl %eax, -0xb4(%rbp)
jmp 0x9533
movl -0xb4(%rbp), %eax
cmpl $0x0, %eax
je 0x96e4
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
leaq 0x14cb1(%rip), %rcx     # 0x1e204
cmpl (%rcx), %eax
jge 0x96aa
leaq 0x14ca6(%rip), %rax     # 0x1e208
movq (%rax), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rbp)
movslq -0x3c(%rbp), %rax
cmpq 0x14c46(%rip), %rax     # 0x1e1c0
jne 0x95d5
jmp 0x969c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x5d(%rbp), %rdi
callq 0x4c40
jmp 0x9bc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x8d(%rbp), %rdi
callq 0x4c40
jmp 0x9bba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x3a30
jmp 0x9bba
movl -0x3c(%rbp), %eax
cmpl 0x14dea(%rip), %eax     # 0x1e3c8
jl 0x9637
movl -0x3c(%rbp), %eax
incl %eax
movslq %eax, %rsi
movl $0x0, -0x94(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x94(%rbp), %rdx
callq 0xbf60
jmp 0x9604
movl -0x3c(%rbp), %eax
incl %eax
movslq %eax, %rsi
movl $0xffffffff, -0x98(%rbp) # imm = 0xFFFFFFFF
leaq -0x88(%rbp), %rdi
leaq -0x98(%rbp), %rdx
callq 0xbf60
jmp 0x962b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, 0x14d91(%rip)     # 0x1e3c8
testb $0x1, 0x14b96(%rip)     # 0x1e1d4
je 0x9688
movslq -0x3c(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x6520
movl (%rax), %eax
leaq 0x14bbb(%rip), %rcx     # 0x1e214
cmpl (%rcx), %eax
jne 0x965f
jmp 0x969c
leaq 0x14bae(%rip), %rax     # 0x1e214
movl (%rax), %eax
movl %eax, -0xb8(%rbp)
movslq -0x3c(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x6520
movl -0xb8(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x9688
movslq -0x3c(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x6520
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x9549
leaq 0x14b4f(%rip), %rax     # 0x1e200
movl (%rax), %eax
leaq 0x14b4a(%rip), %rcx     # 0x1e204
cmpl (%rcx), %eax
jge 0x96d0
leaq 0x14b3f(%rip), %rax     # 0x1e204
movl (%rax), %ecx
leaq 0x14b32(%rip), %rax     # 0x1e200
movl %ecx, (%rax)
movl 0x14cf6(%rip), %eax     # 0x1e3cc
addl $0x1, %eax
movl %eax, 0x14ced(%rip)     # 0x1e3cc
jmp 0x951f
cmpl $-0x1, 0x14ae5(%rip)    # 0x1e1d0
jne 0x9717
movsd 0x14ccb(%rip), %xmm0    # 0x1e3c0
cvtsi2sdl 0x14ccf(%rip), %xmm1 # 0x1e3cc
mulsd %xmm1, %xmm0
movsd 0xaa67(%rip), %xmm1     # 0x14170
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x14ab9(%rip)     # 0x1e1d0
cmpl $0x1, 0x14ab2(%rip)     # 0x1e1d0
jge 0x972a
movl $0x1, 0x14aa6(%rip)     # 0x1e1d0
movq 0x1489f(%rip), %rdi     # 0x1dfd0
leaq 0xaac1(%rip), %rsi      # 0x141f9
callq 0x2160
movq %rax, -0xc0(%rbp)
jmp 0x9746
movq -0xc0(%rbp), %rdi
movl 0x14c79(%rip), %esi     # 0x1e3cc
callq 0x22b0
movq %rax, -0xc8(%rbp)
jmp 0x9761
movq -0xc8(%rbp), %rdi
movq 0x14849(%rip), %rsi     # 0x1dfb8
callq 0x2190
jmp 0x9776
movq 0x14853(%rip), %rdi     # 0x1dfd0
leaq 0xaa88(%rip), %rsi      # 0x1420c
callq 0x2160
movq %rax, -0xd0(%rbp)
jmp 0x9792
movq -0xd0(%rbp), %rdi
movl 0x14c29(%rip), %esi     # 0x1e3c8
callq 0x22b0
movq %rax, -0xd8(%rbp)
jmp 0x97ad
movq -0xd8(%rbp), %rdi
movq 0x147fd(%rip), %rsi     # 0x1dfb8
callq 0x2190
jmp 0x97c2
movq 0x14807(%rip), %rdi     # 0x1dfd0
leaq 0xaa4d(%rip), %rsi      # 0x1421d
callq 0x2160
movq %rax, -0xe0(%rbp)
jmp 0x97de
movq -0xe0(%rbp), %rdi
movl 0x149e5(%rip), %esi     # 0x1e1d0
callq 0x22b0
movq %rax, -0xe8(%rbp)
jmp 0x97f9
movq -0xe8(%rbp), %rdi
leaq 0xaa24(%rip), %rsi      # 0x1422b
callq 0x2160
movq %rax, -0xf0(%rbp)
jmp 0x9815
movq -0xf0(%rbp), %rdi
movsd 0x14b9c(%rip), %xmm0    # 0x1e3c0
callq 0x2320
movq %rax, -0xf8(%rbp)
jmp 0x9832
movq -0xf8(%rbp), %rdi
leaq 0xaa9c(%rip), %rsi      # 0x142dc
callq 0x2160
movq %rax, -0x100(%rbp)
jmp 0x984e
movq -0x100(%rbp), %rdi
movq 0x1475c(%rip), %rsi     # 0x1dfb8
callq 0x2190
jmp 0x9863
leaq 0x149ae(%rip), %rax     # 0x1e218
movl $0x0, (%rax)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x14b48(%rip), %eax     # 0x1e3c8
jge 0x98bb
movslq -0x34(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x6520
movl (%rax), %eax
cmpl 0x14939(%rip), %eax     # 0x1e1d0
jl 0x98ae
leaq 0x14978(%rip), %rax     # 0x1e218
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x1496c(%rip), %rax     # 0x1e218
movl %ecx, (%rax)
jmp 0x98b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x9877
movslq 0x14b06(%rip), %rax     # 0x1e3c8
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x2030
movq %rax, -0x108(%rbp)
jmp 0x98e6
movq -0x108(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x14ac4(%rip), %eax     # 0x1e3c8
jge 0x9922
movl -0x34(%rbp), %edx
movq -0xa0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x98fb
cmpl $0x0, 0x14aaf(%rip)     # 0x1e3d8
je 0x9958
leaq -0x58(%rbp), %rax
movq %rax, 0x14aca(%rip)     # 0x1e400
movq -0xa0(%rbp), %rdi
movslq 0x14a84(%rip), %rax     # 0x1e3c8
leaq (%rdi,%rax,4), %rsi
leaq -0x6ff(%rip), %rdx      # 0x9250
callq 0xc010
jmp 0x9956
jmp 0x9958
leaq 0x148b9(%rip), %rax     # 0x1e218
movslq (%rax), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x2030
movq %rax, -0x110(%rbp)
jmp 0x9986
movq -0x110(%rbp), %rcx
leaq 0x1485c(%rip), %rax     # 0x1e1f0
movq %rcx, (%rax)
movslq 0x14a2a(%rip), %rax     # 0x1e3c8
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x2030
movq %rax, -0x118(%rbp)
jmp 0x99c2
movq -0x118(%rbp), %rcx
leaq 0x14828(%rip), %rax     # 0x1e1f8
movq %rcx, (%rax)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x149de(%rip), %eax     # 0x1e3c8
jge 0x9b21
movq -0xa0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movslq (%rax,%rcx,4), %rsi
leaq -0x58(%rbp), %rdi
callq 0x6520
movl (%rax), %eax
cmpl 0x147c0(%rip), %eax     # 0x1e1d0
jl 0x9af1
testb $0x1, 0x149b3(%rip)     # 0x1e3d0
je 0x9aa8
movq -0xa0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movq 0x14598(%rip), %rdi     # 0x1dfd0
callq 0x22b0
movq %rax, -0x120(%rbp)
jmp 0x9a46
movq -0x120(%rbp), %rdi
leaq 0xa62c(%rip), %rsi      # 0x14080
callq 0x2160
movq %rax, -0x128(%rbp)
jmp 0x9a62
movq -0xa0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movslq (%rax,%rcx,4), %rsi
leaq -0x58(%rbp), %rdi
callq 0x6520
movq -0x128(%rbp), %rdi
movl (%rax), %esi
callq 0x22b0
movq %rax, -0x130(%rbp)
jmp 0x9a91
movq -0x130(%rbp), %rdi
movq 0x14519(%rip), %rsi     # 0x1dfb8
callq 0x2190
jmp 0x9aa6
jmp 0x9aa8
movq -0xa0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x14733(%rip), %rax     # 0x1e1f0
movq (%rax), %rax
movslq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %edx
leaq 0x14727(%rip), %rax     # 0x1e1f8
movq (%rax), %rax
movq -0xa0(%rbp), %rcx
movslq -0x34(%rbp), %rsi
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x9b11
leaq 0x14700(%rip), %rax     # 0x1e1f8
movq (%rax), %rax
movq -0xa0(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x9b13
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x99e1
cmpl $0x0, 0x148b0(%rip)     # 0x1e3d8
je 0x9b57
movq $0x0, 0x148cb(%rip) # 0x1e400
movq -0xa0(%rbp), %rax
movq %rax, -0x138(%rbp)
cmpq $0x0, %rax
je 0x9b55
movq -0x138(%rbp), %rdi
callq 0x21f0
jmp 0x9b57
leaq -0x28(%rbp), %rdi
callq 0xc060
movsd %xmm0, -0x140(%rbp)
jmp 0x9b6a
movsd -0x140(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl 0x1484b(%rip), %esi     # 0x1e3c8
leaq 0x14694(%rip), %rax     # 0x1e218
movl (%rax), %edx
movsd -0x30(%rbp), %xmm0
leaq 0x14816(%rip), %rdi     # 0x1e3a8
xorps %xmm1, %xmm1
callq 0x7dd0
jmp 0x9b9c
leaq -0x88(%rbp), %rdi
callq 0x3a30
leaq -0x58(%rbp), %rdi
callq 0x3a30
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x3a30
movq -0x68(%rbp), %rdi
callq 0x22d0
nopl (%rax)