// File: /workspace/github_cpp_makefile_star2_O1/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 0x70(%rsp), %rbx
movq %rbx, %rdi
movl $0x1e, %esi
movl $0x1e, %edx
callq 0x35e3
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r14
movaps %xmm0, (%r14)
leaq 0x175e9(%rip), %rax     # 0x1a180
movups (%rax), %xmm0
movq 0x10(%rax), %rcx
movups (%rbx), %xmm1
movups %xmm1, (%rax)
movq 0x10(%rbx), %rdx
movq %rdx, 0x10(%rax)
movaps (%r14), %xmm1
movaps %xmm0, (%r14)
movq %rcx, 0x10(%r14)
movups %xmm1, (%rbx)
xorl %r12d, %r12d
movq %r12, 0x10(%rbx)
movq %r14, %rdi
callq 0x303a
movq %rbx, %rdi
callq 0x303a
movq 0x173ff(%rip), %rbx     # 0x19fd8
leaq 0x10440(%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 0x70(%rsp), %r15
movq %r15, %rdi
movl $0x14, %esi
movl $0xa, %edx
callq 0x3c1c
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
leaq 0x1752f(%rip), %r13     # 0x1a168
movups (%r13), %xmm0
movq 0x10(%r13), %rax
movups (%r15), %xmm1
movups %xmm1, (%r13)
movq 0x10(%r15), %rcx
movq %rcx, 0x10(%r13)
movaps (%r14), %xmm1
movaps %xmm0, (%r14)
movq %rax, 0x10(%r14)
movups %xmm1, (%r15)
movq %r12, 0x10(%r15)
leaq 0x20(%rsp), %rdi
callq 0x3088
movq %r15, %rdi
callq 0x3088
leaq 0x104aa(%rip), %rsi     # 0x1312a
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 0x1034c(%rip), %rsi     # 0x13035
leaq 0x10356(%rip), %rdx     # 0x13046
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x31a8
leaq 0x70(%rsp), %rdi
movq %rbx, %rsi
movl $0x14, %edx
movl $0x2, %ecx
callq 0x10855
movq 0x172bd(%rip), %rbx     # 0x19fd8
leaq 0x10325(%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 0x1728b(%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 0x70(%rsp), %rsi
movl $0x14, %edx
callq 0x749c
leaq 0x48(%rsp), %rdi
callq 0x11295
movq 0x1722f(%rip), %rbx     # 0x19fd8
leaq 0x102a7(%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 0x171fd(%rip), %rbx     # 0x19fd8
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movq 0x48(%rsp), %rsi
cmpq %rsi, 0x50(%rsp)
je 0x2f99
xorl %ecx, %ecx
leaq 0x8(%rsp), %r14
leaq 0x7(%rsp), %rbp
movq %rcx, 0x60(%rsp)
shlq $0x5, %rcx
movq %rcx, 0x68(%rsp)
addq %rcx, %rsi
movq %r14, %rdi
movl $0x14, %edx
callq 0x10b78
movq 0x10(%rsp), %rax
cmpq 0x8(%rsp), %rax
je 0x2f2f
xorl %r12d, %r12d
movq 0x48(%rsp), %rax
movq 0x68(%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), %rcx
cmpq %rcx, 0x8(%rax,%r13,8)
je 0x2ecf
movq %r15, %r14
movb $0x1, %al
xorl %r15d, %r15d
cmpl $0x0, (%rcx,%r15,4)
jle 0x2eab
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
xorl %eax, %eax
incq %r15
movq 0x8(%rsp), %rdx
movq (%rdx,%r13,8), %rcx
movq 0x8(%rdx,%r13,8), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %r15, %rdx
ja 0x2e75
testb $0x1, %al
movq %r14, %r15
je 0x2ee3
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x10195(%rip), %rsi     # 0x13073
callq 0x21a0
movq 0x10(%rsp), %rax
subq 0x8(%rsp), %rax
sarq $0x3, %rax
imulq %r15, %rax
decq %rax
cmpq %r12, %rax
jbe 0x2f11
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x10169(%rip), %rsi     # 0x13075
callq 0x21a0
movq 0x10(%rsp), %rax
subq 0x8(%rsp), %rax
incq %r12
sarq $0x3, %rax
imulq %r15, %rax
cmpq %r12, %rax
ja 0x2e38
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x10139(%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 0x30b8
movq 0x60(%rsp), %rcx
incq %rcx
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rcx, %rax
ja 0x2e07
leaq 0x48(%rsp), %rdi
callq 0x3106
leaq 0x70(%rsp), %rdi
callq 0x3106
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x2fc9
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 0x2fe6
movq %rax, %rbx
jmp 0x301a
jmp 0x2feb
movq %rax, %rbx
jmp 0x3010
movq %rax, %rbx
jmp 0x3001
jmp 0x2ff4
jmp 0x2ff4
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x30b8
leaq 0x30(%rsp), %r14
leaq 0x48(%rsp), %rdi
callq 0x3106
leaq 0x70(%rsp), %rdi
callq 0x3106
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x3031
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2240
nop