// File: fukunagatsu[P]LogicomeProfiler/logicome_profiler.cpp
// Function: LogicomeProfiler::FirstScreeningForFWER()
void LogicomeProfiler::FirstScreeningForFWER(){
  int N = _number_of_samples;
  
  long long int count = 0;
  long long int ne = _number_of_elements;
  long long int max_size_count = 4*ne*(ne-1)*(ne-2); 
  double bf_threshold = _alpha/max_size_count;
  _result_vector.reserve(10000);

  for(int c = 0; c < _number_of_elements; c++){
    for(int a = 0; a < _number_of_elements; a++){
      if(a!=c){
	for(int b = 0; b < _number_of_elements; b++){
	  if(b!=a && b!=c){
	    for(int l = 1; l <=6; l++){
	      if(l>=5 || a < b){
		count++;
		int x = _logic_occurrence_tensor[a][b][l];
		int y = _count_vector[c];
		int z = CountLogicOccurrence(a,b,c,l);
		double prob = CalcProb(x,y,z,N,bf_threshold);
		
		if(prob < bf_threshold){
		  Node new_node(a,b,c,l,prob);
		  _result_vector.push_back(new_node);
		}

		if(count%1000000 == 0){
		  cout << count<< "/" << max_size_count << " " << _result_vector.size() << endl;
		}
	      }
	    }
	  }
	}
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x78(%rbp)
movl 0x100(%rdi), %eax
movl %eax, -0xc(%rbp)
movq $0x0, -0x18(%rbp)
movslq 0x104(%rdi), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
shlq $0x2, %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
imulq %rcx, %rax
movq -0x20(%rbp), %rcx
subq $0x2, %rcx
imulq %rcx, %rax
movq %rax, -0x28(%rbp)
movsd 0x108(%rdi), %xmm0
cvtsi2sdq -0x28(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
addq $0x48, %rdi
movl $0x2710, %esi           # imm = 0x2710
callq 0x8510
movl $0x0, -0x34(%rbp)
movq -0x78(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0x104(%rcx), %eax
jge 0x5572
movl $0x0, -0x38(%rbp)
movq -0x78(%rbp), %rcx
movl -0x38(%rbp), %eax
cmpl 0x104(%rcx), %eax
jge 0x5562
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x5552
movl $0x0, -0x3c(%rbp)
movq -0x78(%rbp), %rcx
movl -0x3c(%rbp), %eax
cmpl 0x104(%rcx), %eax
jge 0x5550
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0x5540
movl -0x3c(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x5540
movl $0x1, -0x40(%rbp)
cmpl $0x6, -0x40(%rbp)
jg 0x553e
cmpl $0x5, -0x40(%rbp)
jge 0x53f1
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x552e
movq -0x78(%rbp), %rdi
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movslq -0x38(%rbp), %rsi
callq 0x8680
movq %rax, %rdi
movslq -0x3c(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x40(%rbp), %rsi
callq 0x86c0
movq -0x78(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x44(%rbp)
addq $0x30, %rdi
movslq -0x34(%rbp), %rsi
callq 0x86c0
movq -0x78(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
movl -0x34(%rbp), %ecx
movl -0x40(%rbp), %r8d
callq 0x6e90
movq -0x78(%rbp), %rdi
movl %eax, -0x4c(%rbp)
movl -0x44(%rbp), %esi
movl -0x48(%rbp), %edx
movl -0x4c(%rbp), %ecx
movl -0xc(%rbp), %r8d
movsd -0x30(%rbp), %xmm0
callq 0x74d0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x54b2
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
movl -0x34(%rbp), %ecx
movl -0x40(%rbp), %r8d
movsd -0x58(%rbp), %xmm0
leaq -0x70(%rbp), %rdi
callq 0x8700
movq -0x78(%rbp), %rdi
addq $0x48, %rdi
leaq -0x70(%rbp), %rsi
callq 0x8770
movq -0x18(%rbp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x552c
movq -0x18(%rbp), %rsi
movq 0x1bb07(%rip), %rdi     # 0x20fd8
callq 0x2140
movq %rax, %rdi
leaq 0x10bb9(%rip), %rsi     # 0x16099
callq 0x2230
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x10bb2(%rip), %rsi     # 0x160ad
callq 0x2230
movq -0x78(%rbp), %rdi
movq %rax, -0x80(%rbp)
addq $0x48, %rdi
callq 0x87e0
movq -0x80(%rbp), %rdi
movq %rax, %rsi
callq 0x2080
movq %rax, %rdi
movq 0x1baa1(%rip), %rsi     # 0x20fc8
callq 0x2260
jmp 0x552e
jmp 0x5530
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x53d5
jmp 0x5540
jmp 0x5542
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x53a3
jmp 0x5552
jmp 0x5554
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x537d
jmp 0x5564
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5363
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)