// File: /workspace/github_c_makefile_star2_O3/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 0x8c36
cmpb $0x0, 0x49(%rdi)
jne 0x8f50
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), %r13
cmpq %r14, %r13
je 0x8cb0
leaq 0x48(%rsp), %r15
movq (%r14), %r12
cmpq %r14, %r12
je 0x8ca4
movl 0x14(%r13), %eax
cmpl 0x10(%r12), %eax
jne 0x8c9e
movl 0x10(%r13), %eax
movl %eax, 0x48(%rsp)
movl 0x14(%r12), %eax
movl %eax, 0x4c(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xae26
movq (%r12), %r12
jmp 0x8c72
movq (%r13), %r13
cmpq %r14, %r13
jne 0x8c6f
movq (%r14), %r13
cmpq %r14, %r13
je 0x8d3a
leaq 0x28(%rsp), %r15
leaq 0x10(%rsp), %r12
movl 0x10(%r13), %edx
movl 0x14(%r13), %eax
cmpl %eax, %edx
cmovlel %eax, %edx
movq 0x8(%rsp), %rcx
movl 0x4c(%rcx), %ecx
cmpl %ecx, %edx
jge 0x8d0a
movl $0x18, %edi
callq 0x21f0
movq 0x10(%r13), %rcx
movq %rcx, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2070
incq 0x38(%rsp)
movl 0x14(%r13), %eax
movq 0x8(%rsp), %rcx
movl 0x4c(%rcx), %ecx
decl %ecx
cmpl %ecx, %eax
jne 0x8d31
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 0x8cc3
movq 0x8(%rsp), %rax
cmpb $0x0, 0x48(%rax)
jne 0x8f03
cmpq $0x0, 0x38(%rsp)
je 0x8edd
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %rcx
movq 0x18(%rax), %rax
movq %rcx, 0x40(%rsp)
cmpq %rcx, %rax
je 0x8eb5
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 0xaeca
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0xaeca
movq %r14, %rsi
movq %r13, %rdx
callq 0x904a
movb %al, 0x7(%rsp)
movq 0xa0(%rsp), %rdi
cmpq %r13, %rdi
je 0x8ddc
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r13, %rbx
jne 0x8dc7
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x8dfb
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x8de6
cmpb $0x0, 0x7(%rsp)
leaq 0x10(%rsp), %rbx
jne 0x8f03
movq %r12, %rdi
leaq 0x28(%rsp), %rsi
callq 0xaeca
movq %r15, %rdi
movq %rbp, %rsi
callq 0xaeca
movq %r12, %rsi
movq %r15, %rdx
callq 0x904a
movb %al, 0x7(%rsp)
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x8e54
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r15, %rbx
jne 0x8e3f
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x8e73
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r12, %rbx
jne 0x8e5e
movq 0x50(%rsp), %rsi
movq (%rsi), %rbp
cmpb $0x0, 0x7(%rsp)
leaq 0x10(%rsp), %rbx
je 0x8ea7
movq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0xb0c6
movq %rbp, %rax
cmpq %rbx, %rbp
leaq 0x10(%rsp), %rbx
jne 0x8d8a
jmp 0x8eb5
movq %rbp, %rax
cmpq 0x40(%rsp), %rbp
jne 0x8d8a
leaq 0x28(%rsp), %rsi
movq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0xb10e
movq %rax, %rdi
movq %r14, %rsi
callq 0x2070
movq 0x8(%rsp), %rax
incq 0x28(%rax)
jmp 0x8f03
movq 0x8(%rsp), %r15
movb $0x1, 0x48(%r15)
leaq 0x18(%r15), %r14
movq %r14, %rdi
callq 0xafd4
movq %r14, 0x20(%r15)
movq %r14, 0x18(%r15)
movq $0x0, 0x28(%r15)
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8f27
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rbx
jne 0x8f0d
movq 0x28(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x8f50
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rbx
jne 0x8f36
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8fb5
movq %rax, %r15
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x8faa
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r12, %rbx
jne 0x8f71
jmp 0x8faa
movq %rax, %r15
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x8faa
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x8f95
leaq 0x10(%rsp), %rbx
jmp 0x8fb8
jmp 0x8fb5
jmp 0x8fb5
movq %rax, %r15
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8fdc
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rbx
jne 0x8fc2
movq 0x28(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x9005
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2200
movq %rbx, %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rbx
jne 0x8feb
movq %r15, %rdi
callq 0x2370
nop