// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
xorl %edi, %edi
callq 0x21e0
movl %eax, %edi
callq 0x21f0
movslq 0x4(%rbx), %r15
movl $0xc, %ecx
movq %r15, %rax
mulq %rcx
movq $-0x1, %r14
cmovoq %r14, %rax
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x2030
testq %r15, %r15
je 0x42cd
leaq (%r15,%r15,2), %rcx
leaq (%rax,%rcx,4), %rcx
movq %rax, %rdx
movq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
addq $0xc, %rdx
cmpq %rcx, %rdx
jne 0x42b9
movq %r15, 0x10(%rsp)
movq %rax, 0xcf37(%rip)      # 0x11210
movslq 0x8(%rbx), %rbp
leaq (,%rbp,8), %rdi
testq %rbp, %rbp
cmovsq %r14, %rdi
callq 0x2030
movq %rax, 0xcf20(%rip)      # 0x11218
testq %rbp, %rbp
jle 0x4359
movslq 0xc(%rbx), %r12
movl $0xc, %ecx
movq %r12, %rax
mulq %rcx
movq $-0x1, %r13
cmovnoq %rax, %r13
xorl %r15d, %r15d
leaq (%r12,%r12,2), %r14
movq %r13, %rdi
callq 0x2030
testl %r12d, %r12d
je 0x4346
leaq (%rax,%r14,4), %rcx
movq %rax, %rdx
movq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
addq $0xc, %rdx
cmpq %rcx, %rdx
jne 0x4332
movq 0xcecb(%rip), %rcx      # 0x11218
movq %rax, (%rcx,%r15,8)
incq %r15
cmpq %rbp, %r15
jne 0x431e
movq 0x8(%rsp), %rdi
callq 0x2030
movq 0x10(%rsp), %rsi
testl %esi, %esi
je 0x43d5
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,4), %rcx
movq %rax, %rdx
movq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
addq $0xc, %rdx
cmpq %rcx, %rdx
jne 0x4377
movq %rax, 0xce8e(%rip)      # 0x11220
cmpb $0x0, 0x18(%rbx)
je 0x43de
testl %esi, %esi
jle 0x443b
xorl %r14d, %r14d
xorl %r15d, %r15d
movl %r15d, (%rax,%r14)
callq 0x20b0
cltd
idivl 0x14(%rbx)
movq 0xce66(%rip), %rax      # 0x11220
movl %edx, 0x4(%rax,%r14)
incq %r15
movslq 0x4(%rbx), %rcx
addq $0xc, %r14
cmpq %rcx, %r15
jl 0x43a6
testl %ecx, %ecx
jg 0x43fc
jmp 0x443b
movq %rax, 0xce44(%rip)      # 0x11220
jmp 0x443b
testl %esi, %esi
jle 0x443b
movl 0x14(%rbx), %ecx
addq $0x4, %rax
xorl %edx, %edx
movl %edx, -0x4(%rax)
movl %ecx, (%rax)
incq %rdx
addq $0xc, %rax
cmpq %rdx, %rsi
jne 0x43eb
movq 0xce0d(%rip), %rax      # 0x11210
xorl %r14d, %r14d
xorl %r15d, %r15d
movl %r15d, (%rax,%r14)
callq 0x20b0
movq 0xce07(%rip), %rcx      # 0x11220
cltd
idivl 0x4(%rcx,%r14)
movq 0xcdea(%rip), %rax      # 0x11210
movl %edx, 0x4(%rax,%r14)
incq %r15
movslq 0x4(%rbx), %rcx
addq $0xc, %r14
cmpq %rcx, %r15
jl 0x4409
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
jle 0x453f
movl 0xc(%rbx), %eax
xorl %r14d, %r14d
testl %eax, %eax
jle 0x4530
xorl %r15d, %r15d
testq %r15, %r15
jne 0x449b
cmpb $0x0, 0x10(%rbx)
je 0x449b
movq 0xcda7(%rip), %r12      # 0x11210
callq 0x20b0
cltd
idivl 0x4(%rbx)
movslq %edx, %rax
leaq (%rax,%rax,2), %rax
movslq (%r12,%rax,4), %rax
movq 0xcd94(%rip), %rcx      # 0x11218
movq (%rcx,%r14,8), %rcx
movl %eax, (%rcx)
movq 0xcd7f(%rip), %rdx      # 0x11210
leaq (%rax,%rax,2), %rax
movl 0x4(%rdx,%rax,4), %edx
jmp 0x451a
callq 0x20b0
cltd
idivl 0x4(%rbx)
movq 0xcd6d(%rip), %rax      # 0x11218
movq (%rax,%r14,8), %rax
leaq (%r15,%r15,2), %r12
movl %edx, (%rax,%r12,4)
testq %r15, %r15
je 0x44f3
movl $0x1, %ecx
movl (%rax), %esi
cmpl %esi, %edx
je 0x44d9
cmpq %rcx, %r15
jbe 0x44f3
incq %rcx
addq $0xc, %rax
cmpl %esi, %edx
jne 0x44c1
jmp 0x44f3
callq 0x20b0
cltd
idivl 0x4(%rbx)
movq 0xcd2f(%rip), %rax      # 0x11218
movq (%rax,%r14,8), %rax
movl %edx, (%rax,%r12,4)
jmp 0x44bc
callq 0x20b0
movq 0xcd21(%rip), %rsi      # 0x11220
movq 0xcd12(%rip), %rcx      # 0x11218
movq (%rcx,%r14,8), %rcx
leaq (%rcx,%r12,4), %rcx
movslq (%rcx), %rdx
leaq (%rdx,%rdx,2), %rdi
cltd
idivl 0x4(%rsi,%rdi,4)
movl %edx, 0x4(%rcx)
incq %r15
movslq 0xc(%rbx), %rax
cmpq %rax, %r15
jl 0x4457
movl 0x8(%rbx), %ecx
incq %r14
movslq %ecx, %rdx
cmpq %rdx, %r14
jl 0x444c
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x2380
movq 0x20(%rbx), %rsi
movq %r14, %rdi
movl $0x10, %edx
callq 0x2060
movq 0x18(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x38(%rsp,%rax)
je 0x46a5
movq 0xca58(%rip), %rdi      # 0x10fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq 0xca3d(%rip), %rdi      # 0x10fd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xca29(%rip), %rbx      # 0x10fd0
leaq 0x9526(%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 0xc9f7(%rip), %rdi      # 0x10fd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xc9e3(%rip), %rbx      # 0x10fd0
leaq 0x94f0(%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 0xc9b1(%rip), %rdi      # 0x10fd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0xc99d(%rip), %rbx      # 0x10fd0
leaq 0x94d0(%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 0xc96b(%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 0xc93d(%rip), %rdi      # 0x10fd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
jmp 0x489e
leaq 0x946e(%rip), %rsi      # 0xdb1a
leaq 0x18(%rsp), %rdi
movl $0x6, %edx
callq 0x2270
movl 0x4(%rbx), %esi
leaq 0x18(%rsp), %rdi
callq 0x2390
movq %rax, %r15
leaq 0x8b75(%rip), %rsi      # 0xd247
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 0x47be
xorl %r15d, %r15d
leaq 0x93f9(%rip), %r14      # 0xdb21
leaq 0x18(%rsp), %r12
xorl %r13d, %r13d
movl $0x2, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x2270
movq 0xcad9(%rip), %rax      # 0x11220
movl (%rax,%r15), %esi
incl %esi
movq %r12, %rdi
callq 0x2390
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0x8ae0(%rip), %rsi      # 0xd247
callq 0x2270
movq 0xcaad(%rip), %rax      # 0x11220
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
movslq 0x4(%rbx), %rax
addq $0xc, %r15
cmpq %rax, %r13
jl 0x4730
cmpl $0x0, 0x8(%rbx)
jle 0x489e
xorl %r13d, %r13d
leaq 0x8a75(%rip), %r12      # 0xd247
cmpl $0x0, 0xc(%rbx)
jle 0x4848
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0xca33(%rip), %rax      # 0x11218
movq (%rax,%r13,8), %rax
movl (%rax,%r14), %esi
incl %esi
leaq 0x18(%rsp), %rdi
callq 0x2390
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0x9476(%rip), %rsi      # 0xdc81
callq 0x2270
movq 0xca01(%rip), %rax      # 0x11218
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
movslq 0xc(%rbx), %rax
addq $0xc, %r14
cmpq %rax, %r15
jl 0x47de
movl $0x1, %edx
leaq 0x18(%rsp), %rdi
leaq 0x93c7(%rip), %rsi      # 0xdc20
callq 0x2270
movq 0x18(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0x18(%rsp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq 0x18(%rsp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
incq %r13
movslq 0x8(%rbx), %rax
cmpq %rax, %r13
jl 0x47d2
leaq 0x18(%rsp), %rdi
callq 0x22f0
movq 0xc719(%rip), %rax      # 0x10fc8
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 0x48f2
jmp 0x48f2
jmp 0x48f2
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2310
movq %rbx, %rdi
callq 0x23a0