// File: /workspace/github_cpp_makefile_star2_O2/akinanop[P]mvl-solver/src/GenBenFunc.cc
// Function: GenBenFin(CommandLine*)
void GenBenFin(CommandLine * cline)
{
  //local variables
  int x = 0;
  int y = 0;
  int z = 0;

  srand(time(NULL));

  //Assign Memory to each global variable
  SOLN = new Literal[cline->NUM_VAR];

  CLAUSE_LIST = new Literal *[cline->NUM_CLAUSE];
  for(y=0; y<cline->NUM_CLAUSE; y++)
    CLAUSE_LIST[y] = new Literal[cline->CLAUSE_SIZE];

  VARIABLES = new Literal [cline->NUM_VAR];

  //Assigning domain values to each variable
  //fixed size
  if(!cline->DRAND)
    {
      for(x=0; x<cline->NUM_VAR; x++)
	{
	  VARIABLES[x].VAR = x;
	  VARIABLES[x].VAL = cline->DOMAIN_SIZE;
	}
    }
  //random domain size
  else
    {
      for(x=0; x<cline->NUM_VAR; x++)
	{
	  VARIABLES[x].VAR = x;
	  VARIABLES[x].VAL = rand() % cline->DOMAIN_SIZE;
	}
    }

  //Generating solution
  for(x=0; x<cline->NUM_VAR; x++)
    {
      SOLN[x].VAR = x;
      SOLN[x].VAL = rand() % VARIABLES[x].VAL;
    }

  //Generating clauses
  bool already_exist = false;
  for(y=0; y<cline->NUM_CLAUSE; y++)
    {
      for(x=0; x<cline->CLAUSE_SIZE; x++)
	{
	  //checking if problem needs to be solvable or random
	  //if satisfiable
	  if(cline->SAT_UNSAT && x==0)
	    {
	      //assigning variable to clause
	      CLAUSE_LIST[y][x].VAR = SOLN[rand() % cline->NUM_VAR].VAR;
	      CLAUSE_LIST[y][x].VAL = SOLN[CLAUSE_LIST[y][x].VAR].VAL;
	    }

	  //else unsatisfiable
	  else
	    {
	      //assigning variable to clause
	      CLAUSE_LIST[y][x].VAR = rand() % cline->NUM_VAR;
	      //checking if variable already exist
	      do
		{
		  already_exist = false;
		  for(z=0; z<x && !already_exist; z++)
		    {
		      if(CLAUSE_LIST[y][x].VAR == CLAUSE_LIST[y][z].VAR)
			{
			  CLAUSE_LIST[y][x].VAR = rand() % cline->NUM_VAR;
			  already_exist = true;
			}
		      else
			{
			  already_exist = false;
			}
		    }
		}while(already_exist);
	      CLAUSE_LIST[y][x].VAL = rand() % VARIABLES[CLAUSE_LIST[y][x].VAR].VAL;
	    }
	}
    }

  //opening and writing to outputfile
  ofstream outfile;
  outfile.open(cline->FILE, ios::out);
  if(!outfile)
    {
      cout<<endl;
      cout<<"**** ERROR ****"<<endl;
      cout<<" Could not open output file to write "<<endl;
      cout<<"****       ****"<<endl;
      cout<<endl;
    }
  else
    {
      outfile<<"p cnf "<<cline->NUM_VAR<<" "<<cline->NUM_CLAUSE<<endl;
      for(y=0; y<cline->NUM_VAR; y++)
	{
	  outfile<<"d "<<VARIABLES[y].VAR+1<<" "<<VARIABLES[y].VAL<<endl;
	}
      for(y=0; y<cline->NUM_CLAUSE; y++)
	{
	  for(x=0; x<cline->CLAUSE_SIZE; x++)
	    {
	      outfile<<CLAUSE_LIST[y][x].VAR+1<<"="<<CLAUSE_LIST[y][x].VAL<<" ";
	    }
	  outfile<<"0"<<endl;
	}
    }
  outfile.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdi, %rbx
xorl %r13d, %r13d
xorl %edi, %edi
callq 0x21e0
movl %eax, %edi
callq 0x21f0
movslq 0x4(%rbx), %r14
pushq $0xc
popq %rcx
movq %r14, %rax
mulq %rcx
pushq $-0x1
popq %r15
cmovoq %r15, %rax
movq %rax, (%rsp)
movq %rax, %rdi
callq 0x2030
testq %r14, %r14
je 0x354d
imulq $0xc, %r14, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rax, %rdx
orq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
addq $0xc, %rdx
cmpq %rcx, %rdx
jne 0x353c
movq %rax, 0xbcac(%rip)      # 0xf200
movslq 0x8(%rbx), %r12
leaq (,%r12,8), %rdi
testq %r12, %r12
cmovsq %r15, %rdi
callq 0x2030
movq %rax, 0xbc95(%rip)      # 0xf208
testl %r12d, %r12d
movl $0x0, %ebp
cmovgl %r12d, %ebp
cmpq %rbp, %r13
je 0x35d0
movslq 0xc(%rbx), %r12
movq %r12, %rax
pushq $0xc
popq %rcx
mulq %rcx
cmovoq %r15, %rax
movq %rax, %rdi
callq 0x2030
testq %r12, %r12
je 0x35c0
imulq $0xc, %r12, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rax, %rdx
orq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
addq $0xc, %rdx
cmpq %rcx, %rdx
jne 0x35af
movq 0xbc41(%rip), %rcx      # 0xf208
movq %rax, (%rcx,%r13,8)
incq %r13
jmp 0x357f
movq (%rsp), %rdi
callq 0x2030
testl %r14d, %r14d
je 0x35f9
imulq $0xc, %r14, %rcx
addq %rax, %rcx
movq %rax, %rdx
orq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
addq $0xc, %rdx
cmpq %rcx, %rdx
jne 0x35e8
movq %rax, 0xbc10(%rip)      # 0xf210
cmpb $0x1, 0x18(%rbx)
jne 0x363a
xorl %r15d, %r15d
xorl %r12d, %r12d
movslq %r14d, %rcx
cmpq %rcx, %r12
jge 0x3662
movl %r12d, (%rax,%r15)
callq 0x20b0
cltd
idivl 0x14(%rbx)
movq 0xbbe8(%rip), %rax      # 0xf210
movl %edx, 0x4(%rax,%r15)
incq %r12
movl 0x4(%rbx), %r14d
addq $0xc, %r15
jmp 0x360c
xorl %ecx, %ecx
testl %r14d, %r14d
movl $0x0, %edx
cmovgl %r14d, %edx
addq $0x4, %rax
cmpq %rcx, %rdx
je 0x3662
movl %ecx, -0x4(%rax)
movl 0x14(%rbx), %esi
movl %esi, (%rax)
incq %rcx
addq $0xc, %rax
jmp 0x364c
xorl %r15d, %r15d
xorl %r12d, %r12d
movslq %r14d, %rax
cmpq %rax, %r12
jge 0x36a6
movq 0xbb89(%rip), %rax      # 0xf200
movl %r12d, (%rax,%r15)
callq 0x20b0
movq 0xbb89(%rip), %rcx      # 0xf210
cltd
idivl 0x4(%rcx,%r15)
movq 0xbb6c(%rip), %rax      # 0xf200
movl %edx, 0x4(%rax,%r15)
incq %r12
movl 0x4(%rbx), %r14d
addq $0xc, %r15
jmp 0x3668
xorl %r14d, %r14d
movslq 0x8(%rbx), %rax
cmpq %rax, %r14
jge 0x37b6
xorl %r15d, %r15d
movslq 0xc(%rbx), %rax
cmpq %rax, %r15
jge 0x37ae
testq %r15, %r15
jne 0x370d
cmpb $0x0, 0x10(%rbx)
je 0x370d
movq 0xbb28(%rip), %r12      # 0xf200
callq 0x20b0
cltd
idivl 0x4(%rbx)
movslq %edx, %rax
imulq $0xc, %rax, %rax
movslq (%r12,%rax), %rax
movq 0xbb15(%rip), %rcx      # 0xf208
movq (%rcx,%r14,8), %rcx
movl %eax, (%rcx)
movq 0xbb00(%rip), %rdx      # 0xf200
imulq $0xc, %rax, %rax
movl 0x4(%rdx,%rax), %edx
jmp 0x37a3
callq 0x20b0
cltd
idivl 0x4(%rbx)
movq 0xbaeb(%rip), %rax      # 0xf208
movq (%rax,%r14,8), %rcx
imulq $0xc, %r15, %r12
movl %edx, (%rcx,%r12)
xorl %r13d, %r13d
xorl %ebp, %ebp
cmpq %r15, %r13
jae 0x3739
testb $0x1, %bpl
je 0x3749
xorl %r13d, %r13d
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x372e
jmp 0x377b
movq (%rax,%r14,8), %rcx
movl (%rcx,%r12), %edx
imulq $0xc, %r13, %rsi
cmpl (%rcx,%rsi), %edx
sete %bpl
jne 0x3776
callq 0x20b0
cltd
idivl 0x4(%rbx)
movq 0xba9a(%rip), %rax      # 0xf208
movq (%rax,%r14,8), %rcx
movl %edx, (%rcx,%r12)
incq %r13
jmp 0x372e
callq 0x20b0
movq 0xba89(%rip), %rsi      # 0xf210
movq 0xba7a(%rip), %rcx      # 0xf208
movq (%rcx,%r14,8), %rdx
leaq (%rdx,%r12), %rcx
movslq (%rdx,%r12), %rdx
imulq $0xc, %rdx, %rdi
cltd
idivl 0x4(%rsi,%rdi)
movl %edx, 0x4(%rcx)
incq %r15
jmp 0x36b9
incq %r14
jmp 0x36a9
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x2370
movq 0x20(%rbx), %rsi
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x2060
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x28(%rsp,%rax)
je 0x3875
movq 0xb7e3(%rip), %rdi      # 0xefd0
callq 0x2140
movq 0xb7d7(%rip), %rdi      # 0xefd0
leaq 0x72d4(%rip), %rsi      # 0xaad4
callq 0x2210
movq %rax, %rdi
callq 0x2140
movq 0xb7bc(%rip), %rdi      # 0xefd0
leaq 0x72c9(%rip), %rsi      # 0xaae4
callq 0x2210
movq %rax, %rdi
callq 0x2140
movq 0xb7a1(%rip), %rdi      # 0xefd0
leaq 0x72d4(%rip), %rsi      # 0xab0a
callq 0x2210
movq %rax, %rdi
callq 0x2140
movq 0xb786(%rip), %rdi      # 0xefd0
callq 0x2140
leaq 0x8(%rsp), %rdi
callq 0x22e0
leaq 0x8(%rsp), %rdi
callq 0x2300
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x729e(%rip), %rsi      # 0xab1a
leaq 0x8(%rsp), %rdi
callq 0x2210
movl 0x4(%rbx), %esi
movq %rax, %rdi
callq 0x2380
leaq 0x69af(%rip), %rsi      # 0xa247
movq %rax, %rdi
callq 0x2210
movl 0x8(%rbx), %esi
movq %rax, %rdi
callq 0x2380
movq %rax, %rdi
callq 0x2140
xorl %r13d, %r13d
leaq 0x7264(%rip), %r14      # 0xab21
leaq 0x8(%rsp), %r15
leaq 0x697e(%rip), %r12      # 0xa247
xorl %ebp, %ebp
movslq 0x4(%rbx), %rax
cmpq %rax, %rbp
jge 0x3924
movq %r15, %rdi
movq %r14, %rsi
callq 0x2210
movq 0xb92a(%rip), %rcx      # 0xf210
movl (%rcx,%r13), %esi
incl %esi
movq %rax, %rdi
callq 0x2380
movq %rax, %rdi
movq %r12, %rsi
callq 0x2210
movq 0xb90a(%rip), %rcx      # 0xf210
movl 0x4(%rcx,%r13), %esi
movq %rax, %rdi
callq 0x2380
movq %rax, %rdi
callq 0x2140
incq %rbp
addq $0xc, %r13
jmp 0x38cb
xorl %ebp, %ebp
leaq 0x8(%rsp), %r14
leaq 0x6915(%rip), %r12      # 0xa247
movslq 0x8(%rbx), %rax
cmpq %rax, %rbp
jge 0x384f
xorl %r13d, %r13d
xorl %r15d, %r15d
movslq 0xc(%rbx), %rax
cmpq %rax, %r15
jge 0x39a2
movq 0xb8b3(%rip), %rax      # 0xf208
movq (%rax,%rbp,8), %rax
movl (%rax,%r13), %esi
incl %esi
movq %r14, %rdi
callq 0x2380
movq %rax, %rdi
leaq 0x727c(%rip), %rsi      # 0xabed
callq 0x2210
movq 0xb88b(%rip), %rcx      # 0xf208
movq (%rcx,%rbp,8), %rcx
movl 0x4(%rcx,%r13), %esi
movq %rax, %rdi
callq 0x2380
movq %rax, %rdi
movq %r12, %rsi
callq 0x2210
incq %r15
addq $0xc, %r13
jmp 0x3945
movq %r14, %rdi
leaq 0x7223(%rip), %rsi      # 0xabcf
callq 0x2210
movq %rax, %rdi
callq 0x2140
incq %rbp
jmp 0x3932
jmp 0x39c7
jmp 0x39c7
jmp 0x39c7
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2300
movq %rbx, %rdi
callq 0x2390