// File: akinanop[P]mvl-solver/src/GenBenFunc.cc
// Function: GenBenBool(CommandLine*)
void GenBenBool(CommandLine * cline)
{
  //local variables
  int x = 0;
  int y = 0;
  int z = 0;
  int * BSOLN;
  int ** BCLAUSE_LIST;
  srand(time(NULL));

  //Assign Memory to each global variable
  BSOLN = new int[cline->NUM_VAR+1];

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

  //Generating solution
  for(x=1; x<cline->NUM_VAR+1; x++)
    {
      if(rand() % 2)
	BSOLN[x] = x;
      else
	BSOLN[x] = -x;
    }

  //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
	      if(rand()%2)
		{
		  BCLAUSE_LIST[y][x] = BSOLN[(rand() % cline->NUM_VAR)+1];
		}
	      else
		{
		  BCLAUSE_LIST[y][x] = -1 * BSOLN[(rand() % cline->NUM_VAR)+1];
		}
	    }

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

  //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_CLAUSE; y++)
	{
	  for(x=0; x<cline->CLAUSE_SIZE; x++)
	    {
	      outfile<<BCLAUSE_LIST[y][x]<<" ";
	    }
	  outfile<<"0"<<endl;
	}
    }
  outfile.close();
}

// Assembly:
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rdi, 0x2b0(%rsp)
movl $0x0, 0x2ac(%rsp)
movl $0x0, 0x2a8(%rsp)
movl $0x0, 0x2a4(%rsp)
xorl %eax, %eax
movl %eax, %edi
callq 0x21f0
movl %eax, %edi
callq 0x2200
movq 0x2b0(%rsp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, 0x298(%rsp)
movq 0x2b0(%rsp), %rax
movslq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, 0x290(%rsp)
movl $0x0, 0x2a8(%rsp)
movl 0x2a8(%rsp), %eax
movq 0x2b0(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x53d4
movq 0x2b0(%rsp), %rax
movslq 0xc(%rax), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rdx
movq 0x290(%rsp), %rax
movslq 0x2a8(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x2a8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2a8(%rsp)
jmp 0x5369
movl $0x1, 0x2ac(%rsp)
movl 0x2ac(%rsp), %eax
movq 0x2b0(%rsp), %rcx
movl 0x4(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x5457
callq 0x20c0
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x5426
movl 0x2ac(%rsp), %edx
movq 0x298(%rsp), %rax
movslq 0x2ac(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x5442
xorl %edx, %edx
subl 0x2ac(%rsp), %edx
movq 0x298(%rsp), %rax
movslq 0x2ac(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x5444
movl 0x2ac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2ac(%rsp)
jmp 0x53df
movb $0x0, 0x28f(%rsp)
movl $0x0, 0x2a8(%rsp)
movl 0x2a8(%rsp), %eax
movq 0x2b0(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x571c
movl $0x0, 0x2ac(%rsp)
movl 0x2ac(%rsp), %eax
movq 0x2b0(%rsp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x5704
movq 0x2b0(%rsp), %rax
testb $0x1, 0x10(%rax)
je 0x5578
cmpl $0x0, 0x2ac(%rsp)
jne 0x5578
callq 0x20c0
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x5524
movq 0x298(%rsp), %rax
movq %rax, 0x70(%rsp)
callq 0x20c0
movq 0x2b0(%rsp), %rcx
cltd
idivl 0x4(%rcx)
movq 0x70(%rsp), %rax
addl $0x1, %edx
movslq %edx, %rcx
movl (%rax,%rcx,4), %edx
movq 0x290(%rsp), %rax
movslq 0x2a8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x2ac(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x5573
movq 0x298(%rsp), %rax
movq %rax, 0x68(%rsp)
callq 0x20c0
movq 0x2b0(%rsp), %rcx
cltd
idivl 0x4(%rcx)
movq 0x68(%rsp), %rax
addl $0x1, %edx
movslq %edx, %rcx
imull $0xffffffff, (%rax,%rcx,4), %edx # imm = 0xFFFFFFFF
movq 0x290(%rsp), %rax
movslq 0x2a8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x2ac(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x56ec
callq 0x20c0
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x55bf
callq 0x20c0
movq 0x2b0(%rsp), %rcx
cltd
idivl 0x4(%rcx)
addl $0x1, %edx
movq 0x290(%rsp), %rax
movslq 0x2a8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x2ac(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x55f8
callq 0x20c0
movq 0x2b0(%rsp), %rcx
cltd
idivl 0x4(%rcx)
addl $0x1, %edx
imull $0xffffffff, %edx, %edx # imm = 0xFFFFFFFF
movq 0x290(%rsp), %rax
movslq 0x2a8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x2ac(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x55fa
movb $0x0, 0x28f(%rsp)
movl $0x0, 0x2a4(%rsp)
movl 0x2a4(%rsp), %ecx
xorl %eax, %eax
cmpl 0x2ac(%rsp), %ecx
movb %al, 0x67(%rsp)
jge 0x5630
movb 0x28f(%rsp), %al
xorb $-0x1, %al
movb %al, 0x67(%rsp)
movb 0x67(%rsp), %al
testb $0x1, %al
jne 0x563d
jmp 0x56da
movq 0x290(%rsp), %rax
movslq 0x2a8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x2ac(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movq 0x290(%rsp), %rcx
movslq 0x2a8(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0x2a4(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x56ba
callq 0x20c0
movq 0x2b0(%rsp), %rcx
cltd
idivl 0x4(%rcx)
addl $0x1, %edx
movq 0x290(%rsp), %rax
movslq 0x2a8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x2ac(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movb $0x1, 0x28f(%rsp)
jmp 0x56c2
movb $0x0, 0x28f(%rsp)
jmp 0x56c4
movl 0x2a4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2a4(%rsp)
jmp 0x560d
jmp 0x56dc
testb $0x1, 0x28f(%rsp)
jne 0x55fa
jmp 0x56ec
jmp 0x56ee
movl 0x2ac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2ac(%rsp)
jmp 0x548d
jmp 0x5706
movl 0x2a8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2a8(%rsp)
jmp 0x546a
leaq 0x88(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x23f0
movq 0x58(%rsp), %rdi
movq 0x2b0(%rsp), %rax
movq 0x20(%rax), %rsi
movl $0x10, %edx
callq 0x2060
jmp 0x574b
movq 0x88(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x88(%rsp,%rax), %rdi
callq 0x2130
movb %al, 0x57(%rsp)
jmp 0x576a
movb 0x57(%rsp), %al
testb $0x1, %al
jne 0x5777
jmp 0x5850
movq 0x18852(%rip), %rdi     # 0x1dfd0
movq 0x1883b(%rip), %rsi     # 0x1dfc0
callq 0x2260
jmp 0x578c
movq 0x1883d(%rip), %rdi     # 0x1dfd0
leaq 0x1233a(%rip), %rsi     # 0x17ad4
callq 0x2220
movq %rax, 0x48(%rsp)
jmp 0x57a6
movq 0x48(%rsp), %rdi
movq 0x1880e(%rip), %rsi     # 0x1dfc0
callq 0x2260
jmp 0x57b9
movq 0x18810(%rip), %rdi     # 0x1dfd0
leaq 0x1231d(%rip), %rsi     # 0x17ae4
callq 0x2220
movq %rax, 0x40(%rsp)
jmp 0x57d3
movq 0x40(%rsp), %rdi
movq 0x187e1(%rip), %rsi     # 0x1dfc0
callq 0x2260
jmp 0x57e6
movq 0x187e3(%rip), %rdi     # 0x1dfd0
leaq 0x12316(%rip), %rsi     # 0x17b0a
callq 0x2220
movq %rax, 0x38(%rsp)
jmp 0x5800
movq 0x38(%rsp), %rdi
movq 0x187b4(%rip), %rsi     # 0x1dfc0
callq 0x2260
jmp 0x5813
movq 0x187b6(%rip), %rdi     # 0x1dfd0
movq 0x1879f(%rip), %rsi     # 0x1dfc0
callq 0x2260
jmp 0x5828
jmp 0x59b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x2380
jmp 0x59d7
leaq 0x122c3(%rip), %rsi     # 0x17b1a
leaq 0x88(%rsp), %rdi
callq 0x2220
movq %rax, 0x30(%rsp)
jmp 0x586b
movq 0x30(%rsp), %rdi
movq 0x2b0(%rsp), %rax
movl 0x4(%rax), %esi
callq 0x2400
movq %rax, 0x28(%rsp)
jmp 0x5887
movq 0x28(%rsp), %rdi
leaq 0x119b4(%rip), %rsi     # 0x17247
callq 0x2220
movq %rax, 0x20(%rsp)
jmp 0x589f
movq 0x20(%rsp), %rdi
movq 0x2b0(%rsp), %rax
movl 0x8(%rax), %esi
callq 0x2400
movq %rax, 0x18(%rsp)
jmp 0x58bb
movq 0x18(%rsp), %rdi
movq 0x186f9(%rip), %rsi     # 0x1dfc0
callq 0x2260
jmp 0x58ce
movl $0x0, 0x2a8(%rsp)
movl 0x2a8(%rsp), %eax
movq 0x2b0(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x59b1
movl $0x0, 0x2ac(%rsp)
movl 0x2ac(%rsp), %eax
movq 0x2b0(%rsp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x596b
movq 0x290(%rsp), %rax
movslq 0x2a8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x2ac(%rsp), %rcx
movl (%rax,%rcx,4), %esi
leaq 0x88(%rsp), %rdi
callq 0x2400
movq %rax, 0x10(%rsp)
jmp 0x5943
movq 0x10(%rsp), %rdi
leaq 0x118f8(%rip), %rsi     # 0x17247
callq 0x2220
jmp 0x5956
jmp 0x5958
movl 0x2ac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2ac(%rsp)
jmp 0x58fc
leaq 0x12241(%rip), %rsi     # 0x17bb3
leaq 0x88(%rsp), %rdi
callq 0x2220
movq %rax, 0x8(%rsp)
jmp 0x5986
movq 0x8(%rsp), %rdi
movq 0x1862e(%rip), %rsi     # 0x1dfc0
callq 0x2260
jmp 0x5999
jmp 0x599b
movl 0x2a8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2a8(%rsp)
jmp 0x58d9
jmp 0x59b3
leaq 0x88(%rsp), %rdi
callq 0x2360
jmp 0x59c2
leaq 0x88(%rsp), %rdi
callq 0x2380
addq $0x2b8, %rsp            # imm = 0x2B8
retq
movq 0x80(%rsp), %rdi
callq 0x2410
nopw %cs:(%rax,%rax)
nop