// File: /workspace/github_cpp_makefile_star2_O3/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 $0x208, %rsp            # imm = 0x208
movq %rdi, %rbx
xorl %edi, %edi
callq 0x21e0
movl %eax, %edi
callq 0x21f0
movslq 0x4(%rbx), %rbp
movq $-0x1, %r15
cmpq %r15, %rbp
leaq 0x4(,%rbp,4), %rdi
cmovlq %r15, %rdi
callq 0x2030
movq %rax, (%rsp)
movslq 0x8(%rbx), %r13
leaq (,%r13,8), %rdi
testq %r13, %r13
cmovsq %r15, %rdi
callq 0x2030
movq %rax, %r14
testq %r13, %r13
jle 0x4996
movslq 0xc(%rbx), %rax
leaq (,%rax,4), %r12
testq %rax, %rax
cmovsq %r15, %r12
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x2030
movq %rax, (%r14,%r15,8)
incq %r15
cmpq %r15, %r13
jne 0x4982
testl %ebp, %ebp
jle 0x49d1
movl $0x1, %r12d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq (%rsp), %r15
callq 0x20b0
testb $0x1, %al
movl %r12d, %eax
cmovel %ebp, %eax
movl %eax, (%r15,%r12,4)
leaq 0x1(%r12), %rax
movslq 0x4(%rbx), %rcx
decl %ebp
cmpq %rcx, %r12
movq %rax, %r12
jl 0x49a9
movl 0x8(%rbx), %r13d
testl %r13d, %r13d
jle 0x4a91
movl 0xc(%rbx), %eax
xorl %r12d, %r12d
testl %eax, %eax
jle 0x4a82
xorl %r13d, %r13d
movb 0x10(%rbx), %r15b
callq 0x20b0
movl %eax, %ebp
callq 0x20b0
cltd
idivl 0x4(%rbx)
testq %r13, %r13
jne 0x4a27
testb %r15b, %r15b
je 0x4a27
movslq %edx, %rax
movq (%rsp), %rcx
movl 0x4(%rcx,%rax,4), %eax
movl %eax, %ecx
negl %ecx
testb $0x1, %bpl
cmovnel %eax, %ecx
movq (%r14,%r12,8), %rax
movl %ecx, (%rax)
jmp 0x4a6e
leal 0x1(%rdx), %eax
testb $0x1, %bpl
movq (%r14,%r12,8), %rbp
notl %edx
cmovnel %eax, %edx
movl %edx, (%rbp,%r13,4)
testq %r13, %r13
je 0x4a6e
movl $0x1, %eax
movl -0x4(%rbp,%rax,4), %ecx
cmpl %ecx, %edx
je 0x4a5c
cmpq %r13, %rax
jae 0x4a6e
incq %rax
cmpl %ecx, %edx
jne 0x4a46
jmp 0x4a6e
callq 0x20b0
cltd
idivl 0x4(%rbx)
incl %edx
movl %edx, (%rbp,%r13,4)
jmp 0x4a41
incq %r13
movslq 0xc(%rbx), %rax
cmpq %rax, %r13
jl 0x49eb
movl 0x8(%rbx), %r13d
incq %r12
movslq %r13d, %rcx
cmpq %rcx, %r12
jl 0x49e0
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x2380
movq 0x20(%rbx), %rsi
movq %r15, %rdi
movl $0x10, %edx
callq 0x2060
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x28(%rsp,%rax)
je 0x4bf7
movq 0xc506(%rip), %rdi      # 0x10fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq 0xc4eb(%rip), %rdi      # 0x10fd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xc4d7(%rip), %rbx      # 0x10fd0
leaq 0x8fd4(%rip), %rsi      # 0xdad4
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 0xc4a5(%rip), %rdi      # 0x10fd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xc491(%rip), %rbx      # 0x10fd0
leaq 0x8f9e(%rip), %rsi      # 0xdae4
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 0xc45f(%rip), %rdi      # 0x10fd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xc44b(%rip), %rbx      # 0x10fd0
leaq 0x8f7e(%rip), %rsi      # 0xdb0a
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 0xc419(%rip), %rbx      # 0x10fd0
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 0xc3eb(%rip), %rdi      # 0x10fd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
jmp 0x4d07
leaq 0x8f1c(%rip), %rsi      # 0xdb1a
leaq 0x8(%rsp), %rdi
movl $0x6, %edx
callq 0x2270
movl 0x4(%rbx), %esi
leaq 0x8(%rsp), %rdi
callq 0x2390
movq %rax, %r12
leaq 0x8623(%rip), %rsi      # 0xd247
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 0x4d07
xorl %ebp, %ebp
leaq 0x85ce(%rip), %r12      # 0xd247
cmpl $0x0, 0xc(%rbx)
jle 0x4cb1
movq (%r14,%rbp,8), %r13
xorl %r15d, %r15d
movl (%r13,%r15,4), %esi
leaq 0x8(%rsp), %rdi
callq 0x2390
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2270
incq %r15
movslq 0xc(%rbx), %rax
cmpq %rax, %r15
jl 0x4c86
movl $0x1, %edx
leaq 0x8(%rsp), %rdi
leaq 0x8f5e(%rip), %rsi      # 0xdc20
callq 0x2270
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0x8(%rsp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq 0x8(%rsp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
incq %rbp
movslq 0x8(%rbx), %rax
cmpq %rax, %rbp
jl 0x4c79
leaq 0x8(%rsp), %rdi
callq 0x22f0
movq 0xc2b0(%rip), %rax      # 0x10fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x10(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x8(%rsp,%rcx)
callq 0x21c0
leaq 0x100(%rsp), %rdi
callq 0x20e0
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4d59
jmp 0x4d59
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2310
movq %rbx, %rdi
callq 0x23a0
nop