// File: /workspace/github_cpp_makefile_star2_O3/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 0x51c8
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 0x522a
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 0x4fcd
movzbl 0x1050(%rsp), %eax
cmpl $0x70, %eax
je 0x4e9c
cmpl $0x63, %eax
jne 0x4ed6
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 0x4e47
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
leaq 0x1050(%rsp), %r15
cmpb $0x9, %al
je 0x4efb
movzbl %al, %ecx
cmpl $0x20, %ecx
jne 0x4f04
movb 0x1(%r15), %al
incq %r15
jmp 0x4eef
xorl %ebp, %ebp
cmpb $0x20, %al
ja 0x4f13
movzbl %al, %ecx
btq %rcx, %r14
jb 0x4f24
movb %al, 0x490(%rsp,%rbp)
movb 0x1(%r15,%rbp), %al
incq %rbp
jmp 0x4f06
movb $0x0, 0x490(%rsp,%rbp)
cmpb $0x0, 0x490(%rsp)
je 0x4f88
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 0x53d6
movl 0xc(%rsp), %eax
testl %eax, %eax
je 0x4f88
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x4f79
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x4f88
leaq 0x20(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x54e4
addq %rbp, %r15
movb (%r15), %al
testb %al, %al
jne 0x4eef
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x52fc
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
leaq 0x288(%rsp), %r15
je 0x4e47
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
jmp 0x4e47
movq 0x70(%rsp), %r14
leaq 0x60(%rsp), %rdi
callq 0x2150
movq %rax, %r15
leaq 0x8b3b(%rip), %r12      # 0xdb21
leaq 0x88(%rsp), %rbx
leaq 0x8b65(%rip), %r13      # 0xdb5a
cmpq %r15, %r14
je 0x505e
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 0x4ff5
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 0x5143
movq 0x10(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
leaq 0x8ac1(%rip), %r13      # 0xdb61
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 0x5109
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 0x50e3
movq %rbx, %rdi
callq 0x2390
movq %r13, %rsi
jmp 0x50f4
negl %esi
movq %rbx, %rdi
callq 0x2390
leaq 0x8a69(%rip), %rsi      # 0xdb5d
movl $0x3, %edx
movq %rax, %rdi
callq 0x2270
incq %r12
cmpq %r12, %r14
jne 0x50c5
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 0x50a0
leaq 0x288(%rsp), %rdi
callq 0x2090
leaq 0x88(%rsp), %rdi
callq 0x22f0
leaq 0x40(%rsp), %rdi
callq 0x5328
leaq 0x58(%rsp), %rdi
callq 0x5386
movq 0xbe50(%rip), %rax      # 0x10fc8
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 0xbe01(%rip), %rdi      # 0x10fd0
callq 0x2120
movq 0xbdf5(%rip), %rdi      # 0x10fd0
leaq 0x88f2(%rip), %rsi      # 0xdad4
movl $0xf, %edx
callq 0x2270
movq 0xbddd(%rip), %rdi      # 0x10fd0
callq 0x2120
movq 0xbdd1(%rip), %rdi      # 0x10fd0
leaq 0x893a(%rip), %rsi      # 0xdb40
movl $0x19, %edx
callq 0x2270
movq 0xbdb9(%rip), %rdi      # 0x10fd0
callq 0x2120
movq 0xbdad(%rip), %rdi      # 0x10fd0
callq 0x2120
jmp 0x528a
movq 0xbd9f(%rip), %rdi      # 0x10fd0
callq 0x2120
movq 0xbd93(%rip), %rdi      # 0x10fd0
leaq 0x8890(%rip), %rsi      # 0xdad4
movl $0xf, %edx
callq 0x2270
movq 0xbd7b(%rip), %rdi      # 0x10fd0
callq 0x2120
movq 0xbd6f(%rip), %rdi      # 0x10fd0
leaq 0x88d8(%rip), %rsi      # 0xdb40
movl $0x19, %edx
callq 0x2270
movq 0xbd57(%rip), %rdi      # 0x10fd0
callq 0x2120
movq 0xbd4b(%rip), %rdi      # 0x10fd0
callq 0x2120
movl $0x1, %edi
callq 0x2290
movq %rax, %rbx
jmp 0x52e7
jmp 0x52c3
jmp 0x52c3
jmp 0x52a7
jmp 0x52a7
jmp 0x52c3
jmp 0x52c3
jmp 0x52c3
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x52c6
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
jmp 0x52c6
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x5328
leaq 0x58(%rsp), %rdi
callq 0x5386
leaq 0x88(%rsp), %rdi
callq 0x2310
leaq 0x288(%rsp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x23a0