// File: /workspace/github_cpp_makefile_star2_O2/manschga[P]M5GB/poly.cpp
// Function: reduce(polynomial&, polynomial const&, bool&, int&)
void reduce(polynomial &G_i, const polynomial &G_j, bool &changed, int& reductions)
{
  term_vec LT_j_vec = table[G_j.Get_LT()].first;
  for (int terms = 0; terms < G_i.size(); ++terms)
    {
      monomial monom = G_i.Get_monomials()[terms];
      int coeff = monom.Get_coeff();
      vector<int> monom_vec = table[monom.Get_term()].first;
      if (isDivisible(monom_vec,LT_j_vec))
	{
	  changed = true;
	  reductions ++;
	  /*
	  for (int i = 0; i < monom_vec.size(); ++i)
	    {
	      cout << monom_vec[i] << ",";
	    }
	  cout << "LT_G_j " << endl;
	  for (int i = 0; i < LT_j_vec.size(); ++i)
	    {
	      cout << LT_j_vec[i] << ",";
	    }
	  cout << endl;
	  changed = true;
	  /*
	  cout << "G_i before: " << G_i << endl << endl;
	  cout << "G_j: " << polynomial({monomial(get_remainder(monom.Get_term(),G_j.Get_LT()),monom.Get_coeff()*Inverse(G_j.Get_LC(),monom.Get_p()),monom.Get_p())}) << endl << endl;
	  */
	  polynomial vG_j = G_j.Multiply(get_remainder(monom_vec,LT_j_vec)); //term multi
	  //vG_j = G_j.Multiply(monom.Get_coeff()*Inverse(G_j.Get_LC(),monom.Get_p()),true,table);//constant multi
	  int c = coeff*Inverse(vG_j.Get_LC(),vG_j.Get_p());
	  /*


	  cout << "G_i: " << G_i << endl;
	  */
	  G_i = G_i - vG_j.Multiply(c,true);
	  //cout << "G_i after : " << G_i<< endl << endl;
	}
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rcx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rdi, %rbx
movq %rsi, 0x8(%rsp)
movq (%rsi), %rax
movslq (%rax), %rax
leaq 0xa419(%rip), %rcx      # 0x18170
imulq $0x30, %rax, %rsi
addq (%rcx), %rsi
leaq 0x28(%rsp), %rdi
callq 0x3a1a
pushq $0x8
popq %rdx
xorl %r14d, %r14d
leaq 0xb0(%rsp), %r15
leaq 0x98(%rsp), %rbp
movq %rbx, (%rsp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r14
jge 0xdeca
movl (%rax,%rdx), %ebx
movq %rdx, 0x20(%rsp)
imulq $0x30, -0x8(%rax,%rdx), %rsi
leaq 0xa3bf(%rip), %rax      # 0x18170
addq (%rax), %rsi
movq %r15, %rdi
callq 0x3a1a
movq %r15, %r12
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x36f2
testb %al, %al
je 0xdeaa
movq 0x10(%rsp), %rax
movb $0x1, (%rax)
movq 0x18(%rsp), %rax
incl (%rax)
leaq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x3a1a
movq %rbp, %r15
movq %rbp, %rdi
leaq 0x28(%rsp), %rsi
callq 0x3a1a
leaq 0x78(%rsp), %r13
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
movq %r15, %rdx
callq 0xd81b
leaq 0x58(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
callq 0x52fe
movq %r13, %rdi
callq 0x2dfe
movq %rbp, %rdi
callq 0x2dfe
leaq 0x40(%rsp), %rdi
callq 0x2dfe
movq 0x58(%rsp), %rax
movl 0x8(%rax), %edi
movl 0xc(%rax), %esi
callq 0x3274
imull %ebx, %eax
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
leaq 0x58(%rsp), %rsi
movl %eax, %edx
pushq $0x1
popq %rcx
callq 0x54e6
leaq 0x78(%rsp), %r15
movq %r15, %rdi
movq (%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq 0x56ba
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4ef0
movq %r15, %rdi
callq 0x2f74
movq %r13, %rdi
callq 0x2f74
leaq 0x58(%rsp), %rdi
callq 0x2f74
movq %r12, %r15
movq %r12, %rdi
callq 0x2dfe
incq %r14
movq 0x20(%rsp), %rdx
addq $0x10, %rdx
movq (%rsp), %rbx
jmp 0xdd82
leaq 0x28(%rsp), %rdi
callq 0x2dfe
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xdf40
movq %rax, %rbx
jmp 0xdf2f
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x2f74
jmp 0xdf13
jmp 0xdf10
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x2dfe
jmp 0xdf22
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x2f74
jmp 0xdf43
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x2dfe
leaq 0x40(%rsp), %rdi
callq 0x2dfe
jmp 0xdf43
movq %rax, %rbx
jmp 0xdf50
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x2dfe
leaq 0x28(%rsp), %rdi
callq 0x2dfe
movq %rbx, %rdi
callq 0x2260