// File: /workspace/github_cpp_makefile_star2_O1/iu-vail[P]iprimal/main.cpp
// Function: main
int main(int argc, char** argv)
{

  //parse command line and generate an assignment
  CmdParser parser(argc, argv);
  parser.DisplayInput();

  Assignment as;
  if(parser.GetInputFileName().empty()){
    if(parser.GetSeed())
      as.SetSeed(parser.GetSeed());
    else
      as.SetSeed(time(NULL));
    _cout(endl<<"  *Seed for random generator: "<<as.GetSeed()<<endl);
    as.RandomGenerate( parser.GetAssignmentSize(), 
			 parser.GetAssignmentSize(), 
			 MAX_RANDOM, 
			 parser.GetSeed() );
  }
  else{
    ifstream myfile(parser.GetInputFileName().c_str());
    as.ImportMatrix(myfile);
  }
  // negate matrix: uncomment below to convert from Minimization to Maximization
  //as.NegateMatrix();

  as.DisplayMatrix(as.GetMatrix());

  if(as.GetRowSize() != as.GetColSize()){
     cerr<<endl<<"  The input problem must be a SQUARE matrix. You can add dummy rows/columns of 0s to convert a rectangular matrix to a square matrix."<<endl<<endl;
     exit(0);
  }

//  vector<uint> asgn_vec;
//  ifstream fasgn((char*)"asgn.txt");
//  as.ImportVec(fasgn, asgn_vec);

  Utils utils;

  try{

    Primal primal(as.GetMatrix());

    double time_start = utils.GetCurTime();
    double time = 0;
  
    //initiation
#ifdef USE_GREEDY
    vector<uint> asgn_vec;
    primal.GreedyApprox2(asgn_vec);
    primal.InitSolution(asgn_vec);
#else
    primal.RandSolution();
#endif

    primal.PrimalAlgo();

    time += utils.GetCurTime() - time_start;
    cout<<"Time used: "<<time<<endl;

    //utils.WriteVec<uint>(primal.GetAsgnVec(), (char*)"asgn.txt");

    //for testing
    //primal.PrimalTest();
  }
  catch(int e){

    if(e==EXCEPTION_BROKEN){
      cerr<<"I suspect there is something wrong..."<<endl;
      cerr<<"Current seed: "<<as.GetSeed()<<endl;
      cerr<<"The problem has been written in to \"debug.txt\". Send this file to code maintainer?  "<<endl;
      utils.WriteMatrix(as);
    }
    else if(e==EXCEPTION_WRONG){
      cerr<<"!!Wrong solution, double check it. "<<endl;
      cerr<<"Current seed: "<<as.GetSeed()<<endl;
      cerr<<"The problem has been written in to \"debug.txt\"."<<endl;
      utils.WriteMatrix(as);
    }
    else
      cerr<<"Unknown exception caught. "<<endl;
  }

  return 0;

}

