// File: /workspace/github_cpp_makefile_star2_O2/akinanop[P]mvl-solver/src/Boolean2Finite.cc
// Function: Boolean2Finite(CommandLine*)
void Boolean2Finite(CommandLine * cline)
{
  //local variables
  ifstream infile;
  ofstream outfile;
  char line_buffer[MAX_LINE];
  char word_buffer[MAX_LINE];
  int line_num = 0;
  int variable = 0;
  set<int> variables;
  vector <vector<int> > data;

  //opening infile to read and checking if it opens
  infile.open(cline->FILE, ios::in);
  if(!infile)
    {
      cout<<endl;
      cout<<"**** ERROR ****"<<endl;
      cout<<"Could not open input file"<<endl;
      cout<<endl;
      exit(1);
    }

  //opening outfile to write and checking if it opens
  outfile.open(cline->MODEL_FILE, ios::out);
  if(!outfile)
    {
      cout<<endl;
      cout<<"**** ERROR ****"<<endl;
      cout<<"Could not open input file"<<endl;
      cout<<endl;
      exit(1);
    }

  //now reading each line from the infile and if needed to convert
  //then converting it and writing to outfile or just writing directly
  while(infile.getline(line_buffer, MAX_LINE))
    {
      ++line_num;
      //if line is comment - just write
      if(line_buffer[0] == 'c')
	{
	  outfile.write(line_buffer, strlen(line_buffer));
	  outfile.put('\n');
	}
      //else if line is p cnf var_num clause_num - just write
      else if(line_buffer[0] == 'p')
	{
	  outfile.write(line_buffer, strlen(line_buffer));
	  outfile.put('\n');
	}
      //else its variables
      else
	{
	  char * lp = line_buffer;
	  vector <int> temp;
	  do
	    {
	      char * wp = word_buffer;
	      //erasing all leading space/tabs
	      while (*lp && ((*lp == ' ') || (*lp == '\t')))
		{
		  lp++;
		}
	      //reading each value into word buffer
	      while (*lp && (*lp != ' ') && (*lp != '\t') && (*lp != '\n'))
		{
		  *(wp++) = *(lp++);
		}
	      *wp = '\0';
	      //converting into int and writing to file
	      if(strlen(word_buffer) != 0)
		{
		  variable = atoi(word_buffer);
		  variables.insert(abs(variable));
		  //checking if variable = 0 i.e end of line
		  if(variable != 0)
		    {
		      //checking for sign
		      if(variable < 0)
			{
			  //variable = -variable;
			  //outfile<<variable<<"=0 ";
			  temp.push_back(variable);
			}
		      else
			{
			  //outfile<<variable<<"=1 ";
			  temp.push_back(variable);
			}
		    }
		  //else print newline in outfile
		  else
		    {
		      //outfile.put('\n');
		    }
		}
	    }while(*lp);
	  data.push_back(temp);
	}
    }

  //now writing back the domain information
  set<int>::iterator start = variables.begin();
  set<int>::iterator end = variables.end();
  end--;
  for( ; start != end; )
    {
      ++start;
      outfile<<"d "<<*start<<" 2"<<endl;
    }

  int ovsize = data.size();
  int uvsize = 0;
  int var = 0;
  for(int y=0; y<ovsize; y++)
    {
      uvsize = data[y].size();
      for(int x=0; x<uvsize; x++)
	{
	  var = data[y][x];
	  if(var < 0 )
	    {
	      var = -var;
	      outfile<<var<<"=0 ";
	    }
	  else
	    {
	      outfile<<var<<"=1 ";
	    }
	}
      outfile<<endl;
    }
  //closing file
  infile.close();
  outfile.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c08, %rsp           # imm = 0x1C08
movq %rdi, %rbx
leaq 0x288(%rsp), %rdi
callq 0x2250
leaq 0x88(%rsp), %rdi
callq 0x2370
andl $0x0, 0x8(%rsp)
leaq 0x60(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq 0x20(%rbx), %rsi
leaq 0x288(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2190
movq 0x288(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x2a8(%rsp,%rax)
jne 0x406f
movq 0x28(%rbx), %rsi
leaq 0x88(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x2060
movq 0x88(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xa8(%rsp,%rax)
jne 0x40bf
leaq 0x288(%rsp), %rbx
leaq 0x1050(%rsp), %r12
movabsq $0x100000601, %r15      # imm = 0x100000601
leaq 0x490(%rsp), %r13
leaq 0x58(%rsp), %rbp
leaq 0xc(%rsp), %r14
movl $0xbb8, %edx            # imm = 0xBB8
movq %rbx, %rdi
movq %r12, %rsi
callq 0x20e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3f00
movzbl 0x1050(%rsp), %eax
cmpl $0x70, %eax
je 0x3e07
cmpl $0x63, %eax
jne 0x3e34
movq %r12, %rdi
callq 0x2110
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x22a0
leaq 0x88(%rsp), %rdi
pushq $0xa
popq %rsi
callq 0x2040
jmp 0x3dd3
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
cmpb $0x9, %al
je 0x3e4e
movzbl %al, %ecx
cmpl $0x20, %ecx
jne 0x3e58
movb 0x1(%r12), %al
incq %r12
jmp 0x3e42
xorl %ebx, %ebx
cmpb $0x20, %al
ja 0x3e67
movzbl %al, %ecx
btq %rcx, %r15
jb 0x3e78
movb %al, 0x490(%rsp,%rbx)
movb 0x1(%r12,%rbx), %al
incq %rbx
jmp 0x3e5a
movb $0x0, 0x490(%rsp,%rbx)
cmpb $0x0, 0x490(%rsp)
je 0x3ec2
movq %r13, %rdi
callq 0x2320
movl %eax, 0x8(%rsp)
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %ecx, 0xc(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x42d4
cmpl $0x0, 0x8(%rsp)
je 0x3ec2
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4170
addq %rbx, %r12
movb (%r12), %al
testb %al, %al
jne 0x3e42
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %r12
movq %r12, %rsi
callq 0x418e
leaq 0x288(%rsp), %rbx
movq %r12, %rdi
callq 0x42a0
leaq 0x1050(%rsp), %r12
jmp 0x3dd3
movq 0x70(%rsp), %rbx
leaq 0x60(%rsp), %rdi
callq 0x2170
movq %rax, %r14
leaq 0x6c08(%rip), %r15      # 0xab21
leaq 0x88(%rsp), %r12
leaq 0x6c32(%rip), %r13      # 0xab5a
cmpq %r14, %rbx
je 0x3f63
movq %rbx, %rdi
callq 0x2260
movq %rax, %rbx
movq %r12, %rdi
movq %r15, %rsi
callq 0x2210
movl 0x20(%rbx), %esi
movq %rax, %rdi
callq 0x2380
movq %rax, %rdi
movq %r13, %rsi
callq 0x2210
movq %rax, %rdi
callq 0x2140
jmp 0x3f28
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movq %rax, 0x30(%rsp)
leaq 0x88(%rsp), %r14
leaq 0x6bcd(%rip), %r12      # 0xab5d
leaq 0x6bca(%rip), %r13      # 0xab61
xorl %ecx, %ecx
cmpq 0x30(%rsp), %rcx
je 0x4015
movq 0x10(%rsp), %rax
movq %rcx, 0x38(%rsp)
imulq $0x18, %rcx, %r15
movq 0x8(%rax,%r15), %rbx
subq (%rax,%r15), %rbx
shrq $0x2, %rbx
testl %ebx, %ebx
movl $0x0, %eax
cmovlel %eax, %ebx
xorl %ebp, %ebp
cmpq %rbp, %rbx
je 0x4003
movq 0x10(%rsp), %rax
movq (%rax,%r15), %rax
movl (%rax,%rbp,4), %esi
testl %esi, %esi
js 0x3fe9
movq %r14, %rdi
callq 0x2380
movq %r13, %rsi
jmp 0x3ff6
negl %esi
movq %r14, %rdi
callq 0x2380
movq %r12, %rsi
movq %rax, %rdi
callq 0x2210
incq %rbp
jmp 0x3fc7
movq %r14, %rdi
callq 0x2140
movq 0x38(%rsp), %rcx
incq %rcx
jmp 0x3f99
leaq 0x288(%rsp), %rdi
callq 0x2090
leaq 0x88(%rsp), %rdi
callq 0x22e0
leaq 0x10(%rsp), %rdi
callq 0x41ba
leaq 0x58(%rsp), %rdi
callq 0x41e6
leaq 0x88(%rsp), %rdi
callq 0x2300
leaq 0x288(%rsp), %rdi
callq 0x20a0
addq $0x1c08, %rsp           # imm = 0x1C08
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xaf5a(%rip), %rdi      # 0xefd0
callq 0x2140
movq 0xaf4e(%rip), %rdi      # 0xefd0
leaq 0x6a4b(%rip), %rsi      # 0xaad4
callq 0x2210
movq %rax, %rdi
callq 0x2140
movq 0xaf33(%rip), %rdi      # 0xefd0
leaq 0x6a9c(%rip), %rsi      # 0xab40
callq 0x2210
movq %rax, %rdi
callq 0x2140
movq 0xaf18(%rip), %rdi      # 0xefd0
callq 0x2140
jmp 0x410d
movq 0xaf0a(%rip), %rdi      # 0xefd0
callq 0x2140
movq 0xaefe(%rip), %rdi      # 0xefd0
leaq 0x69fb(%rip), %rsi      # 0xaad4
callq 0x2210
movq %rax, %rdi
callq 0x2140
movq 0xaee3(%rip), %rdi      # 0xefd0
leaq 0x6a4c(%rip), %rsi      # 0xab40
callq 0x2210
movq %rax, %rdi
callq 0x2140
movq 0xaec8(%rip), %rdi      # 0xefd0
callq 0x2140
pushq $0x1
popq %rdi
callq 0x2280
movq %rax, %rbx
jmp 0x415b
jmp 0x4137
jmp 0x4137
jmp 0x4128
jmp 0x4137
jmp 0x4137
jmp 0x4137
jmp 0x4128
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x42a0
jmp 0x413a
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x41ba
leaq 0x58(%rsp), %rdi
callq 0x41e6
leaq 0x88(%rsp), %rdi
callq 0x2300
leaq 0x288(%rsp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x2390