// File: /workspace/github_c_makefile_star2_O2/ComplexNetworks-DCC-FCUP[P]gtrieScanner/GTrie.cpp
// Function: GTrieNode::insertConditionsFiltered(std::__cxx11::list<std::pair<int, int>, std::allocator<std::pair<int, int>>>*)
void GTrieNode::insertConditionsFiltered(list<iPair> *conditions) {

  // Already has "empty set" of conditions
  if (cond_ok && cond_this_ok) return;

  list<iPair> aux;
  list<int>   aux_this_node;
  list<iPair>::iterator jj, kk;
  iPair p;


  /*for (jj=conditions->begin(); jj!=conditions->end(); jj++)
    printf("%d < %d  |  ", jj->first, jj->second);
    putchar('\n');*/
  

  // A bit slow but works (search a<b and b<c: remove a<c)
  for (jj=conditions->begin(); jj!=conditions->end(); jj++)
    for (kk=conditions->begin(); kk!=conditions->end(); kk++)
      if (jj->second == kk->first) {
	p.first  = jj->first;
	p.second = kk->second;
	conditions->remove(p); // does not invalidade jj and kk
      }

  /*for (jj=conditions->begin(); jj!=conditions->end(); jj++)
    printf("%d < %d  |  ", jj->first, jj->second);
    putchar('\n');*/

  for (jj=conditions->begin(); jj!=conditions->end(); jj++) {
    if (max(jj->first, jj->second)<=depth-1) // HERE!
      aux.push_back(*jj);
    if (jj->second == depth-1)
      aux_this_node.push_back(jj->first);
 } 

  // Deal with ancestor conditions
  if (!cond_ok) {

    if (aux.size()==0) {
      cond_ok = true;
      cond.clear();
    } else {

      list< list<iPair> >::iterator mm;
      bool is_contained = false;
      // A bit slow, but saves a lot of conditions
      for (mm=cond.begin(); mm!=cond.end();) {
	if (_is_pairset_included(*mm, aux)) {
	  is_contained = true;
	  break;
	}
	else if (_is_pairset_included(aux, *mm)) {
	  //printf("Erasing old condition (ancestors) !!\n");
	  mm = cond.erase(mm);
	  if (mm == cond.end()) break;
	}
	else mm++;
      }

      if (!is_contained) cond.push_back(aux);
      //else printf("avoid insertion (ancestors)!\n");
    }
  }

  return;

 // Deal with this node conditions {
  if (!cond_this_ok) {
    
    if (aux_this_node.size()==0) {
      cond_this_ok = true;
      this_node_cond.clear();
      } else {
    
      list< list<int> >::iterator mm;

      bool is_contained = false;
      // A bit slow, but saves a lot of conditions
      for (mm=this_node_cond.begin(); mm!=this_node_cond.end(); mm++) {
        if (_is_intset_included(*mm, aux_this_node)) {
            is_contained = true;
            break;
        }
        if (_is_intset_included(aux_this_node, *mm)) {
          //printf("Erasing old condition (this_node) !!\n");
          mm = this_node_cond.erase(mm);
       }
      }

      if (!is_contained) this_node_cond.push_back(aux_this_node);
      //else printf("avoid insertion (this_node)!\n");      
    }
  }

   
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r14
movq %rdi, %rbx
cmpb $0x1, 0x48(%rdi)
jne 0x85ad
cmpb $0x0, 0x49(%rbx)
jne 0x878c
leaq 0x8(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x20(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
movq %rsp, %r15
andq $0x0, (%r15)
movq %r14, %r12
movq (%r12), %r12
movq %r14, %r13
cmpq %r14, %r12
je 0x8616
movq (%r13), %r13
cmpq %r14, %r13
je 0x85d9
movl 0x14(%r12), %eax
cmpl 0x10(%r13), %eax
jne 0x85e5
movl 0x10(%r12), %eax
movl %eax, (%rsp)
movl 0x14(%r13), %eax
movl %eax, 0x4(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xa338
jmp 0x85e5
leaq 0x8(%rsp), %r15
leaq 0x20(%rsp), %r12
movq %r14, %rbp
movq (%rbp), %rbp
cmpq %r14, %rbp
je 0x8666
leaq 0x10(%rbp), %r13
movl 0x10(%rbp), %edx
movl 0x14(%rbp), %eax
cmpl %eax, %edx
cmovlel %eax, %edx
movl 0x4c(%rbx), %ecx
cmpl %ecx, %edx
jge 0x8653
movq %r15, %rdi
movq %r13, %rsi
callq 0x6666
movl 0x14(%rbp), %eax
movl 0x4c(%rbx), %ecx
decl %ecx
cmpl %ecx, %eax
jne 0x8623
movq %r12, %rdi
movq %r13, %rsi
callq 0xa3a8
jmp 0x8623
cmpb $0x0, 0x48(%rbx)
jne 0x8778
cmpq $0x0, 0x18(%rsp)
je 0x8768
addq $0x18, %rbx
leaq 0x50(%rsp), %r14
leaq 0x8(%rsp), %rbp
movq %rbx, %r12
movq (%r12), %r12
cmpq %rbx, %r12
je 0x8759
leaq 0x10(%r12), %r13
leaq 0x68(%rsp), %rdi
movq %r13, %rsi
callq 0xa3b4
movq %r14, %rdi
movq %rbp, %r15
movq %rbp, %rsi
callq 0xa3b4
leaq 0x68(%rsp), %rbp
movq %rbp, %rsi
movq %r14, %rdx
callq 0x8804
movq %r14, %rdi
movl %eax, %r14d
callq 0x67ea
movq %rbp, %rdi
callq 0x67ea
testb %r14b, %r14b
jne 0x8778
leaq 0x38(%rsp), %rdi
movq %r15, %rbp
movq %r15, %rsi
callq 0xa3b4
leaq 0x80(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0xa3b4
leaq 0x38(%rsp), %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x8804
movl %eax, %r13d
movq %r14, %rdi
callq 0x67ea
movq %r15, %rdi
callq 0x67ea
testb %r13b, %r13b
je 0x874f
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa3ee
movq %rax, %r12
cmpq %rbx, %rax
leaq 0x50(%rsp), %r14
jne 0x8691
jmp 0x8759
leaq 0x50(%rsp), %r14
jmp 0x868d
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0xa3fc
jmp 0x8778
movb $0x1, 0x48(%rbx)
addq $0x18, %rbx
movq %rbx, %rdi
callq 0xa2fc
leaq 0x20(%rsp), %rdi
callq 0xa562
leaq 0x8(%rsp), %rdi
callq 0x67ea
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x87bd
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x87b2
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x67ea
jmp 0x87c0
jmp 0x87bd
jmp 0x87bd
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xa562
leaq 0x8(%rsp), %rdi
callq 0x67ea
movq %rbx, %rdi
callq 0x23b0