// Assembly:
pushq %r14
pushq %rbx
subq $0x2e8, %rsp            # imm = 0x2E8
movq %rsi, %rdx
movl %edi, %esi
leaq 0x88(%rsp), %rdi
callq 0x9772
leaq 0x90(%rsp), %rdi
leaq 0x20e3(%rip), %rsi      # 0xb3bc
callq 0x30c0
leaq 0xb8(%rsp), %rbx
leaq 0x22ad(%rip), %rsi      # 0xb59a
movq %rbx, %rdi
callq 0x30c0
movl $0x0, 0x48(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x58(%rsp)
movupd %xmm0, 0x68(%rsp)
movupd %xmm0, 0x78(%rsp)
leaq 0xf0(%rsp), %r14
movq %r14, -0x10(%r14)
movq -0x28(%rbx), %rsi
movq -0x20(%rbx), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rdi
callq 0x9c6a
movq 0xe0(%rsp), %rdi
movq 0xe8(%rsp), %rbx
cmpq %r14, %rdi
je 0x935c
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x3260
testq %rbx, %rbx
je 0x93d2
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x9c6a
movq (%rsp), %rsi
leaq 0xe0(%rsp), %rdi
movl $0x8, %edx
callq 0x33f0
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x93b1
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3260
leaq 0x48(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x3c06
leaq 0xe0(%rsp), %rdi
callq 0x3090
jmp 0x9406
movl 0x88(%rsp), %eax
testl %eax, %eax
jne 0x93e4
xorl %edi, %edi
callq 0x3210
leaq 0x48(%rsp), %rdi
movl %eax, (%rdi)
movl 0x88(%rsp), %r8d
movl 0xb0(%rsp), %edx
movl %edx, %esi
movl $0x3e8, %ecx            # imm = 0x3E8
callq 0x379c
leaq 0x58(%rsp), %rbx
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x3eea
movl 0x4c(%rsp), %eax
cmpl 0x50(%rsp), %eax
jne 0x9550
leaq 0x28(%rsp), %rdi
callq 0x8880
leaq 0xe0(%rsp), %rdi
movq %rbx, %rsi
callq 0x9826
leaq 0x28(%rsp), %rdi
callq 0x88c4
movsd %xmm0, 0x40(%rsp)
xorpd %xmm0, %xmm0
movq %rsp, %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0xe0(%rsp), %rdi
callq 0x486c
leaq 0xe0(%rsp), %rdi
movq %rsp, %rsi
callq 0x45b2
leaq 0xe0(%rsp), %rdi
callq 0x5ecc
leaq 0x28(%rsp), %rdi
callq 0x88c4
movsd %xmm0, 0x38(%rsp)
movq 0x5b24(%rip), %rdi      # 0xefc8
leaq 0x22a0(%rip), %rsi      # 0xb74b
movl $0xb, %edx
callq 0x32a0
movsd 0x38(%rsp), %xmm1
subsd 0x40(%rsp), %xmm1
xorpd %xmm0, %xmm0
addsd %xmm1, %xmm0
movq 0x5af8(%rip), %rdi      # 0xefc8
callq 0x3370
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9515
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
leaq 0xe0(%rsp), %rdi
callq 0x9a78
leaq 0x28(%rsp), %rdi
callq 0x88f4
leaq 0x48(%rsp), %rdi
callq 0x9b7c
leaq 0x88(%rsp), %rdi
callq 0x9ba2
xorl %eax, %eax
addq $0x2e8, %rsp            # imm = 0x2E8
popq %rbx
popq %r14
retq
movq 0x5a99(%rip), %rdi      # 0xeff0
callq 0x3110
movq %rax, %rbx
leaq 0x215f(%rip), %rsi      # 0xb6c5
movl $0x85, %edx
movq %rax, %rdi
callq 0x32a0
movq %rbx, %rdi
callq 0x3110
movq %rax, %rdi
callq 0x3110
xorl %edi, %edi
callq 0x32b0
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x3090
jmp 0x95d0
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x95d0
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0x95d0
jmp 0x95cd
movq %rdx, %r14
movq %rax, %rbx
jmp 0x960b
movq %rdx, %r14
movq %rax, %rbx
jmp 0x9618
jmp 0x95cd
jmp 0x95cd
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x9b7c
leaq 0x88(%rsp), %rdi
callq 0x9ba2
movq %rbx, %rdi
callq 0x33d0
movq %rdx, %r14
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x960b
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
leaq 0xe0(%rsp), %rdi
callq 0x9a78
cmpl $0x1, %r14d
jne 0x9762
movq %rbx, %rdi
callq 0x30f0
movl (%rax), %eax
cmpl $-0x2, %eax
je 0x969c
cmpl $-0x1, %eax
jne 0x972c
movq 0x59af(%rip), %rdi      # 0xeff0
leaq 0x210f(%rip), %rsi      # 0xb757
movl $0x25, %edx
callq 0x32a0
movq 0x5997(%rip), %rdi      # 0xeff0
callq 0x3110
movq 0x598b(%rip), %rdi      # 0xeff0
leaq 0x2111(%rip), %rsi      # 0xb77d
movl $0xe, %edx
callq 0x32a0
movl 0x48(%rsp), %esi
movq 0x596f(%rip), %rdi      # 0xeff0
callq 0x3160
movq %rax, %rdi
callq 0x3110
movl $0x54, %edx
leaq 0x20f2(%rip), %rsi      # 0xb78c
jmp 0x96fc
movq 0x594d(%rip), %rdi      # 0xeff0
leaq 0x2141(%rip), %rsi      # 0xb7eb
movl $0x23, %edx
callq 0x32a0
movq 0x5935(%rip), %rdi      # 0xeff0
callq 0x3110
movq 0x5929(%rip), %rdi      # 0xeff0
leaq 0x20af(%rip), %rsi      # 0xb77d
movl $0xe, %edx
callq 0x32a0
movl 0x48(%rsp), %esi
movq 0x590d(%rip), %rdi      # 0xeff0
callq 0x3160
movq %rax, %rdi
callq 0x3110
movl $0x2f, %edx
leaq 0x2113(%rip), %rsi      # 0xb80f
movq 0x58ed(%rip), %rdi      # 0xeff0
callq 0x32a0
movq 0x58e1(%rip), %rdi      # 0xeff0
callq 0x3110
leaq 0x20c6(%rip), %rdx      # 0xb7e1
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x8b48
jmp 0x9750
movq 0x58bd(%rip), %rdi      # 0xeff0
leaq 0x2105(%rip), %rsi      # 0xb83f
movl $0x1a, %edx
callq 0x32a0
movq 0x58a5(%rip), %rdi      # 0xeff0
callq 0x3110
callq 0x33a0
jmp 0x9522
movq %rax, %rbx
callq 0x33a0
leaq 0x28(%rsp), %rdi
callq 0x88f4
jmp 0x95d0
nop