// File: /workspace/github_cpp_makefile_star2_O1/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 0x9340(%rip), %rcx      # 0x1a168
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
addq (%rcx), %rsi
leaq 0x10(%rsp), %rdi
callq 0x405e
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
testl %ecx, %ecx
jle 0x11035
movl $0x8, %r14d
xorl %r15d, %r15d
leaq 0xb0(%rsp), %r12
movq %rbx, 0x8(%rsp)
movq -0x8(%rax,%r14), %rcx
movl (%rax,%r14), %ebp
leaq (%rcx,%rcx,2), %rsi
shlq $0x4, %rsi
leaq 0x92e7(%rip), %rax      # 0x1a168
addq (%rax), %rsi
movq %r12, %rbx
movq %r12, %rdi
callq 0x405e
movq %rbx, %r12
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3bd6
testb %al, %al
je 0x10ff2
movq 0x50(%rsp), %rax
movb $0x1, (%rax)
movq 0x58(%rsp), %rax
incl (%rax)
leaq 0x60(%rsp), %rdi
movq %r12, %rsi
callq 0x405e
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0x405e
leaq 0x28(%rsp), %r13
movq %r13, %rdi
leaq 0x60(%rsp), %rsi
movq %rbx, %rdx
callq 0x1074e
leaq 0x78(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %r13, %rdx
callq 0x61f0
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x10f16
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x10f33
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x10f4a
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x78(%rsp), %rax
movl 0x8(%rax), %edi
movl 0xc(%rax), %esi
callq 0x3519
imull %ebp, %eax
leaq 0xc8(%rsp), %rbp
movq %rbp, %rdi
leaq 0x78(%rsp), %rsi
movl %eax, %edx
movl $0x1, %ecx
callq 0x6402
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %r13
movq %r13, %rsi
movq %rbp, %rdx
callq 0x6640
movq %r13, %rdi
movq %rbx, %rsi
callq 0x60a8
movl 0x40(%rsp), %eax
movl %eax, 0x18(%r13)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x10fbb
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x10fd8
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x10ff2
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x1100f
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
incq %r15
movq 0x8(%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 0x10e69
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1104c
movq 0x20(%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 0x110a3
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x11086
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x11086
jmp 0x110b4
jmp 0x110fa
movq %rax, %rbx
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x110a3
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x110fd
movq 0x70(%rsp), %rsi
jmp 0x110eb
movq %rax, %rbx
jmp 0x110d9
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x110d9
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x110fd
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
jmp 0x110fd
movq %rax, %rbx
jmp 0x1111a
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x1111a
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x11131
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2240