// File: /workspace/github_cpp_makefile_star2_O2/manschga[P]M5GB/main.cpp
// Function: main
int main(int argc, char *argv[])
{
  int n = 20;
  int d = 10;
  binom_table = Create_binom_table(n+d,n+d);
  cout << "binom table created!" << endl;
  table = Create_table(n,d); //check, maybe neednot d = n!
  cout << "size: " << table.size() << endl;
  int p = 2;
  //const string input_file("Examples/medium_ideal.txt");
  //const string input_file("Examples/test_ideal.txt");
  //const string input_file("Examples/small_test.txt");
  //const string input_file("Examples/test_ideal_orig.txt");
  //const string input_file("Examples/example_2.txt");
  //const string input_file("Examples/big_example.txt");
  const string input_file("Examples/n_20.txt");
  //const string input_file("Examples/ToyExample-type4-n10-seed3");
  //const string input_file("Examples/ToyExample-type4-n15-seed0");
  //const string input_file("katsura_4.txt");
  //const string input_file("Examples/example_31.txt");

  vector<polynomial> system_ = Create_poly_system(input_file,n,p);
  //#define PRINT
  
  #ifdef PRINT
  cout << "Polynomials before reduce:" << endl;
  for (int i = 0; i < system_.size(); ++i)
    {
      vector<vector<int>> poly_i = vec_from_poly(system_[i],n);
	for (int j = 0; j < poly_i.size(); ++j)
	  {
	    bool is_zero = true;
	    for (int k = 0; k < poly_i[j].size(); ++k)
	      {
		if ((poly_i[j])[k]>0 )
		{
		  is_zero = false;
		  cout << char(97+k) << (poly_i[j])[k];
		//		    cout << "x_" << k+1 << "^" << ((poly_i[j])[k] );
		}
	      }
	    if (is_zero)
	      cout << "1";
	    if (j < poly_i.size()-1)
	    cout << "+";
	  }
      //      cout << basis[i] << endl;
	cout << "," << endl;
    }
  #endif

  cout << "M5GB start!!!!!" << endl << endl;

  
  //  Basis solution = M5GB(system_,n);
    
  vector<polynomial> basis = M5GB(system_,n);//Poly(solution,n,p); //remove signatures

  
  /*
  //cout << "not reduced basis:" << endl;
  for (int i = 0; i < basis.size(); ++i)
    {
      basis[i].update();
      //cout << basis[i] << endl;
    }

  int size = 0;
  int size_before = 1;
  size = 0;
  size_before = 1;
  while(size != size_before)
    {
      size_before = basis.size();
      reduce(basis); //get the (unique) reduced gröbner basis
      //cout << "in here! " << endl;
      size = basis.size();//maybe the size drops
    }
  sort(basis);
  */

  sort(basis);
  ///*
  cout << "Gröbner Basis polynomials:" << endl;
  for (int i = 0; i < basis.size(); ++i)
    {
      vector<vector<int>> poly_i = vec_from_poly(basis[i],n);
      for (int j = 0; j < poly_i.size(); ++j)
	  {
	    bool is_zero = true;
	    cout << basis[i].Get_monomials()[j].Get_coeff();
	    for (int k = 0; k < poly_i[j].size(); ++k)
	      {
		if ((poly_i[j])[k]>0 )
		{
		  is_zero = false;
		  cout << char(97+k) << (poly_i[j])[k];
		//		    cout << "x_" << k+1 << "^" << ((poly_i[j])[k] );
		}
	      }
	    if (is_zero)
	      cout << "1";
	    if (j < poly_i.size()-1)
	    cout << "+";
	  }
	cout << "," << endl;
    }
  //*/
 

  //cout << "basis size:" << basis.size() << endl;

     return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
leaq 0x58(%rsp), %rbx
pushq $0x1e
popq %rdx
movq %rbx, %rdi
movl %edx, %esi
callq 0x3300
leaq 0x15875(%rip), %rdi     # 0x18188
movq %rbx, %rsi
callq 0x2d4a
movq %rbx, %rdi
callq 0x2be6
movq 0x156ae(%rip), %r14     # 0x17fd8
leaq 0xc6d3(%rip), %rsi      # 0xf004
movq %r14, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
leaq 0x58(%rsp), %r15
pushq $0x14
popq %rbx
pushq $0xa
popq %rdx
movq %r15, %rdi
movl %ebx, %esi
callq 0x372f
leaq 0x15813(%rip), %r12     # 0x18170
movq %r12, %rdi
movq %r15, %rsi
callq 0x2e48
movq %r15, %rdi
callq 0x2c08
leaq 0xc7c0(%rip), %rsi      # 0xf137
movq %r14, %rdi
callq 0x2180
movq %rax, %rdi
movq 0x8(%r12), %rax
subq (%r12), %rax
pushq $0x30
popq %rcx
cqto
idivq %rcx
movq %rax, %rsi
callq 0x2110
movq %rax, %rdi
callq 0x20d0
leaq 0xc66f(%rip), %rsi      # 0xf019
leaq 0x58(%rsp), %r14
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
callq 0x2c2a
leaq 0x40(%rsp), %rdi
pushq $0x2
popq %rcx
movq %r14, %rsi
movl %ebx, %edx
callq 0xd8ca
movq 0x15603(%rip), %rdi     # 0x17fd8
leaq 0xc64f(%rip), %rsi      # 0xf02b
callq 0x2180
movq %rax, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x20d0
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
pushq $0x14
popq %rdx
callq 0x62d4
leaq 0x20(%rsp), %rdi
callq 0xe05d
movq 0x155c4(%rip), %rdi     # 0x17fd8
leaq 0xc620(%rip), %rsi      # 0xf03b
callq 0x2180
movq %rax, %rdi
callq 0x20d0
xorl %ebp, %ebp
leaq 0x8(%rsp), %rbx
pushq $0x18
popq %r13
movq 0x1559e(%rip), %r14     # 0x17fd8
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rbp, %rax
jbe 0x2b6c
movq %rbp, 0x38(%rsp)
shlq $0x5, %rbp
addq %rbp, %rsi
movq %rbx, %rdi
pushq $0x14
popq %rdx
callq 0xdb04
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
subq 0x8(%rsp), %rax
cqto
idivq %r13
cmpq %rbx, %rax
jbe 0x2b3b
movq 0x20(%rsp), %rax
movq (%rax,%rbp), %rax
movq %rbx, %rcx
shlq $0x4, %rcx
movl 0x8(%rax,%rcx), %esi
movq %r14, %rdi
callq 0x2250
movb $0x1, %al
imulq $0x18, %rbx, %r15
xorl %r12d, %r12d
movq 0x8(%rsp), %rcx
movq (%rcx,%r15), %rdx
movq 0x8(%rcx,%r15), %rsi
subq %rdx, %rsi
sarq $0x2, %rsi
cmpq %r12, %rsi
jbe 0x2af7
cmpl $0x0, (%rdx,%r12,4)
jle 0x2af2
leal 0x61(%r12), %eax
movsbl %al, %esi
movq %r14, %rdi
callq 0x21d0
movq 0x8(%rsp), %rcx
movq (%rcx,%r15), %rcx
movl (%rcx,%r12,4), %esi
movq %rax, %rdi
callq 0x2250
xorl %eax, %eax
incq %r12
jmp 0x2aaa
testb $0x1, %al
je 0x2b0f
movq %r14, %rdi
leaq 0xc552(%rip), %rsi      # 0xf057
callq 0x2180
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
subq %rcx, %rax
cqto
idivq %r13
decq %rax
cmpq %rbx, %rax
jbe 0x2b33
movq %r14, %rdi
leaq 0xc52b(%rip), %rsi      # 0xf059
callq 0x2180
incq %rbx
jmp 0x2a6d
movq %r14, %rdi
leaq 0xc516(%rip), %rsi      # 0xf05b
callq 0x2180
movq %rax, %rdi
callq 0x20d0
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x2c66
movq 0x38(%rsp), %rbp
incq %rbp
jmp 0x2a3a
leaq 0x20(%rsp), %rdi
callq 0x2c88
leaq 0x40(%rsp), %rdi
callq 0x2c88
leaq 0x58(%rsp), %rdi
callq 0x20c0
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2ba4
movq %rax, %rbx
jmp 0x2bd3
jmp 0x2ba9
movq %rax, %rbx
jmp 0x2bc9
movq %rax, %rbx
jmp 0x2bbf
jmp 0x2bb2
jmp 0x2bb2
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2c66
leaq 0x20(%rsp), %rdi
callq 0x2c88
leaq 0x40(%rsp), %rdi
callq 0x2c88
leaq 0x58(%rsp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x2260
nop