// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq 0x1201d(%rip), %r12     # 0x1a258
testq %r12, %r12
setne 0x7(%rsp)
je 0x83a7
movl 0x20(%rdi), %r14d
movq %rdi, 0x18(%rsp)
movq 0x28(%rdi), %rax
leaq 0x60(%rsp), %rcx
movq %rcx, 0x8(%rsp)
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movq %rax, 0x10(%rsp)
leaq 0x50(%rsp), %r13
cmpl %r14d, 0x10(%r12)
jne 0x8395
movq 0x8(%r12), %rbp
movq 0x18(%r12), %rax
leaq 0x11eda(%rip), %rcx     # 0x1a168
movq (%rcx), %rsi
movq 0x10(%rsp), %rcx
leaq (%rsi,%rcx), %rdi
leaq (%rax,%rax,2), %r15
shlq $0x4, %r15
addq %r15, %rsi
callq 0x3bd6
testb %al, %al
je 0x8395
leaq 0x11eaf(%rip), %rbx     # 0x1a168
movq (%rbx), %rsi
addq 0x10(%rsp), %rsi
movq %r13, %rdi
callq 0x405e
addq (%rbx), %r15
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x405e
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x1074e
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x8303
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x831a
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x18(%rsp), %rdi
callq 0xc69a
movl %eax, %r15d
movq %rbp, %rax
xorl %edx, %edx
divq 0x11f8d(%rip)           # 0x1a2c0
movq 0x11f7e(%rip), %rax     # 0x1a2b8
movq (%rax,%rdx,8), %rax
movq (%rax), %rcx
cmpq 0x8(%rcx), %rbp
je 0x834f
movq %rcx, %rax
movq (%rcx), %rcx
jmp 0x8341
movq (%rax), %rsi
addq $0x10, %rsi
leaq 0x68(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x61f0
movq 0x68(%rsp), %rdi
movq 0x78(%rsp), %rsi
movl (%rdi), %ebp
subq %rdi, %rsi
callq 0x2180
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x8390
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
cmpl %ebp, %r15d
jg 0x83a7
movq (%r12), %r12
testq %r12, %r12
setne 0x7(%rsp)
jne 0x8272
movb 0x7(%rsp), %al
andb $0x1, %al
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x83e7
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x83e0
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x83e0
movq %rax, %rbx
movq 0x50(%rsp), %rdi
jmp 0x83f9
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
testq %rdi, %rdi
je 0x840e
movq 0x8(%rsp), %rax
movq (%rax), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2240