// File: manschga[P]M5GB/poly.cpp
// Function: reduce(std::vector<polynomial, std::allocator<polynomial>>&)
int reduce(vector<polynomial>& G)
{
  int reductions = 0;
  int size = 0;
  int size_before = 1;
  while(size != size_before)
    {
      size_before = G.size();
      
      bool changed = true;
      while (changed)
	{
	  changed = false;
	  int size = G.size();
	  int i = 0;
	  while (i < G.size())
	    {
	      int j = 0;
	      while (j < G.size())
		{
		  if (j != i)
		    {
		      reduce(G[i],G[j],changed,reductions);//reduce G[i] by all other in G
		      int LT_G = G[i].Get_LT();
		      int LC_G = G[i].Get_LC();
		      if (LT_G == 0 && LC_G == 0) //is zero-polynomial
			{
			  G.erase (G.begin()+i);
			  size--;
			  j = G.size();
			  i = G.size();
			}
		    }
		  ++j;
		}
	      ++i;
	    }
	}
      //lc 1
      /* //works for p = 2
	 for (int i = 0; i < G.size(); ++i)
	 {
	 G[i] = G[i]*Inverse(G[i].Get_LC(),G[i].Get_p());
	 }
      */
      size = G.size();//maybe the size drops
    }
  return reductions;
  //sort(G);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x26bea
movq -0x8(%rbp), %rdi
callq 0x3180
movl %eax, -0x14(%rbp)
movb $0x1, -0x15(%rbp)
testb $0x1, -0x15(%rbp)
je 0x26bd9
movb $0x0, -0x15(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3180
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movslq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3180
movq %rax, %rcx
movq -0x58(%rbp), %rax
cmpq %rcx, %rax
jae 0x26bd4
movl $0x0, -0x24(%rbp)
movslq -0x24(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3180
movq %rax, %rcx
movq -0x60(%rbp), %rax
cmpq %rcx, %rax
jae 0x26bc6
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x26bb8
movq -0x8(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x31a0
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x31a0
movq -0x68(%rbp), %rdi
movq %rax, %rsi
leaq -0x15(%rbp), %rdx
leaq -0xc(%rbp), %rcx
callq 0x26c00
movq -0x8(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x31a0
movq %rax, %rdi
callq 0x17490
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x31a0
movq %rax, %rdi
callq 0xe7c0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x26bb6
cmpl $0x0, -0x2c(%rbp)
jne 0x26bb6
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
callq 0xfd40
movq %rax, -0x48(%rbp)
movslq -0x20(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x17840
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x28760
movq -0x70(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x286f0
movq %rax, -0x50(%rbp)
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3180
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3180
movl %eax, -0x20(%rbp)
jmp 0x26bb8
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x26ab6
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x26a8e
jmp 0x26a6d
movq -0x8(%rbp), %rdi
callq 0x3180
movl %eax, -0x10(%rbp)
jmp 0x26a51
movl -0xc(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)