// File: /workspace/github_cpp_makefile_star2_O2/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 $0x238, %rsp            # imm = 0x238
movq %rcx, 0x18(%rsp)
movl %edx, %ebp
movq %rdi, 0x10(%rsp)
leaq 0x10d2e(%rip), %r14     # 0x18260
leaq 0x10e67(%rip), %r13     # 0x183a0
leaq 0x178(%rsp), %r12
movl %edx, 0xc(%rsp)
movq (%r14), %r14
testq %r14, %r14
je 0x7793
leaq 0x8(%r14), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0xbc20
cmpl %ebp, 0x10(%rax)
jle 0x7545
movq 0x10(%rsp), %rdi
callq 0x97f2
cltq
leaq 0x10bf8(%rip), %rcx     # 0x18170
movq (%rcx), %rcx
imulq $0x30, %rax, %rdi
addq %rcx, %rdi
imulq $0x30, (%rbx), %rsi
addq %rcx, %rsi
callq 0x8a8f
testb %al, %al
je 0x759b
movq 0x18(%rsp), %rax
incl (%rax)
jmp 0x7545
leaq 0x10d1e(%rip), %rdi     # 0x182c0
movq %rbx, %rsi
callq 0xbbe4
leaq 0x10(%rax), %rsi
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x57a2
movl 0x10(%r14), %edx
movq 0x18(%r14), %rcx
movq %r12, %rdi
movq %r15, %rsi
callq 0x4524
movq %r13, %r15
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x474a
movq %r12, %rdi
callq 0x2f74
leaq 0x20(%rsp), %rdi
callq 0x2f74
movq 0x10cd9(%rip), %r13     # 0x182d8
leaq 0x138(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x97ca
incq %r13
movq %r13, 0x170(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0xbc20
leaq 0x1f8(%rsp), %rbp
addq $0x10, %rax
movq %rbp, %rdi
leaq 0x78(%rsp), %rsi
movq %rax, %rdx
callq 0xa062
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x9ffe
movq %r12, %rbx
leaq 0x178(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x9888
leaq 0x40(%rsp), %r15
movq %r13, %rdi
callq 0x98b2
movq %rbp, %rdi
callq 0x2f74
movq %rbx, %rdi
callq 0x2f74
movl 0x60(%rsp), %eax
movl 0x98(%rsp), %ecx
cmpl %ecx, %eax
sete %dil
movq 0x68(%rsp), %rdx
movq 0xa0(%rsp), %rsi
cmpq %rsi, %rdx
sete %r8b
testb %r8b, %dil
movl 0xc(%rsp), %ebp
leaq 0x10ce0(%rip), %r13     # 0x183a0
jne 0x777e
xorl %edi, %edi
cmpl %ecx, %eax
setl %dil
xorl %eax, %eax
cmpq %rsi, %rdx
setl %al
cmovel %edi, %eax
cmpb $0x1, %al
jne 0x772e
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x78(%rsp), %rsi
movq %r15, %rdx
callq 0xa09e
movq %r15, %rdi
movq %rbx, %rsi
callq 0x61f0
movq %rbx, %rdi
callq 0x61da
movq %rbx, %rdi
leaq 0x1b8(%rsp), %rsi
movq %r12, %rdx
callq 0xa0d4
movq %r12, %rdi
movq %rbx, %rsi
callq 0x98c8
movq %rbx, %rdi
callq 0x98f2
leaq 0x10d2b(%rip), %rdi     # 0x18460
leaq 0x60(%rsp), %rbx
movq %rbx, %rsi
callq 0xbe64
movups (%rbx), %xmm0
movaps %xmm0, 0xb0(%rsp)
leaq 0xc0(%rsp), %rdi
movq %r12, %rsi
callq 0xa10a
leaq 0x10d2c(%rip), %rdi     # 0x18490
leaq 0xb0(%rsp), %rsi
callq 0xbfee
leaq 0xc0(%rsp), %rdi
callq 0x2f74
movq %r12, %rdi
callq 0x98f2
movq %r15, %rdi
callq 0x61da
jmp 0x7545
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x77bd
jmp 0x77bd
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x2f74
jmp 0x77c0
jmp 0x77bd
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x98f2
jmp 0x7824
movq %rax, %rbx
jmp 0x7824
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x2f74
jmp 0x77e9
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2f74
jmp 0x782e
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x98b2
leaq 0x1f8(%rsp), %rdi
callq 0x2f74
jmp 0x7817
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x2f74
leaq 0x40(%rsp), %rdi
callq 0x61da
movq %rbx, %rdi
callq 0x2260