// File: /workspace/github_cpp_makefile_star2_O1/manschga[P]M5GB/M5GB.cpp
// Function: Low_pol(signature const&, Lab_poly const&, int, int)
Lab_poly Low_pol(const signature& smallest_sign, const Lab_poly& uF, const int generation, int n)
{
  term_int LT_low = 0;
  term_int remainder_low = 0;
  Lab_poly Low = uF;
  bool not_yet = true;
#ifdef LARGEST_LT //no sense to do largest lt heuristic here
  return uF;
#endif
  for (auto& it : LT_M)
    {
      if (smallest_sign.Get_index() == it.second.Get_index())
	{
	  if (isDivisible(table[smallest_sign.Get_term()].first,table[it.second.Get_term()].first))
	    {
	      polynomial test = M.find(it.first)->second.Multiply(get_remainder(table[smallest_sign.Get_term()].first,table[it.second.Get_term()].first));
	      
#ifdef LARGE_GEN
	      if (not_yet) //still uF is best
		{

	       if (Generations_G.find(it.first)->second > generation) //different heuristics to check
		    {
		      not_yet = false;
		      Low = Lab_poly(test,smallest_sign);
		      LT_low = it.first;
		    }
		}
	      else
		{
		  if (Generations_G.find(it.first)->second > Generations_G.find(LT_low)->second) //different heuristics to check
		     {
		       Low = Lab_poly(test,smallest_sign);
		       LT_low = it.first;
		     }
		}
#endif
	      //*
#ifdef NUMBER_OF_TERMS
	      if (not_yet) //still uF is best
		{
		  if (test.size() <= uF.Get_poly().size()) //different heuristics to check
		    {
		      not_yet = false;
		      Low = Lab_poly(test,smallest_sign);
		      LT_low = it.first;
		    }
		}
	      else
		{
		  if (test.size() < Low.Get_poly().size()) //different heuristics to check
		     {
		       Low = Lab_poly(test,smallest_sign);
		       LT_low = it.first;
		     }
		}
#endif
	      //*/
#ifdef SMALLEST_REMAINDER
	      if (not_yet) //still uF is best
		{
		  if (test.size() < uF.Get_poly().size()) //different heuristics to check
		    {
		      not_yet = false;
		      Low = Lab_poly(test,smallest_sign);
		      LT_low = it.first;
		      remainder_low = term_to_int(get_remainder(table[smallest_sign.Get_term()].first,table[it.second.Get_term()].first),n);
		    }
		}
	      else
		{
		  if(term_to_int(get_remainder(table[smallest_sign.Get_term()].first,table[it.second.Get_term()].first),n) > remainder_low)
		    {
		       Low = Lab_poly(test,smallest_sign);
		       LT_low = it.first;
		       remainder_low = term_to_int(get_remainder(table[smallest_sign.Get_term()].first,table[it.second.Get_term()].first),n);
		     }
		}
#endif
#ifdef SMALLEST_LT
	      if (not_yet) //still uF is best
		{
		  if (test.Get_LT() <= uF.Get_LT()) //different heuristics to check
		    {
		      not_yet = false;
		      Low = Lab_poly(test,smallest_sign);
		      LT_low = it.first;
		    }
		}
	      else
		{
		  if (test.Get_LT() <= Low.Get_LT()) //different heuristics to check
		     {
		       Low = Lab_poly(test,smallest_sign);
		       LT_low = it.first;
		     }
		}
#endif
	    }
	}
    }
	  return Low;
	  /*

  
  for (auto& it : LT_M) 
    {
      if (Lab_pol_M.find(it.first)->second == true) //check if correct label!
	{
      if (smallest_sign.Get_index() == it.second.Get_index())
	{
	  if (isDivisible(table[smallest_sign.Get_term()].first,table[it.second.Get_term()].first))
	    {
	      polynomial test = M.find(it.first)->second.Multiply(get_remainder(table[smallest_sign.Get_term()].first,table[it.second.Get_term()].first));
#ifdef high_gen
	      if (not_yet) //still uF is best
		{

	       if (Generations_M.find(it.first)->second > generation) //different heuristics to check
		    {
		      not_yet = false;
		      Low = Lab_poly(test,smallest_sign);
		      LT_low = it.first;
		    }
		}
	      else
		{
		  if (Generations_M.find(it.first)->second > Generations_M.find(LT_low)->second) //different heuristics to check
		     {
		       Low = Lab_poly(test,smallest_sign);
		       LT_low = it.first;
		     }
		}
#endif

#ifdef smallest_size
	      if (not_yet) //still uF is best
		{
		  if (test.size() <= uF.Get_poly().size()) //different heuristics to check
		    {
		      not_yet = false;
		      Low = Lab_poly(test,smallest_sign);
		      LT_low = it.first;
		    }
		}
	      else
		{
		  if (test.size() < Low.Get_poly().size()) //different heuristics to check
		     {
		       Low = Lab_poly(test,smallest_sign);
		       LT_low = it.first;
		     }
		}
#endif
#ifdef smallest_remainder
	      if (not_yet) //still uF is best
		{
		  if (test.size() <= uF.Get_poly().size()) //different heuristics to check
		    {
		      not_yet = false;
		      Low = Lab_poly(test,smallest_sign);
		      LT_low = it.first;
		      remainder_low = term_to_int(get_remainder(table[smallest_sign.Get_term()].first,table[it.second.Get_term()].first),n);
		    }
		}
	      else
		{
		  if(term_to_int(get_remainder(table[smallest_sign.Get_term()].first,table[it.second.Get_term()].first),n) > remainder_low)
		    {
		       Low = Lab_poly(test,smallest_sign);
		       LT_low = it.first;
		       remainder_low = term_to_int(get_remainder(table[smallest_sign.Get_term()].first,table[it.second.Get_term()].first),n);
		     }
		}
#endif
	    }
	    }
	}
    }
  return Low;
	  */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq %rdx, %rsi
callq 0x6314
movl 0x18(%r14), %eax
movl %eax, 0x18(%rbx)
movl 0x30(%r14), %eax
movl %eax, 0x30(%rbx)
movq %r14, 0x38(%rsp)
movups 0x20(%r14), %xmm0
movq %rbx, (%rsp)
movups %xmm0, 0x20(%rbx)
movq 0x11e31(%rip), %rbp     # 0x1a290
testq %rbp, %rbp
je 0x8763
movq (%rsp), %rax
addq $0x20, %rax
movq %rax, 0x10(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
leaq 0x11ce6(%rip), %rcx     # 0x1a168
leaq 0x90(%rsp), %r12
leaq 0x58(%rsp), %r13
movl (%r15), %eax
cmpl 0x10(%rbp), %eax
jne 0x8756
movq %r15, %rbx
movq 0x8(%r15), %rax
movq (%rcx), %rcx
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq %rcx, %rdi
movq 0x18(%rbp), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
addq %rcx, %rsi
callq 0x3bd6
testb %al, %al
je 0x874c
leaq 0x8(%rbp), %rcx
movq (%rcx), %r8
movq %r8, %rax
xorl %edx, %edx
divq 0x11e19(%rip)           # 0x1a2f8
leaq 0x11e0a(%rip), %rdi     # 0x1a2f0
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
callq 0xdd4a
testq %rax, %rax
leaq 0x11c6a(%rip), %rcx     # 0x1a168
je 0x8505
movq (%rax), %r15
jmp 0x8508
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
addq (%rcx), %rsi
movq %rcx, %r14
leaq 0x40(%rsp), %rdi
callq 0x405e
movq 0x18(%rbp), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
addq (%r14), %rsi
movq %r12, %r14
movq %r12, %rdi
callq 0x405e
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
movq %r14, %rdx
callq 0x1074e
addq $0x10, %r15
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x61f0
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x8579
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x8596
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x85ad
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x18(%rsp), %rax
testb $0x1, 0xc(%rsp)
je 0x8680
movq 0x20(%rsp), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
movq 0x38(%rsp), %rdx
movq 0x8(%rdx), %rax
subq (%rdx), %rax
shrq $0x4, %rax
cmpl %eax, %ecx
jg 0x8735
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x6314
movl 0x30(%rsp), %eax
movl %eax, 0xe0(%rsp)
movl (%rbx), %edx
movq 0x8(%rbx), %rcx
movq %r13, %rdi
movq %r14, %rsi
callq 0x4bf0
movq (%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x60a8
movl 0x70(%rsp), %eax
movl %eax, 0x18(%r14)
leaq 0x78(%rsp), %rdx
movl 0x10(%rdx), %eax
movq 0x10(%rsp), %rcx
movl %eax, 0x10(%rcx)
movups (%rdx), %xmm0
movups %xmm0, (%rcx)
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x8656
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x8673
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movl $0x0, 0xc(%rsp)
jmp 0x8735
movq 0x20(%rsp), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
movq (%rsp), %rdx
movq 0x8(%rdx), %rax
subq (%rdx), %rax
shrq $0x4, %rax
cmpl %eax, %ecx
jge 0x8735
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x6314
movl 0x30(%rsp), %eax
movl %eax, 0xc0(%rsp)
movl (%rbx), %edx
movq 0x8(%rbx), %rcx
movq %r13, %rdi
movq %r14, %rsi
callq 0x4bf0
movq (%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x60a8
movl 0x70(%rsp), %eax
movl %eax, 0x18(%r14)
leaq 0x78(%rsp), %rdx
movl 0x10(%rdx), %eax
movq 0x10(%rsp), %rcx
movl %eax, 0x10(%rcx)
movups (%rdx), %xmm0
movups %xmm0, (%rcx)
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x8718
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x8735
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x874c
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
leaq 0x11a15(%rip), %rcx     # 0x1a168
movq %rbx, %r15
movq (%rbp), %rbp
testq %rbp, %rbp
jne 0x848f
movq (%rsp), %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x87ba
movq 0xd8(%rsp), %rsi
jmp 0x87ad
jmp 0x87b7
movq %rax, %r14
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x87ba
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x87ba
movq %rax, %r14
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x882c
movq 0x28(%rsp), %rsi
jmp 0x881f
jmp 0x8829
jmp 0x8829
movq %rax, %r14
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x87ee
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x87ee
movq %rax, %r14
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x8810
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x8810
movq %rax, %r14
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x882c
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x882c
movq %rax, %r14
movq (%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x8848
movq (%rsp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2180
movq %r14, %rdi
callq 0x2240