// File: /workspace/github_cpp_makefile_star2_O1/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 0x2260
leaq 0x88(%rsp), %rdi
callq 0x2380
xorl %eax, %eax
movl %eax, 0xc(%rsp)
leaq 0x60(%rsp), %rcx
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq %rax, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x20(%rbx), %rsi
leaq 0x288(%rsp), %r15
movq %r15, %rdi
movl $0x8, %edx
callq 0x2170
movq 0x288(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x2a8(%rsp,%rax)
jne 0x5218
movq 0x28(%rbx), %rsi
leaq 0x88(%rsp), %rdi
movl $0x10, %edx
callq 0x2060
movq 0x88(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xa8(%rsp,%rax)
jne 0x527a
movabsq $0x100000601, %r14      # imm = 0x100000601
leaq 0x490(%rsp), %rbx
leaq 0x58(%rsp), %r13
leaq 0x1c(%rsp), %r12
movq 0x288(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %ecx
movl $0xbb8, %edx            # imm = 0xBB8
movq %r15, %rdi
leaq 0x1050(%rsp), %rsi
callq 0x23c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x501d
movzbl 0x1050(%rsp), %eax
cmpl $0x70, %eax
je 0x4ef0
cmpl $0x63, %eax
jne 0x4f2a
leaq 0x1050(%rsp), %rbp
movq %rbp, %rdi
callq 0x2110
leaq 0x88(%rsp), %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x22b0
leaq 0x88(%rsp), %rdi
movl $0xa, %esi
callq 0x2040
jmp 0x4e9b
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
leaq 0x1050(%rsp), %r15
movzbl (%r15), %eax
cmpl $0x9, %eax
je 0x4f51
cmpl $0x20, %eax
jne 0x4f56
incq %r15
jmp 0x4f43
xorl %ebp, %ebp
movzbl (%r15,%rbp), %eax
cmpq $0x20, %rax
ja 0x4f69
btq %rax, %r14
jb 0x4f75
movb %al, 0x490(%rsp,%rbp)
incq %rbp
jmp 0x4f58
movb $0x0, 0x490(%rsp,%rbp)
cmpb $0x0, 0x490(%rsp)
je 0x4fd9
movq %rbx, %rdi
callq 0x2330
movl %eax, 0xc(%rsp)
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %ecx, 0x1c(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x5420
movl 0xc(%rsp), %eax
testl %eax, %eax
je 0x4fd9
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x4fca
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x4fd9
leaq 0x20(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x5530
addq %rbp, %r15
cmpb $0x0, (%r15)
jne 0x4f43
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x534c
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
leaq 0x288(%rsp), %r15
je 0x4e9b
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
jmp 0x4e9b
movq 0x70(%rsp), %r14
leaq 0x60(%rsp), %rdi
callq 0x2150
movq %rax, %r15
leaq 0x7aeb(%rip), %r12      # 0xcb21
leaq 0x88(%rsp), %rbx
leaq 0x7b15(%rip), %r13      # 0xcb5a
cmpq %r15, %r14
je 0x50ae
movq %r14, %rdi
callq 0x2280
movq %rax, %r14
movl $0x2, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2270
movl 0x20(%r14), %esi
movq %rbx, %rdi
callq 0x2390
movq %rax, %rbp
movl $0x2, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2270
movq (%rbp), %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
jmp 0x5045
movq 0x48(%rsp), %rax
subq 0x40(%rsp), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rcx
movq %rcx, 0x10(%rsp)
testl %ecx, %ecx
jle 0x5193
movq 0x10(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
leaq 0x7a71(%rip), %r13      # 0xcb61
movq 0x40(%rsp), %rax
leaq (%r15,%r15,2), %rbp
movq 0x8(%rax,%rbp,8), %r14
subq (%rax,%rbp,8), %r14
shrq $0x2, %r14
testl %r14d, %r14d
jle 0x5159
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorl %r12d, %r12d
movq 0x40(%rsp), %rax
movq (%rax,%rbp,8), %rax
movl (%rax,%r12,4), %esi
testl %esi, %esi
js 0x5133
movq %rbx, %rdi
callq 0x2390
movq %r13, %rsi
jmp 0x5144
negl %esi
movq %rbx, %rdi
callq 0x2390
leaq 0x7a19(%rip), %rsi      # 0xcb5d
movl $0x3, %edx
movq %rax, %rdi
callq 0x2270
incq %r12
cmpq %r12, %r14
jne 0x5115
movq 0x88(%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 %r15
cmpq 0x10(%rsp), %r15
jne 0x50f0
leaq 0x288(%rsp), %rdi
callq 0x2090
leaq 0x88(%rsp), %rdi
callq 0x22f0
leaq 0x40(%rsp), %rdi
callq 0x5378
leaq 0x58(%rsp), %rdi
callq 0x53d0
movq 0xae00(%rip), %rax      # 0xffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x90(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x88(%rsp,%rcx)
callq 0x21c0
leaq 0x180(%rsp), %rdi
callq 0x20e0
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 0xadb1(%rip), %rdi      # 0xffd0
callq 0x2120
movq 0xada5(%rip), %rdi      # 0xffd0
leaq 0x78a2(%rip), %rsi      # 0xcad4
movl $0xf, %edx
callq 0x2270
movq 0xad8d(%rip), %rdi      # 0xffd0
callq 0x2120
movq 0xad81(%rip), %rdi      # 0xffd0
leaq 0x78ea(%rip), %rsi      # 0xcb40
movl $0x19, %edx
callq 0x2270
movq 0xad69(%rip), %rdi      # 0xffd0
callq 0x2120
movq 0xad5d(%rip), %rdi      # 0xffd0
callq 0x2120
jmp 0x52da
movq 0xad4f(%rip), %rdi      # 0xffd0
callq 0x2120
movq 0xad43(%rip), %rdi      # 0xffd0
leaq 0x7840(%rip), %rsi      # 0xcad4
movl $0xf, %edx
callq 0x2270
movq 0xad2b(%rip), %rdi      # 0xffd0
callq 0x2120
movq 0xad1f(%rip), %rdi      # 0xffd0
leaq 0x7888(%rip), %rsi      # 0xcb40
movl $0x19, %edx
callq 0x2270
movq 0xad07(%rip), %rdi      # 0xffd0
callq 0x2120
movq 0xacfb(%rip), %rdi      # 0xffd0
callq 0x2120
movl $0x1, %edi
callq 0x2290
movq %rax, %rbx
jmp 0x5337
jmp 0x5313
jmp 0x5313
jmp 0x52f7
jmp 0x52f7
jmp 0x5313
jmp 0x5313
jmp 0x5313
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5316
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
jmp 0x5316
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x5378
leaq 0x58(%rsp), %rdi
callq 0x53d0
leaq 0x88(%rsp), %rdi
callq 0x2310
leaq 0x288(%rsp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x23a0