// File: /workspace/github_c_makefile_star2_O1/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 $0xb8, %rsp
movq %rsi, %r14
cmpb $0x1, 0x48(%rdi)
jne 0x8aac
cmpb $0x0, 0x49(%rdi)
jne 0x8dbe
movq %rdi, 0x8(%rsp)
leaq 0x28(%rsp), %rcx
movq %rcx, 0x8(%rcx)
movq %rcx, (%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
leaq 0x10(%rsp), %rbx
movq %rbx, 0x8(%rbx)
movq %rbx, (%rbx)
movq %rax, 0x10(%rbx)
movq %rax, 0x48(%rsp)
movq (%r14), %r12
cmpq %r14, %r12
je 0x8b23
leaq 0x48(%rsp), %r15
movq (%r14), %r13
cmpq %r14, %r13
je 0x8b1a
movl 0x14(%r12), %eax
cmpl 0x10(%r13), %eax
jne 0x8b14
movl 0x10(%r12), %eax
movl %eax, 0x48(%rsp)
movl 0x14(%r13), %eax
movl %eax, 0x4c(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xacbc
movq (%r13), %r13
jmp 0x8ae8
movq (%r12), %r12
cmpq %r14, %r12
jne 0x8ae5
movq (%r14), %r13
cmpq %r14, %r13
je 0x8ba8
leaq 0x28(%rsp), %r15
leaq 0x10(%rsp), %r12
movl 0x10(%r13), %eax
movl 0x14(%r13), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movq 0x8(%rsp), %rax
cmpl 0x4c(%rax), %ecx
jge 0x8b6e
movl $0x18, %edi
callq 0x21f0
movq 0x10(%r13), %rcx
movq %rcx, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2070
incq 0x38(%rsp)
movq 0x8(%rsp), %rax
movl 0x4c(%rax), %eax
decl %eax
cmpl %eax, 0x14(%r13)
jne 0x8b9f
movl $0x18, %edi
callq 0x21f0
movl 0x10(%r13), %ecx
movl %ecx, 0x10(%rax)
movq %rax, %rdi
movq %r12, %rsi
callq 0x2070
incq 0x20(%rsp)
movq (%r13), %r13
cmpq %r14, %r13
jne 0x8b35
movq 0x8(%rsp), %rax
cmpb $0x0, 0x48(%rax)
jne 0x8d71
cmpq $0x0, 0x38(%rsp)
je 0x8d4b
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %rcx
movq 0x18(%rax), %rax
movq %rcx, 0x40(%rsp)
cmpq %rcx, %rax
je 0x8d23
leaq 0x70(%rsp), %r14
leaq 0xa0(%rsp), %r13
leaq 0x58(%rsp), %r12
leaq 0x88(%rsp), %r15
movq %rax, 0x50(%rsp)
leaq 0x10(%rax), %rbp
movq %r14, %rdi
movq %rbp, %rsi
callq 0xad54
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0xad54
movq %r14, %rsi
movq %r13, %rdx
callq 0x8eb8
movb %al, 0x7(%rsp)
movq 0xa0(%rsp), %rdi
cmpq %r13, %rdi
je 0x8c4a
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r13, %rbx
jne 0x8c35
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x8c69
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x8c54
cmpb $0x0, 0x7(%rsp)
leaq 0x10(%rsp), %rbx
jne 0x8d71
movq %r12, %rdi
leaq 0x28(%rsp), %rsi
callq 0xad54
movq %r15, %rdi
movq %rbp, %rsi
callq 0xad54
movq %r12, %rsi
movq %r15, %rdx
callq 0x8eb8
movb %al, 0x7(%rsp)
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x8cc2
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r15, %rbx
jne 0x8cad
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x8ce1
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r12, %rbx
jne 0x8ccc
movq 0x50(%rsp), %rsi
movq (%rsi), %rbp
cmpb $0x0, 0x7(%rsp)
leaq 0x10(%rsp), %rbx
je 0x8d15
movq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0xaf50
movq %rbp, %rax
cmpq %rbx, %rbp
leaq 0x10(%rsp), %rbx
jne 0x8bf8
jmp 0x8d23
movq %rbp, %rax
cmpq 0x40(%rsp), %rbp
jne 0x8bf8
leaq 0x28(%rsp), %rsi
movq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0xaf98
movq %rax, %rdi
movq %r14, %rsi
callq 0x2070
movq 0x8(%rsp), %rax
incq 0x28(%rax)
jmp 0x8d71
movq 0x8(%rsp), %r15
movb $0x1, 0x48(%r15)
leaq 0x18(%r15), %r14
movq %r14, %rdi
callq 0xae5e
movq %r14, 0x20(%r15)
movq %r14, 0x18(%r15)
movq $0x0, 0x28(%r15)
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8d95
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rbx
jne 0x8d7b
movq 0x28(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x8dbe
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rbx
jne 0x8da4
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8e23
movq %rax, %r15
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x8e18
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r12, %rbx
jne 0x8ddf
jmp 0x8e18
movq %rax, %r15
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x8e18
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x8e03
leaq 0x10(%rsp), %rbx
jmp 0x8e26
jmp 0x8e23
jmp 0x8e23
movq %rax, %r15
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8e4a
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rbx
jne 0x8e30
movq 0x28(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x8e73
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rbx
jne 0x8e59
movq %r15, %rdi
callq 0x2370
nop