// File: manschga[P]M5GB/M5GB.cpp
// Function: Div_by_M(long, signature const&)
Lab_poly Div_by_M(const term_int t, const signature& T)
{
  g_reduced++;
  Lab_poly current = Lab_poly();
  polynomial Old_M = polynomial();
  bool m_found = false;
  vector<int> t_ = table[t].first;
    if (!m_found)
    {
      for (auto& it : LT_M) 
	{
	  if (isDivisible(table[t].first,table[it.first].first))
	    {
	      term_vec v = get_remainder(table[t].first, table[it.first].first);//if divisor divides term, then term = divisor*remainder);
	      signature test = it.second.Multiply(v);
	      if (Smaller_sign(test,T)) //check if S(vG) < T
		{
		  m_found = true;
		  polynomial New_M = M.find(it.first)->second;
		  //Lab_poly candidate(G_.find(it.first)->second.Multiply(v),test);
		  if (is_more_reduced(New_M,Old_M)) //check different criteria
		    {
		      current = Lab_poly(New_M.Multiply(v),test);
		      Old_M = New_M;
		      //return candidate;
		    }
		}
	    }
	}
    }
    if (!m_found)
    {
      for (auto& it : LT_G) 
	{
	  if (isDivisible(table[t].first,table[it.first].first))
	    {
	      term_vec v = get_remainder(table[t].first, table[it.first].first);//if divisor divides term, then term = divisor*remainder);
	      signature test = it.second.Multiply(v);
	      if (Smaller_sign(test,T)) //check if S(vG) < T
		{
		  m_found = true;
		  polynomial New_M = G_.find(it.first)->second;
		  //Lab_poly candidate(G_.find(it.first)->second.Multiply(v),test);
		  if (is_more_reduced(New_M,Old_M)) //check different criteria
		    {
		      current = Lab_poly(New_M.Multiply(v),test);
		      Old_M = New_M;
		      //return candidate;
		    }
		}
	    }
	}
      }
  return current;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movq %rdi, -0x290(%rbp)
movq %rdi, %rax
movq %rax, -0x288(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl 0x2c436(%rip), %eax     # 0x40234
incl %eax
movl %eax, 0x2c42e(%rip)     # 0x40234
movb $0x0, -0x19(%rbp)
callq 0x9cf0
leaq -0x40(%rbp), %rdi
callq 0x25e60
jmp 0x13e1a
movb $0x0, -0x4d(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x2c3b7(%rip), %rdi     # 0x401e0
callq 0xd480
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
callq 0x5ff0
jmp 0x13e3c
testb $0x1, -0x4d(%rbp)
jne 0x141cc
leaq 0x2c4ab(%rip), %rax     # 0x402f8
movq %rax, -0x70(%rbp)
leaq 0x2c4a0(%rip), %rdi     # 0x402f8
callq 0x16ff0
movq %rax, -0x78(%rbp)
leaq 0x2c490(%rip), %rdi     # 0x402f8
callq 0x17020
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x17050
testb $0x1, %al
jne 0x13e87
jmp 0x141ca
leaq -0x78(%rbp), %rdi
callq 0x17080
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x2c33e(%rip), %rdi     # 0x401e0
movq %rdi, -0x2a8(%rbp)
callq 0xd480
movq -0x2a8(%rbp), %rdi
movq %rax, -0x2a0(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rsi
callq 0xd480
movq -0x2a0(%rbp), %rdi
movq %rax, %rsi
callq 0x5880
movb %al, -0x291(%rbp)
jmp 0x13ee2
movb -0x291(%rbp), %al
testb $0x1, %al
jne 0x13ef1
jmp 0x141ba
movq -0x10(%rbp), %rsi
leaq 0x2c2e4(%rip), %rdi     # 0x401e0
callq 0xd480
movq %rax, %rsi
leaq -0xb8(%rbp), %rdi
callq 0x5ff0
jmp 0x13f12
movq -0x88(%rbp), %rax
movq (%rax), %rsi
leaq 0x2c2bd(%rip), %rdi     # 0x401e0
callq 0xd480
movq %rax, %rsi
leaq -0xd0(%rbp), %rdi
callq 0x5ff0
jmp 0x13f39
leaq -0xa0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
callq 0x262f0
jmp 0x13f55
leaq -0xd0(%rbp), %rdi
callq 0x3b70
leaq -0xb8(%rbp), %rdi
callq 0x3b70
movq -0x88(%rbp), %rdi
addq $0x8, %rdi
leaq -0xa0(%rbp), %rsi
callq 0xd0c0
movq %rdx, -0x2b8(%rbp)
movl %eax, -0x2ac(%rbp)
jmp 0x13f93
movq -0x2b8(%rbp), %rax
movl -0x2ac(%rbp), %ecx
movl %ecx, -0xe0(%rbp)
movq %rax, -0xd8(%rbp)
movq -0x18(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x2a460
movb %al, -0x2b9(%rbp)
jmp 0x13fc5
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x13fd4
jmp 0x1419b
movb $0x1, -0x4d(%rbp)
movq -0x88(%rbp), %rsi
leaq 0x2c382(%rip), %rdi     # 0x40368
callq 0x170c0
movq %rax, -0x2c8(%rbp)
jmp 0x13ff4
movq -0x2c8(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x170f0
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x100(%rbp), %rdi
callq 0xd980
jmp 0x14023
leaq -0x100(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x16810
movb %al, -0x2c9(%rbp)
jmp 0x1403b
movb -0x2c9(%rbp), %al
testb $0x1, %al
jne 0x1404a
jmp 0x1417f
leaq -0x160(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0xcfc0
jmp 0x14066
movups -0xe0(%rbp), %xmm0
movaps %xmm0, -0x170(%rbp)
movl -0x170(%rbp), %edx
movq -0x168(%rbp), %rcx
leaq -0x140(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x9d90
jmp 0x14096
movq -0x290(%rbp), %rdi
leaq -0x140(%rbp), %rsi
movq %rsi, -0x2d8(%rbp)
callq 0xbf00
movq -0x2d8(%rbp), %rdi
callq 0xbc80
leaq -0x160(%rbp), %rdi
callq 0x44a0
leaq -0x40(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0xb850
jmp 0x140da
jmp 0x1417f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x14586
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1455f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x14556
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x14138
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3b70
leaq -0xb8(%rbp), %rdi
callq 0x3b70
jmp 0x14556
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x141a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1418d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x44a0
jmp 0x1418d
leaq -0x100(%rbp), %rdi
callq 0x44a0
jmp 0x1419b
leaq -0x100(%rbp), %rdi
callq 0x44a0
jmp 0x141a9
leaq -0xa0(%rbp), %rdi
callq 0x3b70
jmp 0x141ba
leaq -0xa0(%rbp), %rdi
callq 0x3b70
jmp 0x14556
jmp 0x141bc
leaq -0x78(%rbp), %rdi
callq 0x17140
jmp 0x13e71
jmp 0x141cc
testb $0x1, -0x4d(%rbp)
jne 0x14538
leaq 0x2c0e3(%rip), %rax     # 0x402c0
movq %rax, -0x178(%rbp)
leaq 0x2c0d5(%rip), %rdi     # 0x402c0
callq 0x16ff0
movq %rax, -0x180(%rbp)
leaq 0x2c0c2(%rip), %rdi     # 0x402c0
callq 0x17020
movq %rax, -0x188(%rbp)
leaq -0x180(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x17050
testb $0x1, %al
jne 0x14226
jmp 0x14536
leaq -0x180(%rbp), %rdi
callq 0x17080
movq %rax, -0x190(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x2bf9c(%rip), %rdi     # 0x401e0
movq %rdi, -0x2f0(%rbp)
callq 0xd480
movq -0x2f0(%rbp), %rdi
movq %rax, -0x2e8(%rbp)
movq -0x190(%rbp), %rax
movq (%rax), %rsi
callq 0xd480
movq -0x2e8(%rbp), %rdi
movq %rax, %rsi
callq 0x5880
movb %al, -0x2d9(%rbp)
jmp 0x14284
movb -0x2d9(%rbp), %al
testb $0x1, %al
jne 0x14293
jmp 0x14523
movq -0x10(%rbp), %rsi
leaq 0x2bf42(%rip), %rdi     # 0x401e0
callq 0xd480
movq %rax, %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x5ff0
jmp 0x142b4
movq -0x190(%rbp), %rax
movq (%rax), %rsi
leaq 0x2bf1b(%rip), %rdi     # 0x401e0
callq 0xd480
movq %rax, %rsi
leaq -0x1d8(%rbp), %rdi
callq 0x5ff0
jmp 0x142db
leaq -0x1a8(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
leaq -0x1d8(%rbp), %rdx
callq 0x262f0
jmp 0x142f7
leaq -0x1d8(%rbp), %rdi
callq 0x3b70
leaq -0x1c0(%rbp), %rdi
callq 0x3b70
movq -0x190(%rbp), %rdi
addq $0x8, %rdi
leaq -0x1a8(%rbp), %rsi
callq 0xd0c0
movq %rdx, -0x300(%rbp)
movl %eax, -0x2f4(%rbp)
jmp 0x14335
movq -0x300(%rbp), %rax
movl -0x2f4(%rbp), %ecx
movl %ecx, -0x1e8(%rbp)
movq %rax, -0x1e0(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x1e8(%rbp), %rdi
callq 0x2a460
movb %al, -0x301(%rbp)
jmp 0x14367
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0x14376
jmp 0x14507
movb $0x1, -0x4d(%rbp)
movq -0x190(%rbp), %rsi
leaq 0x2bfa8(%rip), %rdi     # 0x40330
callq 0x170c0
movq %rax, -0x310(%rbp)
jmp 0x14396
movq -0x310(%rbp), %rax
movq %rax, -0x210(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x170f0
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x208(%rbp), %rdi
callq 0xd980
jmp 0x143c5
leaq -0x208(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x16810
movb %al, -0x311(%rbp)
jmp 0x143dd
movb -0x311(%rbp), %al
testb $0x1, %al
jne 0x143ec
jmp 0x144eb
leaq -0x268(%rbp), %rdi
leaq -0x208(%rbp), %rsi
leaq -0x1a8(%rbp), %rdx
callq 0xcfc0
jmp 0x14408
movups -0x1e8(%rbp), %xmm0
movaps %xmm0, -0x280(%rbp)
movl -0x280(%rbp), %edx
movq -0x278(%rbp), %rcx
leaq -0x248(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x9d90
jmp 0x14438
movq -0x290(%rbp), %rdi
leaq -0x248(%rbp), %rsi
movq %rsi, -0x320(%rbp)
callq 0xbf00
movq -0x320(%rbp), %rdi
callq 0xbc80
leaq -0x268(%rbp), %rdi
callq 0x44a0
leaq -0x40(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0xb850
jmp 0x1447c
jmp 0x144eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x144a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x3b70
leaq -0x1c0(%rbp), %rdi
callq 0x3b70
jmp 0x14556
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x14515
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x144f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x44a0
jmp 0x144f9
leaq -0x208(%rbp), %rdi
callq 0x44a0
jmp 0x14507
leaq -0x208(%rbp), %rdi
callq 0x44a0
jmp 0x14515
leaq -0x1a8(%rbp), %rdi
callq 0x3b70
jmp 0x14523
leaq -0x1a8(%rbp), %rdi
callq 0x3b70
jmp 0x14556
jmp 0x14525
leaq -0x180(%rbp), %rdi
callq 0x17140
jmp 0x1420a
jmp 0x14538
movb $0x1, -0x19(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3b70
leaq -0x40(%rbp), %rdi
callq 0x44a0
testb $0x1, -0x19(%rbp)
jne 0x14576
jmp 0x1456a
leaq -0x68(%rbp), %rdi
callq 0x3b70
leaq -0x40(%rbp), %rdi
callq 0x44a0
jmp 0x14586
movq -0x290(%rbp), %rdi
callq 0xbc80
movq -0x288(%rbp), %rax
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
movq -0x290(%rbp), %rdi
callq 0xbc80
movq -0x48(%rbp), %rdi
callq 0x2300
nopl (%rax,%rax)