// File: /workspace/github_cpp_makefile_star2_O1/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 $0x218, %rsp            # imm = 0x218
movq %rdi, %r15
xorl %edi, %edi
callq 0x21e0
movl %eax, %edi
callq 0x21f0
movslq 0x4(%r15), %r14
movl $0xc, %ecx
movq %r14, %rax
mulq %rcx
movq $-0x1, %rbx
cmovoq %rbx, %rax
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x2030
testq %r14, %r14
je 0x4291
leaq (%r14,%r14,2), %rcx
leaq (%rax,%rcx,4), %rcx
movq %rax, %rdx
movq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
addq $0xc, %rdx
cmpq %rcx, %rdx
jne 0x427d
movq %rax, 0xbf78(%rip)      # 0x10210
movq %r15, 0x8(%rsp)
movslq 0x8(%r15), %rbp
leaq (,%rbp,8), %rdi
testq %rbp, %rbp
cmovsq %rbx, %rdi
callq 0x2030
movq %rax, 0xbf5c(%rip)      # 0x10218
testq %rbp, %rbp
jle 0x4322
movq 0x8(%rsp), %rax
movslq 0xc(%rax), %r12
movl $0xc, %ecx
movq %r12, %rax
mulq %rcx
movq $-0x1, %r13
cmovnoq %rax, %r13
xorl %r15d, %r15d
leaq (%r12,%r12,2), %rbx
movq %r13, %rdi
callq 0x2030
testl %r12d, %r12d
je 0x430f
leaq (%rax,%rbx,4), %rcx
movq %rax, %rdx
movq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
addq $0xc, %rdx
cmpq %rcx, %rdx
jne 0x42fb
movq 0xbf02(%rip), %rcx      # 0x10218
movq %rax, (%rcx,%r15,8)
incq %r15
cmpq %rbp, %r15
jne 0x42e7
movq 0x10(%rsp), %rdi
callq 0x2030
testl %r14d, %r14d
je 0x4350
leaq (%r14,%r14,2), %rcx
leaq (%rax,%rcx,4), %rcx
movq %rax, %rdx
movq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
addq $0xc, %rdx
cmpq %rcx, %rdx
jne 0x433c
movq %rax, 0xbec9(%rip)      # 0x10220
movq 0x8(%rsp), %r12
cmpb $0x0, 0x18(%r12)
je 0x43a5
cmpl $0x0, 0x4(%r12)
jle 0x43c6
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0xbea8(%rip), %rax      # 0x10220
movl %r14d, (%rax,%rbx)
callq 0x20b0
cltd
idivl 0x14(%r12)
movq 0xbe92(%rip), %rax      # 0x10220
movl %edx, 0x4(%rax,%rbx)
incq %r14
movslq 0x4(%r12), %rax
addq $0xc, %rbx
cmpq %rax, %r14
jl 0x4371
jmp 0x43c6
testl %r14d, %r14d
jle 0x43c6
movl 0x14(%r12), %ecx
addq $0x4, %rax
xorl %edx, %edx
movl %edx, -0x4(%rax)
movl %ecx, (%rax)
incq %rdx
addq $0xc, %rax
cmpq %rdx, %r14
jne 0x43b5
cmpl $0x0, 0x4(%r12)
jle 0x440b
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0xbe36(%rip), %rax      # 0x10210
movl %r14d, (%rax,%rbx)
callq 0x20b0
movq 0xbe36(%rip), %rcx      # 0x10220
cltd
idivl 0x4(%rcx,%rbx)
movq 0xbe1a(%rip), %rax      # 0x10210
movl %edx, 0x4(%rax,%rbx)
incq %r14
movslq 0x4(%r12), %rax
addq $0xc, %rbx
cmpq %rax, %r14
jl 0x43d3
cmpl $0x0, 0x8(%r12)
jle 0x4540
xorl %r14d, %r14d
cmpl $0x0, 0xc(%r12)
jle 0x452f
xorl %r15d, %r15d
testq %r15, %r15
jne 0x4474
cmpb $0x0, 0x10(%r12)
je 0x4474
movq 0xbdd3(%rip), %rbx      # 0x10210
callq 0x20b0
cltd
idivl 0x4(%r12)
movslq %edx, %rax
leaq (%rax,%rax,2), %rax
movslq (%rbx,%rax,4), %rax
movq 0xbdbe(%rip), %rcx      # 0x10218
movq (%rcx,%r14,8), %rcx
movl %eax, (%rcx)
movq 0xbda9(%rip), %rdx      # 0x10210
leaq (%rax,%rax,2), %rax
movl 0x4(%rdx,%rax,4), %edx
jmp 0x451b
callq 0x20b0
cltd
idivl 0x4(%r12)
movq 0xbd92(%rip), %rax      # 0x10218
movq (%rax,%r14,8), %rax
leaq (%r15,%r15,2), %r12
movl %edx, (%rax,%r12,4)
testq %r15, %r15
je 0x44ef
xorl %r13d, %r13d
movq 0xbd77(%rip), %rax      # 0x10218
movq (%rax,%r14,8), %rax
movl (%rax,%r12,4), %ebp
movl %r13d, %ecx
leaq (%rcx,%rcx,2), %rcx
movl (%rax,%rcx,4), %ebx
cmpl %ebx, %ebp
jne 0x44d4
callq 0x20b0
cltd
movq 0x8(%rsp), %rcx
idivl 0x4(%rcx)
movq 0xbd4c(%rip), %rax      # 0x10218
movq (%rax,%r14,8), %rax
movl %edx, (%rax,%r12,4)
incl %r13d
cmpq %r13, %r15
jbe 0x44e0
cmpl %ebx, %ebp
jne 0x449a
testq %r15, %r15
je 0x44ef
movl $0x0, %r13d
cmpl %ebx, %ebp
je 0x449a
callq 0x20b0
movq 0xbd25(%rip), %rsi      # 0x10220
movq 0xbd16(%rip), %rcx      # 0x10218
movq (%rcx,%r14,8), %rcx
leaq (%rcx,%r12,4), %rcx
movslq (%rcx), %rdx
leaq (%rdx,%rdx,2), %rdi
cltd
idivl 0x4(%rsi,%rdi,4)
movq 0x8(%rsp), %r12
movl %edx, 0x4(%rcx)
incq %r15
movslq 0xc(%r12), %rax
cmpq %rax, %r15
jl 0x4429
incq %r14
movslq 0x8(%r12), %rax
cmpq %rax, %r14
jl 0x441a
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x2380
movq 0x20(%r12), %rsi
movq %r14, %rdi
movl $0x10, %edx
callq 0x2060
movq 0x18(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x38(%rsp,%rax)
je 0x46a7
movq 0xba56(%rip), %rdi      # 0xffd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq 0xba3b(%rip), %rdi      # 0xffd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xba27(%rip), %rbx      # 0xffd0
leaq 0x8524(%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 0xb9f5(%rip), %rdi      # 0xffd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xb9e1(%rip), %rbx      # 0xffd0
leaq 0x84ee(%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 0xb9af(%rip), %rdi      # 0xffd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xb99b(%rip), %rbx      # 0xffd0
leaq 0x84ce(%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 0xb969(%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 0xb93b(%rip), %rdi      # 0xffd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
jmp 0x48b6
leaq 0x846c(%rip), %rsi      # 0xcb1a
leaq 0x18(%rsp), %rdi
movl $0x6, %edx
callq 0x2270
movq 0x8(%rsp), %rbx
movl 0x4(%rbx), %esi
leaq 0x18(%rsp), %rdi
callq 0x2390
movq %rax, %r15
leaq 0x7b6e(%rip), %rsi      # 0xc247
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movl 0x8(%rbx), %esi
movq %r15, %rdi
callq 0x2390
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
cmpl $0x0, 0x4(%rbx)
jle 0x47cd
xorl %r15d, %r15d
leaq 0x83f2(%rip), %rbx      # 0xcb21
leaq 0x18(%rsp), %r12
leaq 0x7b0c(%rip), %r14      # 0xc247
xorl %r13d, %r13d
movl $0x2, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2270
movq 0xbacb(%rip), %rax      # 0x10220
movl (%rax,%r15), %esi
incl %esi
movq %r12, %rdi
callq 0x2390
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2270
movq 0xbaa3(%rip), %rax      # 0x10220
movl 0x4(%rax,%r15), %esi
movq %rbp, %rdi
callq 0x2390
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
incq %r13
movq 0x8(%rsp), %rax
movslq 0x4(%rax), %rax
addq $0xc, %r15
cmpq %rax, %r13
jl 0x473e
movq 0x8(%rsp), %rcx
cmpl $0x0, 0x8(%rcx)
jle 0x48b6
xorl %r13d, %r13d
leaq 0x7a61(%rip), %r12      # 0xc247
cmpl $0x0, 0xc(%rcx)
leaq 0x18(%rsp), %rbx
jle 0x4864
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0xba1a(%rip), %rax      # 0x10218
movq (%rax,%r13,8), %rax
movl (%rax,%r14), %esi
incl %esi
movq %rbx, %rdi
callq 0x2390
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0x845f(%rip), %rsi      # 0xcc81
callq 0x2270
movq 0xb9ea(%rip), %rax      # 0x10218
movq (%rax,%r13,8), %rax
movl 0x4(%rax,%r14), %esi
movq %rbp, %rdi
callq 0x2390
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2270
incq %r15
movq 0x8(%rsp), %rax
movslq 0xc(%rax), %rax
addq $0xc, %r14
cmpq %rax, %r15
jl 0x47f7
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x83ad(%rip), %rsi      # 0xcc20
callq 0x2270
movq 0x18(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
incq %r13
movq 0x8(%rsp), %rcx
movslq 0x8(%rcx), %rax
cmpq %rax, %r13
jl 0x47e6
leaq 0x18(%rsp), %rdi
callq 0x22f0
movq 0xb701(%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 0x490a
jmp 0x490a
jmp 0x490a
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2310
movq %rbx, %rdi
callq 0x23a0