// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdi, %rbx
xorl %edi, %edi
callq 0x21e0
movl %eax, %edi
callq 0x21f0
movslq 0x4(%rbx), %rax
movq $-0x1, %r14
cmpq %r14, %rax
leaq 0x4(,%rax,4), %rdi
cmovlq %r14, %rdi
callq 0x2030
movq %rax, 0x8(%rsp)
movslq 0x8(%rbx), %r13
leaq (,%r13,8), %rdi
testq %r13, %r13
cmovsq %r14, %rdi
callq 0x2030
movq %rax, %r15
testq %r13, %r13
jle 0x49af
movslq 0xc(%rbx), %rax
leaq (,%rax,4), %r12
testq %rax, %rax
cmovsq %r14, %r12
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x2030
movq %rax, (%r15,%r14,8)
incq %r14
cmpq %r14, %r13
jne 0x499b
cmpl $0x0, 0x4(%rbx)
movq 0x8(%rsp), %r12
jle 0x49e8
movl $0x1, %r14d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
callq 0x20b0
testb $0x1, %al
movl %r14d, %eax
cmovel %ebp, %eax
movl %eax, (%r12,%r14,4)
leaq 0x1(%r14), %rax
movslq 0x4(%rbx), %rcx
decl %ebp
cmpq %rcx, %r14
movq %rax, %r14
jl 0x49c5
cmpl $0x0, 0x8(%rbx)
movq %r15, 0x10(%rsp)
jle 0x4ae8
movq $0x0, (%rsp)
cmpl $0x0, 0xc(%rbx)
jle 0x4ad0
xorl %r13d, %r13d
movb 0x10(%rbx), %r14b
callq 0x20b0
movl %eax, %ebp
callq 0x20b0
cltd
idivl 0x4(%rbx)
testq %r13, %r13
jne 0x4a40
testb %r14b, %r14b
je 0x4a40
movslq %edx, %rcx
testb $0x1, %bpl
jne 0x4aa8
xorl %eax, %eax
movq 0x8(%rsp), %rdx
subl 0x4(%rdx,%rcx,4), %eax
jmp 0x4ab1
leal 0x1(%rdx), %eax
testb $0x1, %bpl
notl %edx
cmovnel %eax, %edx
movq (%rsp), %rax
movq (%r15,%rax,8), %rax
movl %edx, (%rax,%r13,4)
testq %r13, %r13
je 0x4abb
movq 0x10(%rsp), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rbp
movl $0x1, %r12d
movl (%rbp,%r13,4), %r15d
movl -0x4(%rbp,%r12,4), %r14d
cmpl %r14d, %r15d
jne 0x4a8f
callq 0x20b0
cltd
idivl 0x4(%rbx)
incl %edx
movl %edx, (%rbp,%r13,4)
cmpq %r13, %r12
jae 0x4a9c
incq %r12
cmpl %r14d, %r15d
jne 0x4a70
testq %r13, %r13
je 0x4abb
cmpl %r14d, %r15d
je 0x4a6a
jmp 0x4abb
movq 0x8(%rsp), %rax
movl 0x4(%rax,%rcx,4), %eax
movq (%rsp), %rcx
movq (%r15,%rcx,8), %rcx
movl %eax, (%rcx)
incq %r13
movslq 0xc(%rbx), %rax
cmpq %rax, %r13
movq 0x10(%rsp), %r15
jl 0x4a0c
movq (%rsp), %rdx
incq %rdx
movslq 0x8(%rbx), %rax
movq %rdx, (%rsp)
cmpq %rax, %rdx
jl 0x49ff
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x2380
movq 0x20(%rbx), %rsi
movq %r15, %rdi
movl $0x10, %edx
callq 0x2060
movq 0x18(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x38(%rsp,%rax)
je 0x4c4e
movq 0xb4af(%rip), %rdi      # 0xffd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq 0xb494(%rip), %rdi      # 0xffd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xb480(%rip), %rbx      # 0xffd0
leaq 0x7f7d(%rip), %rsi      # 0xcad4
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2270
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq 0xb44e(%rip), %rdi      # 0xffd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xb43a(%rip), %rbx      # 0xffd0
leaq 0x7f47(%rip), %rsi      # 0xcae4
movl $0x25, %edx
movq %rbx, %rdi
callq 0x2270
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq 0xb408(%rip), %rdi      # 0xffd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xb3f4(%rip), %rbx      # 0xffd0
leaq 0x7f27(%rip), %rsi      # 0xcb0a
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2270
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq 0xb3c2(%rip), %rbx      # 0xffd0
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq 0xb394(%rip), %rdi      # 0xffd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
jmp 0x4d5b
leaq 0x7ec5(%rip), %rsi      # 0xcb1a
leaq 0x18(%rsp), %rdi
movl $0x6, %edx
callq 0x2270
movl 0x4(%rbx), %esi
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x2390
movq %rax, %r12
leaq 0x75c9(%rip), %rsi      # 0xc247
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movl 0x8(%rbx), %esi
movq %r12, %rdi
callq 0x2390
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
cmpl $0x0, 0x8(%rbx)
jle 0x4d5b
xorl %ebp, %ebp
leaq 0x7574(%rip), %r12      # 0xc247
cmpl $0x0, 0xc(%rbx)
jle 0x4d0e
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %r13
xorl %r15d, %r15d
movl (%r13,%r15,4), %esi
movq %r14, %rdi
callq 0x2390
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2270
incq %r15
movslq 0xc(%rbx), %rax
cmpq %rax, %r15
jl 0x4ce5
movl $0x1, %edx
movq %r14, %rdi
leaq 0x7f03(%rip), %rsi      # 0xcc20
callq 0x2270
movq 0x18(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
incq %rbp
movslq 0x8(%rbx), %rax
cmpq %rax, %rbp
jl 0x4cd3
leaq 0x18(%rsp), %rdi
callq 0x22f0
movq 0xb25c(%rip), %rax      # 0xffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x20(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x18(%rsp,%rcx)
callq 0x21c0
leaq 0x110(%rsp), %rdi
callq 0x20e0
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4dad
jmp 0x4dad
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2310
movq %rbx, %rdi
callq 0x23a0
nop