// File: /workspace/github_cpp_makefile_star2_O3/manschga[P]M5GB/M5GB.cpp
// Function: isRewritable(Lab_poly const&, int)
bool isRewritable(const Lab_poly& F, const int generation)
{
  signature T = F.Get_sign();
  for (auto it : LT_G)
    {
      if (it.second.Get_index() == T.Get_index())
	{
	  if (isDivisible(table[T.Get_term()].first,table[it.second.Get_term()].first))
	    {
#ifdef NUMBER
	      //rewrite order num: F < G if F created before G, still some error in here!
	      if (generation < Generations_G.find(it.first)->second)
		{
		  /*
		  cout << "Gen(F) = " << generation << endl;
		  cout << "Gen(G) = " << Generations_G.find(it.first)->second << endl;
		  */
		  return true;
		}
	      
#endif
#ifdef RATIO
	      //define vG = v*G_i if S(vG_i) = S(F);
	      vector<int> v = get_remainder(table[T.Get_term()].first,table[it.second.Get_term()].first);
	      //rewrite order, for ratio, only need: LT(g) < LT(f)
	      if (F.Get_LT() > G_.find(it.first)->second.Multiply(v).Get_LT())
		{
#ifdef DEBUG
		  cout << F << "is rewritable by " << it.second << endl;
		  cout << F << "is rewritable by " << it.second.Multiply(v) << endl;
#endif
		  return true;
		}
#endif
	    }
	}
    }
  return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq 0x11a62(%rip), %r13     # 0x1a268
testq %r13, %r13
je 0x8957
movl 0x20(%rdi), %r14d
movq %rdi, 0x28(%rsp)
movq 0x28(%rdi), %rax
leaq 0x70(%rsp), %rcx
movq %rcx, 0x8(%rsp)
leaq 0x11943(%rip), %r15     # 0x1a170
leaq (%rax,%rax,2), %r12
shlq $0x4, %r12
movups 0x8(%r13), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x18(%r13), %rax
movq %rax, 0x20(%rsp)
cmpl %r14d, 0x18(%rsp)
jne 0x894a
movq (%r15), %rax
leaq (%rax,%r12), %rdi
movq 0x20(%rsp), %rcx
leaq (%rcx,%rcx,2), %rsi
shlq $0x4, %rsi
addq %rax, %rsi
callq 0x3bf9
leaq 0x48(%rsp), %rbx
leaq 0x60(%rsp), %rbp
testb %al, %al
je 0x894a
movq (%r15), %rsi
addq %r12, %rsi
movq %rbp, %rdi
callq 0x4214
movq 0x20(%rsp), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
addq (%r15), %rsi
movq %rbx, %rdi
callq 0x4214
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x10d0f
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x88ce
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x88e5
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x28(%rsp), %rdi
callq 0xcb20
movl %eax, %ebp
leaq 0x119d0(%rip), %rdi     # 0x1a2c8
leaq 0x10(%rsp), %rsi
callq 0xed1a
addq $0x10, %rax
leaq 0x78(%rsp), %rdi
movq %rax, %rsi
leaq 0x30(%rsp), %rdx
callq 0x6780
movq 0x78(%rsp), %rdi
movq 0x88(%rsp), %rsi
movl (%rdi), %ebx
subq %rdi, %rsi
callq 0x2180
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8946
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
cmpl %ebx, %ebp
jg 0x896b
movq (%r13), %r13
testq %r13, %r13
jne 0x8835
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
jmp 0x8959
jmp 0x8997
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x8990
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x8990
movq %rax, %rbx
movq 0x60(%rsp), %rdi
jmp 0x89a9
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
testq %rdi, %rdi
je 0x89be
movq 0x8(%rsp), %rax
movq (%rax), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2240