// File: /workspace/github_cpp_makefile_star2_O3/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, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rdi, %rbx
movq %rsi, 0x48(%rsp)
movq (%rsi), %rax
movslq (%rax), %rax
leaq 0x8d69(%rip), %rcx      # 0x1a170
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
addq (%rcx), %rsi
leaq 0x30(%rsp), %rdi
callq 0x4214
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
testl %ecx, %ecx
jle 0x1163c
movl $0x8, %r14d
xorl %r15d, %r15d
leaq 0xb0(%rsp), %r12
movq %rbx, 0x28(%rsp)
movq -0x8(%rax,%r14), %rcx
movl (%rax,%r14), %ebp
leaq (%rcx,%rcx,2), %rsi
shlq $0x4, %rsi
leaq 0x8d10(%rip), %rax      # 0x1a170
addq (%rax), %rsi
movq %r12, %rbx
movq %r12, %rdi
callq 0x4214
movq %rbx, %r12
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
callq 0x3bf9
testb %al, %al
je 0x115f9
movq 0x50(%rsp), %rax
movb $0x1, (%rax)
movq 0x58(%rsp), %rax
incl (%rax)
leaq 0x60(%rsp), %rdi
movq %r12, %rsi
callq 0x4214
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
callq 0x4214
movq %rsp, %r13
movq %r13, %rdi
leaq 0x60(%rsp), %rsi
movq %rbx, %rdx
callq 0x10d0f
leaq 0x78(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %r13, %rdx
callq 0x6780
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x114f2
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x1150f
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x11526
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x78(%rsp), %rax
movl 0x8(%rax), %edi
movl 0xc(%rax), %esi
callq 0x353e
imull %ebp, %eax
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
leaq 0x78(%rsp), %rsi
movl %eax, %edx
movl $0x1, %ecx
callq 0x6992
movq %rsp, %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq 0x6bd0
movq (%rbx), %rdi
movq 0x10(%rbx), %rsi
movaps (%rsp), %xmm0
movups %xmm0, (%rbx)
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rdi, %rdi
je 0x115bb
subq %rdi, %rsi
callq 0x2180
movq (%rsp), %rdi
movl 0x18(%rsp), %eax
movl %eax, 0x18(%rbx)
testq %rdi, %rdi
je 0x115c2
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x115c2
movl 0x18(%rsp), %eax
movl %eax, 0x18(%rbx)
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x115df
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x115f9
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x11616
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
incq %r15
movq 0x28(%rsp), %rbx
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
movslq %ecx, %rcx
addq $0x10, %r14
cmpq %rcx, %r15
jl 0x11448
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x11653
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x116a9
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1168c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x1168c
jmp 0x116ba
jmp 0x11700
movq %rax, %rbx
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x116a9
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x11703
movq 0x70(%rsp), %rsi
jmp 0x116f1
movq %rax, %rbx
jmp 0x116df
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x116df
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x11703
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x11703
movq %rax, %rbx
jmp 0x11720
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x11720
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x11737
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2240