// File: /workspace/github_cpp_makefile_star2_O1/manschga[P]M5GB/M5GB.cpp
// Function: Update_pairs(Lab_poly const&, std::vector<polynomial, std::allocator<polynomial>> const&, int, int&)
void Update_pairs(const Lab_poly& F, const vector<polynomial>& system, const int n, int& BB_counter)
{
  //cout << "pair update: " << LT_G.size() << endl;
  for (auto& it : LT_G) 
    {
      //cout << Generations_G.find(it.first)->second << endl;
      if (Generations_G.find(it.first)->second <= n) //do not add spols coming from field equations!
	{
	  //cout << "Field equation detected!" << endl;
	  continue;
	}      
      
      if (First_Buchberger(table[F.Get_LT()].first,table[it.first].first))
	{
	  //inefficient!
	  /*
	  pair<Lab_poly,Lab_poly> Spair = spair(F,Lab_poly(G_.find(it.first)->second,it.second));
	  Lab_poly Spol = Spair.first-Spair.second;
	  H[Spol.Get_sign().Get_index()].emplace_back(Spol.Get_sign().Get_term());
	  */
	  BB_counter ++;
	  continue;
	}
     
      //*/
      pair<Lab_poly,Lab_poly> Spair = spair(F,Lab_poly(G_.find(it.first)->second,it.second));
      pair<pair<Lab_poly,int>,pair<Lab_poly,int>> spair_gen = make_pair(make_pair(Spair.first,G_.size()+1),make_pair(Spair.second,Generations_G.find(it.first)->second));
      if (Spair.first.Get_sign() == Spair.second.Get_sign()) // remove pair if same signature! Get counter for statistic
	{
	  continue;
	  //cout << "singular pair!" << endl;
	}
      else
	{
	  if (Spair.first.Get_sign() < Spair.second.Get_sign()) 
	    {
	      //change order to ensure first > second
	      Spair = make_pair(Spair.second,Spair.first);
	      spair_gen = make_pair(spair_gen.second,spair_gen.first);
	    }
	  //insert correctly

	  Spol_sign.insert(Spair.first.Get_sign()); //not efficient, only inserted when signature not yet in
	  Spairs_map.insert(make_pair(Spair.first.Get_sign(),spair_gen.first)); //not efficient, only inserted when signature not yet in
	  //auto correct_insert = P.insert(Spair);
	  /*
	  if (!correct_insert.second)
	    {
	      std::cout << "Failed to insert element!" << std::endl;
	      cout << Spair.first.Get_sign() << endl;
	      for (auto it = P.begin(); it != P.end(); ++it)
		{
		  cout << it->first.Get_sign() << endl;
		}
	      
	    }
	  */
	}
    }

      
#ifdef DEBUG
    for (auto it = P.begin(); it != P.end(); ++it)
    {
      cout << it->first.Get_sign() << ","  << it->second.Get_sign() << endl;
    }
#endif

  //cout << "size of P after update: " << P.size() << endl;
  return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rcx, 0x108(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x110d2(%rip), %r12     # 0x1a258
testq %r12, %r12
je 0x9765
movl %edx, %ebp
leaq 0x11200(%rip), %r14     # 0x1a398
leaq 0x10fc9(%rip), %r15     # 0x1a168
movl %edx, 0x4(%rsp)
leaq 0x8(%r12), %rbx
movq 0x8(%r12), %rcx
movq %rcx, %rax
xorl %edx, %edx
divq 0x111e7(%rip)           # 0x1a3a0
movq %r14, %rdi
movq %rdx, %rsi
movq %rbx, %rdx
callq 0xe1a2
movq (%rax), %rax
cmpl %ebp, 0x10(%rax)
jle 0x9758
movq 0x8(%rsp), %rdi
callq 0xc69a
cltq
movq (%r15), %rcx
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq %rcx, %rdi
movq (%rbx), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
addq %rcx, %rsi
callq 0xb39d
testb %al, %al
je 0x9213
movq 0x108(%rsp), %rax
incl (%rax)
jmp 0x9758
movq %r14, %r15
leaq 0xb8(%rsp), %r14
movq (%rbx), %rcx
movq %rcx, %rax
xorl %edx, %edx
divq 0x11093(%rip)           # 0x1a2c0
leaq 0x11084(%rip), %rdi     # 0x1a2b8
movq %rdx, %rsi
movq %rbx, %rdx
callq 0xdd4a
movl $0x0, %r13d
testq %rax, %rax
je 0x924d
movq (%rax), %r13
leaq 0x10(%r13), %rsi
leaq 0x190(%rsp), %rbp
movq %rbp, %rdi
callq 0x6314
movl 0x28(%r13), %eax
movl %eax, 0x1a8(%rsp)
movl 0x10(%r12), %edx
movq 0x18(%r12), %rcx
leaq 0x110(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4bf0
leaq 0x98(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
callq 0x4ee5
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x92bb
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x190(%rsp), %rdi
testq %rdi, %rdi
je 0x92d8
movq 0x1a0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x10ff1(%rip), %r13     # 0x1a2d0
leaq 0x10(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x6314
incq %r13
movl 0xb0(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x10(%r14), %eax
leaq 0x30(%rsp), %rdx
movl %eax, 0x10(%rdx)
movups (%r14), %xmm0
movups %xmm0, (%rdx)
movq %r13, 0x48(%rsp)
movq (%rbx), %rcx
movq %rcx, %rax
xorl %edx, %edx
divq 0x1107a(%rip)           # 0x1a3a0
movq %r15, %rdi
movq %rdx, %rsi
movq %rbx, %rdx
callq 0xe1a2
testq %rax, %rax
je 0x933e
movq (%rax), %rbx
jmp 0x9340
xorl %ebx, %ebx
leaq 0x1b0(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x6314
movl 0xe8(%rsp), %eax
movl %eax, 0x1c8(%rsp)
leaq 0xf0(%rsp), %r9
movl 0x10(%r9), %ecx
leaq 0x1d0(%rsp), %rdx
movl %ecx, 0x10(%rdx)
movups (%r9), %xmm0
movups %xmm0, (%rdx)
movl 0x10(%rbx), %ecx
movl %ecx, 0x1e8(%rsp)
movaps 0x10(%rsp), %xmm0
movq 0x20(%rsp), %rdx
movl $0x0, %r10d
movq %r10, 0x20(%rsp)
xorps %xmm2, %xmm2
movaps %xmm2, 0x10(%rsp)
movl 0x28(%rsp), %esi
movl 0x48(%rsp), %edi
movaps 0x1b0(%rsp), %xmm1
movq 0x1c0(%rsp), %r8
movaps %xmm2, 0x1b0(%rsp)
movq %r10, 0x1c0(%rsp)
movups %xmm0, 0x110(%rsp)
movq %rdx, 0x120(%rsp)
movl %esi, 0x128(%rsp)
leaq 0x30(%rsp), %r10
movups (%r10), %xmm0
leaq 0x130(%rsp), %rsi
movups %xmm0, (%rsi)
movl 0x10(%r10), %edx
movl %edx, 0x10(%rsi)
movl %edi, 0x148(%rsp)
movups %xmm1, 0x150(%rsp)
movq %r8, 0x160(%rsp)
movl %eax, 0x168(%rsp)
movl 0x10(%r9), %eax
movl %eax, 0x50(%rsi)
movups (%r9), %xmm0
movups %xmm0, 0x40(%rsi)
movl %ecx, 0x188(%rsp)
movq 0x1b0(%rsp), %rdi
testq %rdi, %rdi
je 0x9453
movq 0x1c0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
leaq 0x10(%rsp), %rbx
je 0x946f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movl 0xb8(%rsp), %eax
movl 0xf0(%rsp), %ecx
cmpl %ecx, %eax
movq %r15, %r14
leaq 0x10cdf(%rip), %r15     # 0x1a168
movl 0x4(%rsp), %ebp
jne 0x94a5
movq 0xc0(%rsp), %rdx
cmpq 0xf8(%rsp), %rdx
je 0x96e4
movq 0xc0(%rsp), %rdx
xorl %esi, %esi
cmpl %ecx, %eax
setl %sil
xorl %eax, %eax
cmpq 0xf8(%rsp), %rdx
setl %al
cmovel %esi, %eax
testb %al, %al
je 0x965b
movq %rbx, %rdi
leaq 0xd0(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0xcf14
movq 0x98(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movq 0x10(%rsp), %rax
movq %rax, 0x98(%rsp)
movups 0x18(%rsp), %xmm0
movups %xmm0, 0xa0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0x952d
subq %rdi, %rsi
callq 0x2180
movl 0x28(%rsp), %eax
movl %eax, 0xb0(%rsp)
leaq 0x30(%rsp), %rdx
movl 0x10(%rdx), %eax
leaq 0xb8(%rsp), %rcx
movl %eax, 0x10(%rcx)
movups (%rdx), %xmm0
movups %xmm0, (%rcx)
movq 0xd0(%rsp), %rdi
movq 0xd8(%rsp), %rax
movq 0xe0(%rsp), %rsi
movq 0x48(%rsp), %rcx
movq %rcx, 0xd0(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, 0xd8(%rsp)
movq %rdi, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movq %rsi, 0x58(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rdx)
movq $0x0, 0x28(%rdx)
testq %rdi, %rdi
je 0x95ae
subq %rdi, %rsi
callq 0x2180
movl 0x60(%rsp), %eax
movl %eax, 0xe8(%rsp)
leaq 0x30(%rsp), %rdx
movl 0x48(%rdx), %eax
leaq 0xf0(%rsp), %rcx
movl %eax, 0x10(%rcx)
movups 0x38(%rdx), %xmm0
movups %xmm0, (%rcx)
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x95ea
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9601
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
leaq 0x150(%rsp), %rsi
movq %rbx, %r13
leaq 0x110(%rsp), %rbx
movq %rbx, %rdx
callq 0xcf86
movq %rbx, %rdi
movq %r13, %rsi
callq 0xc726
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
movq %r13, %rbx
je 0x9644
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x965b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
leaq 0x10df6(%rip), %rdi     # 0x1a458
leaq 0xb8(%rsp), %r13
movq %r13, %rsi
callq 0xeaf6
movups (%r13), %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x6314
movl 0x128(%rsp), %eax
movl %eax, 0x38(%rsp)
leaq 0x130(%rsp), %rcx
movl 0x10(%rcx), %eax
leaq 0x30(%rsp), %rdx
movl %eax, 0x20(%rdx)
movups (%rcx), %xmm0
movups %xmm0, 0x10(%rdx)
movl 0x148(%rsp), %eax
movl %eax, 0x58(%rsp)
leaq 0x10dc3(%rip), %rdi     # 0x1a488
movq %rbx, %rsi
callq 0xec4a
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x96e4
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x9701
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x971e
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x973b
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x9758
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq (%r12), %r12
testq %r12, %r12
jne 0x91a3
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9799
jmp 0x9799
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x979c
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x979c
jmp 0x9799
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xc78a
jmp 0x980e
movq %rax, %rbx
jmp 0x980e
movq %rax, %rbx
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x97d5
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x97d5
movq %rax, %rbx
movq 0x190(%rsp), %rdi
testq %rdi, %rdi
je 0x981b
movq 0x1a0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x981b
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x980e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
leaq 0x98(%rsp), %rdi
callq 0xc6f6
movq %rbx, %rdi
callq 0x2240