// File: /workspace/github_cpp_makefile_star2_O3/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 0x10ade(%rip), %r13     # 0x1a268
testq %r13, %r13
je 0x9cb9
movl %edx, %ebp
leaq 0xb0(%rsp), %r15
leaq 0x10c04(%rip), %r12     # 0x1a3a8
movl %edx, 0x4(%rsp)
leaq 0x8(%r13), %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0xedd2
cmpl %ebp, 0x10(%rax)
jle 0x9cac
movq 0x8(%rsp), %rdi
callq 0xcb20
cltq
leaq 0x1099d(%rip), %rcx     # 0x1a170
movq (%rcx), %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 0xb894
testb %al, %al
je 0x9807
movq 0x108(%rsp), %rax
incl (%rax)
jmp 0x9cac
movq %r12, %r14
leaq 0x10ab7(%rip), %rdi     # 0x1a2c8
movq %rbx, %rsi
callq 0xed1a
movq %rax, %r12
leaq 0x10(%rax), %rsi
leaq 0x198(%rsp), %rbp
movq %rbp, %rdi
callq 0x68a4
movl 0x28(%r12), %eax
movl %eax, 0x1b0(%rsp)
movl 0x10(%r13), %edx
movq 0x18(%r13), %rcx
leaq 0x110(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x50f8
leaq 0x90(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
callq 0x53ed
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x9889
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x198(%rsp), %rdi
testq %rdi, %rdi
je 0x98a6
movq 0x1a8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x10a33(%rip), %r12     # 0x1a2e0
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x68a4
incq %r12
movl 0xa8(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x10(%r15), %eax
leaq 0x30(%rsp), %rcx
movl %eax, 0x10(%rcx)
movaps (%r15), %xmm0
movaps %xmm0, (%rcx)
movq %r12, 0x48(%rsp)
movq %r14, %r12
movq %r14, %rdi
movq %rbx, %rsi
callq 0xedd2
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x68a4
movl 0xe0(%rsp), %eax
movl %eax, 0x1d0(%rsp)
movl 0x48(%r15), %ecx
leaq 0x1d8(%rsp), %rdx
movl %ecx, 0x10(%rdx)
movups 0x38(%r15), %xmm0
movups %xmm0, (%rdx)
movl 0x10(%rbx), %ecx
movq 0x20(%rsp), %rdx
movaps 0x10(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl 0x28(%rsp), %esi
movl 0x48(%rsp), %r8d
movq 0x1b8(%rsp), %rdi
movaps %xmm0, 0x110(%rsp)
movq %rdx, 0x120(%rsp)
movl %esi, 0x128(%rsp)
leaq 0x30(%rsp), %rbx
movaps (%rbx), %xmm0
leaq 0x130(%rsp), %rsi
movaps %xmm0, (%rsi)
movl 0x10(%rbx), %edx
movl %edx, 0x10(%rsi)
movl %r8d, 0x148(%rsp)
movq %rdi, 0x150(%rsp)
movups 0x1c0(%rsp), %xmm0
movups %xmm0, 0x158(%rsp)
movl %eax, 0x168(%rsp)
movl 0x48(%r15), %eax
movl %eax, 0x50(%rsi)
movups 0x38(%r15), %xmm0
movups %xmm0, 0x40(%rsi)
movl %ecx, 0x188(%rsp)
movl 0xb0(%rsp), %ecx
movl 0xe8(%rsp), %esi
movq 0xb8(%rsp), %rax
movq 0xf0(%rsp), %rdx
cmpl %esi, %ecx
sete %r8b
cmpq %rdx, %rax
sete %r9b
testb %r9b, %r8b
movl 0x4(%rsp), %ebp
leaq 0x10(%rsp), %r14
jne 0x9c38
xorl %edi, %edi
cmpl %esi, %ecx
setl %dil
xorl %ecx, %ecx
cmpq %rdx, %rax
setl %cl
cmovel %edi, %ecx
cmpb $0x1, %cl
jne 0x9bad
movq %r14, %rdi
leaq 0xc8(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0xd3ec
movq 0x90(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0xa0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0x9a86
subq %rdi, %rsi
callq 0x2180
movl 0x28(%rsp), %eax
movl %eax, 0xa8(%rsp)
movl 0x10(%rbx), %eax
leaq 0xb0(%rsp), %r15
movl %eax, 0x10(%r15)
movaps (%rbx), %xmm0
movaps %xmm0, (%r15)
movq 0xc8(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movups 0x48(%rsp), %xmm0
movups %xmm0, 0xc8(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0xd8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx)
movq $0x0, 0x28(%rbx)
testq %rdi, %rdi
je 0x9b21
subq %rdi, %rsi
callq 0x2180
movq 0x48(%rsp), %rdi
movl 0x60(%rsp), %eax
movl %eax, 0xe0(%rsp)
movl 0x48(%rbx), %eax
movl %eax, 0x48(%r15)
movups 0x38(%rbx), %xmm0
movups %xmm0, 0x38(%r15)
testq %rdi, %rdi
je 0x9b3c
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x9b3c
movl 0x60(%rsp), %eax
movl %eax, 0xe0(%rsp)
movl 0x48(%rbx), %eax
movl %eax, 0x48(%r15)
movups 0x38(%rbx), %xmm0
movups %xmm0, 0x38(%r15)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9b53
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %r14, %rdi
leaq 0x150(%rsp), %rsi
movq %r14, %r15
leaq 0x110(%rsp), %r14
movq %r14, %rdx
callq 0xd45e
movq %r14, %rdi
movq %r15, %rsi
callq 0xcbac
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
movq %r15, %r14
je 0x9b96
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9bad
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
leaq 0x108b4(%rip), %rdi     # 0x1a468
leaq 0xb0(%rsp), %r15
movq %r15, %rsi
callq 0xf016
movups (%r15), %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x68a4
movl 0x128(%rsp), %eax
movl %eax, 0x38(%rsp)
leaq 0x130(%rsp), %rcx
movl 0x10(%rcx), %eax
movl %eax, 0x20(%rbx)
movups (%rcx), %xmm0
movups %xmm0, 0x10(%rbx)
movl 0x148(%rsp), %eax
movl %eax, 0x58(%rsp)
leaq 0x10887(%rip), %rdi     # 0x1a498
movq %r14, %rsi
callq 0xf16a
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x9c30
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x9c4d
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
leaq 0xb0(%rsp), %r15
je 0x9c72
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x9c8f
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x9cac
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq (%r13), %r13
testq %r13, %r13
jne 0x97a8
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9ced
jmp 0x9ced
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x9cf0
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x9cf0
jmp 0x9ced
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xcc10
jmp 0x9d62
movq %rax, %rbx
jmp 0x9d62
movq %rax, %rbx
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x9d29
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x9d29
movq %rax, %rbx
movq 0x198(%rsp), %rdi
testq %rdi, %rdi
je 0x9d6f
movq 0x1a8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x9d6f
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9d62
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
leaq 0x90(%rsp), %rdi
callq 0xcb7c
movq %rbx, %rdi
callq 0x2240