// File: 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
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0xb8d0
movq (%rax), %rcx
movq %rcx, -0x28(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
leaq 0x2ea7f(%rip), %rax     # 0x402c0
movq %rax, -0x30(%rbp)
leaq 0x2ea74(%rip), %rdi     # 0x402c0
callq 0x16ff0
movq %rax, -0x38(%rbp)
leaq 0x2ea64(%rip), %rdi     # 0x402c0
callq 0x17020
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x17050
testb $0x1, %al
jne 0x1187b
jmp 0x11b03
leaq -0x38(%rbp), %rdi
callq 0x17080
movq (%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
leaq -0x58(%rbp), %rdi
addq $0x8, %rdi
callq 0x170b0
movl %eax, -0xe0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x170b0
movl %eax, %ecx
movl -0xe0(%rbp), %eax
cmpl %ecx, %eax
jne 0x11af3
leaq -0x28(%rbp), %rdi
callq 0x16b30
movq %rax, %rsi
leaq 0x2e906(%rip), %rdi     # 0x401e0
callq 0xd480
movq %rax, -0xe8(%rbp)
leaq -0x58(%rbp), %rdi
addq $0x8, %rdi
callq 0x16b30
movq %rax, %rsi
leaq 0x2e8e3(%rip), %rdi     # 0x401e0
callq 0xd480
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
callq 0x5880
testb $0x1, %al
jne 0x1191a
jmp 0x11af1
leaq -0x28(%rbp), %rdi
callq 0x16b30
movq %rax, %rsi
leaq 0x2e8b3(%rip), %rdi     # 0x401e0
callq 0xd480
movq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0x5ff0
leaq -0x50(%rbp), %rdi
callq 0x16b30
movq %rax, -0xf0(%rbp)
jmp 0x11953
movq -0xf0(%rbp), %rsi
leaq 0x2e87f(%rip), %rdi     # 0x401e0
callq 0xd480
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x5ff0
jmp 0x11977
leaq -0x70(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x262f0
jmp 0x11990
leaq -0xa0(%rbp), %rdi
callq 0x3b70
leaq -0x88(%rbp), %rdi
callq 0x3b70
movq -0x10(%rbp), %rdi
callq 0x16d80
movl %eax, -0xf4(%rbp)
jmp 0x119b9
leaq 0x2e970(%rip), %rdi     # 0x40330
leaq -0x58(%rbp), %rsi
callq 0x170c0
movq %rax, -0x100(%rbp)
jmp 0x119d2
movq -0x100(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x170f0
movq %rax, %rsi
addq $0x8, %rsi
leaq -0xd0(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0xcfc0
jmp 0x11a05
leaq -0xd0(%rbp), %rdi
callq 0x17490
movl %eax, -0x104(%rbp)
jmp 0x11a19
leaq -0xd0(%rbp), %rdi
callq 0x44a0
movl -0x104(%rbp), %ecx
movl -0xf4(%rbp), %eax
cmpl %ecx, %eax
jle 0x11ac3
movb $0x1, -0x1(%rbp)
movl $0x1, -0xdc(%rbp)
jmp 0x11acd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x11a7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x3b70
leaq -0x88(%rbp), %rdi
callq 0x3b70
jmp 0x11b15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x11ae6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x44a0
jmp 0x11ae6
movl $0x0, -0xdc(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3b70
movl -0xdc(%rbp), %eax
testl %eax, %eax
je 0x11ae4
jmp 0x11ae2
jmp 0x11b07
jmp 0x11af1
leaq -0x70(%rbp), %rdi
callq 0x3b70
jmp 0x11b15
jmp 0x11af3
jmp 0x11af5
leaq -0x38(%rbp), %rdi
callq 0x17140
jmp 0x11865
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0xa8(%rbp), %rdi
callq 0x2300
nopw %cs:(%rax,%rax)