// File: /workspace/github_cpp_makefile_star2_O3/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 $0x88, %rsp
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movl $0x1e, %esi
movl $0x1e, %edx
callq 0x3608
leaq 0x175dd(%rip), %rax     # 0x1a188
movq 0x10(%rax), %rcx
movaps (%rbx), %xmm0
movq 0x10(%rbx), %rdx
movq %rdx, 0x10(%rax)
movups (%rax), %xmm1
movups %xmm0, (%rax)
leaq 0x20(%rsp), %r14
movaps %xmm1, (%r14)
movq %rcx, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
xorl %r12d, %r12d
movq %r12, 0x10(%rbx)
movq %r14, %rdi
callq 0x3054
movq %rbx, %rdi
callq 0x3054
movq 0x173e7(%rip), %rbx     # 0x19fd8
leaq 0x10428(%rip), %rsi     # 0x13020
movl $0x14, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movl $0x14, %esi
movl $0xa, %edx
callq 0x3c41
leaq 0x17526(%rip), %r13     # 0x1a170
movq 0x10(%r13), %rax
movaps (%r15), %xmm0
movq 0x10(%r15), %rcx
movq %rcx, 0x10(%r13)
movups (%r13), %xmm1
movups %xmm0, (%r13)
movaps %xmm1, (%r14)
movq %rax, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movq %r12, 0x10(%r15)
leaq 0x20(%rsp), %rdi
callq 0x30a8
movq %r15, %rdi
callq 0x30a8
leaq 0x104f7(%rip), %rsi     # 0x13187
movl $0x6, %edx
movq %rbx, %rdi
callq 0x21a0
movq 0x8(%r13), %rsi
subq (%r13), %rsi
sarq $0x4, %rsi
movabsq $-0x5555555555555555, %r15 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r15, %rsi
movq %rbx, %rdi
callq 0x20e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1033c(%rip), %rsi     # 0x13035
leaq 0x10346(%rip), %rdx     # 0x13046
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x31d4
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
movl $0x14, %edx
movl $0x2, %ecx
callq 0x10e1c
movq 0x172ad(%rip), %rbx     # 0x19fd8
leaq 0x10315(%rip), %rsi     # 0x13047
movl $0xf, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x1727b(%rip), %rdi     # 0x19fd8
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x48(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movl $0x14, %edx
callq 0x79fc
leaq 0x48(%rsp), %rdi
callq 0x118a1
movq 0x1721f(%rip), %rbx     # 0x19fd8
leaq 0x10297(%rip), %rsi     # 0x13057
movl $0x1b, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x171ed(%rip), %rbx     # 0x19fd8
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movq 0x48(%rsp), %rsi
cmpq %rsi, 0x50(%rsp)
je 0x2fb4
xorl %ecx, %ecx
leaq 0x8(%rsp), %r14
leaq 0x7(%rsp), %rbp
movq %rcx, 0x78(%rsp)
shlq $0x5, %rcx
movq %rcx, 0x80(%rsp)
addq %rcx, %rsi
movq %r14, %rdi
movl $0x14, %edx
callq 0x11149
movq 0x10(%rsp), %rax
cmpq 0x8(%rsp), %rax
je 0x2f4a
xorl %r12d, %r12d
movq 0x48(%rsp), %rax
movq 0x80(%rsp), %rcx
movq (%rax,%rcx), %rax
movq %r12, %rcx
shlq $0x4, %rcx
movl 0x8(%rax,%rcx), %esi
movq %rbx, %rdi
callq 0x2230
movq 0x8(%rsp), %rax
leaq (%r12,%r12,2), %r13
movq (%rax,%r13,8), %rdx
cmpq %rdx, 0x8(%rax,%r13,8)
je 0x2ee6
movq %r15, %r14
movb $0x1, %cl
xorl %r15d, %r15d
cmpl $0x0, (%rdx,%r15,4)
jle 0x2ec6
leal 0x61(%r15), %eax
movb %al, 0x7(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x21a0
movq 0x8(%rsp), %rcx
movq (%rcx,%r13,8), %rcx
movl (%rcx,%r15,4), %esi
movq %rax, %rdi
callq 0x2230
movq 0x8(%rsp), %rax
xorl %ecx, %ecx
incq %r15
movq (%rax,%r13,8), %rdx
movq 0x8(%rax,%r13,8), %rsi
subq %rdx, %rsi
sarq $0x2, %rsi
cmpq %r15, %rsi
ja 0x2e8b
testb $0x1, %cl
movq %r14, %r15
je 0x2eff
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x1017e(%rip), %rsi     # 0x13073
callq 0x21a0
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r15, %rcx
leaq -0x1(%rcx), %rax
cmpq %r12, %rax
jbe 0x2f3e
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x1014e(%rip), %rsi     # 0x13075
callq 0x21a0
movq 0x10(%rsp), %rcx
subq 0x8(%rsp), %rcx
sarq $0x3, %rcx
imulq %r15, %rcx
incq %r12
cmpq %r12, %rcx
ja 0x2e4b
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x1011e(%rip), %rsi     # 0x13077
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x30d8
movq 0x78(%rsp), %rcx
incq %rcx
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rcx, %rax
ja 0x2e17
leaq 0x48(%rsp), %rdi
callq 0x312c
leaq 0x60(%rsp), %rdi
callq 0x312c
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x2fe4
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2180
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3001
movq %rax, %rbx
jmp 0x3035
jmp 0x3006
movq %rax, %rbx
jmp 0x302b
movq %rax, %rbx
jmp 0x301c
jmp 0x300f
jmp 0x300f
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x30d8
leaq 0x30(%rsp), %r14
leaq 0x48(%rsp), %rdi
callq 0x312c
leaq 0x60(%rsp), %rdi
callq 0x312c
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x304c
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2240