// File: akinanop[P]mvl-solver/src/SolveFinite.cc
// Function: SolveFinite(CommandLine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void SolveFinite(CommandLine * cline, string type)
{
  //local variable
  double difftime = 0;
  double totaltime = 0;
  int result = -1;
  Formula * fobj;

  //Creating object
  fobj = new Formula(cline);
  //Building database
  fobj->BuildFormula(cline);
  //Compute Buildtime
  difftime = fobj->TIME_E - fobj->TIME_S;
  totaltime += difftime;
  printf("%s \t%2.4f\t", cline->FILE, fabs(difftime));
  //reinitialize the TIME_S and TIME_E
  fobj->TIME_S = GetTime();
  fobj->TIME_E = GetTime();
  //call the algorithm
  // fobj->checkUnit(); // move this check to the algo

  // *** Extended DPLL Algorithm Options

 if(type == "ch")

 {
      // 1. Chronological Backtracking
     result = fobj->ChronoBacktrack(0); // The function defined in FDSolver/Formula.cc
    }

  // 2. NonChronological Backtracking with Clause learning
 else
    {
	 if ( cline -> WATCH  ) {


    	  result = fobj-> WatchedLiterals ( cline -> RESTARTS );

      }
      else if (cline->RESTARTS != 0) {
        result = fobj->NonChronoBacktrack(cline->RESTARTS);
      }
      else  {

     result = fobj->NonChronoBacktrack(0);
      }
    }

  // compute the search time
  difftime = fobj->TIME_E - fobj->TIME_S;
  totaltime += difftime;
  //cout<<"Solving time: "<<endl;
  printf("%2.4f\t %2.4f\t", difftime, totaltime);
  cout<<endl;
  cout<<endl;
  cout << '\a';
  if(result == 0)
    cout<<"SAT"<<endl;
  else if(result == 1)
    cout<<"TIMEOUT"<<endl;
  else
    cout<<"UNSAT"<<endl;
  fobj->PrintInfo();
  if(result == 0)
   { if(cline->MODEL) { cout<<"The model: "<<endl;
     fobj->PrintModel(); }
      cout<<"Verifying model ... ";
       if(fobj->verifyModel())
 	cout<<"model is CORRECT"<<endl;
       else
 	cout<<"model is INCORRECT"<<endl;
     }
}

// Assembly:
subq $0x58, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
movl $0xb0, %edi
callq 0x2230
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rsi
callq 0xcea0
jmp 0x15e6e
movq 0x10(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0xd020
movq 0x28(%rsp), %rax
movsd 0x40(%rax), %xmm0
movq 0x28(%rsp), %rax
subsd 0x38(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x40(%rsp), %xmm0
addsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x50(%rsp), %rax
movq 0x20(%rax), %rsi
movsd 0x40(%rsp), %xmm0
movaps 0x1f67(%rip), %xmm1     # 0x17e30
pand %xmm1, %xmm0
leaq 0x1f6c(%rip), %rdi      # 0x17e40
movb $0x1, %al
callq 0x2050
callq 0x2ec0
movq 0x28(%rsp), %rax
movsd %xmm0, 0x38(%rax)
callq 0x2ec0
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rax
movsd %xmm0, 0x40(%rax)
leaq 0x1185(%rip), %rsi      # 0x1708a
callq 0x16160
testb $0x1, %al
jne 0x15f10
jmp 0x15f44
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x12780
movl %eax, 0x34(%rsp)
jmp 0x15f9e
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x20(%rsp)
movl %eax, 0x1c(%rsp)
movl $0xb0, %esi
callq 0x2240
jmp 0x16150
movq 0x50(%rsp), %rax
testb $0x1, 0x1(%rax)
je 0x15f67
movq 0x28(%rsp), %rdi
movq 0x50(%rsp), %rax
movl 0x34(%rax), %esi
callq 0x11ab0
movl %eax, 0x34(%rsp)
jmp 0x15f9c
movq 0x50(%rsp), %rax
cmpl $0x0, 0x34(%rax)
je 0x15f8a
movq 0x28(%rsp), %rdi
movq 0x50(%rsp), %rax
movl 0x34(%rax), %esi
callq 0x12060
movl %eax, 0x34(%rsp)
jmp 0x15f9a
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x12060
movl %eax, 0x34(%rsp)
jmp 0x15f9c
jmp 0x15f9e
movq 0x28(%rsp), %rax
movsd 0x40(%rax), %xmm0
movq 0x28(%rsp), %rax
subsd 0x38(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x40(%rsp), %xmm0
addsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
leaq 0x1e6e(%rip), %rdi      # 0x17e4b
movb $0x2, %al
callq 0x2050
movq 0x7fe5(%rip), %rdi      # 0x1dfd0
movq 0x7fce(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x7fd2(%rip), %rdi      # 0x1dfd0
movq 0x7fbb(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x7fbf(%rip), %rdi      # 0x1dfd0
movl $0x7, %esi
callq 0x22d0
cmpl $0x0, 0x34(%rsp)
jne 0x16046
movq 0x7fa7(%rip), %rdi      # 0x1dfd0
leaq 0x1d9b(%rip), %rsi      # 0x17dcb
callq 0x2220
movq %rax, %rdi
movq 0x7f81(%rip), %rsi      # 0x1dfc0
callq 0x2260
jmp 0x16095
cmpl $0x1, 0x34(%rsp)
jne 0x16071
movq 0x7f7c(%rip), %rdi      # 0x1dfd0
leaq 0x1dfe(%rip), %rsi      # 0x17e59
callq 0x2220
movq %rax, %rdi
movq 0x7f56(%rip), %rsi      # 0x1dfc0
callq 0x2260
jmp 0x16093
movq 0x7f58(%rip), %rdi      # 0x1dfd0
leaq 0x1d4a(%rip), %rsi      # 0x17dc9
callq 0x2220
movq %rax, %rdi
movq 0x7f32(%rip), %rsi      # 0x1dfc0
callq 0x2260
jmp 0x16095
movq 0x28(%rsp), %rdi
callq 0xdb60
cmpl $0x0, 0x34(%rsp)
jne 0x1614b
movq 0x50(%rsp), %rax
testb $0x1, (%rax)
je 0x160e0
movq 0x7f15(%rip), %rdi      # 0x1dfd0
leaq 0x1d9f(%rip), %rsi      # 0x17e61
callq 0x2220
movq %rax, %rdi
movq 0x7eef(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x28(%rsp), %rdi
callq 0xdaa0
movq 0x7ee9(%rip), %rdi      # 0x1dfd0
leaq 0x1d7f(%rip), %rsi      # 0x17e6d
callq 0x2220
movq 0x28(%rsp), %rdi
callq 0xdc50
testb $0x1, %al
jne 0x16103
jmp 0x16127
movq 0x7ec6(%rip), %rdi      # 0x1dfd0
leaq 0x1d71(%rip), %rsi      # 0x17e82
callq 0x2220
movq %rax, %rdi
movq 0x7ea0(%rip), %rsi      # 0x1dfc0
callq 0x2260
jmp 0x16149
movq 0x7ea2(%rip), %rdi      # 0x1dfd0
leaq 0x1d5e(%rip), %rsi      # 0x17e93
callq 0x2220
movq %rax, %rdi
movq 0x7e7c(%rip), %rsi      # 0x1dfc0
callq 0x2260
jmp 0x1614b
addq $0x58, %rsp
retq
movq 0x20(%rsp), %rdi
callq 0x2410
nopw (%rax,%rax)