// File: /workspace/github_cpp_makefile_star2_O3/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 0x99da
leaq 0x90(%rsp), %rdi
leaq 0x1e9f(%rip), %rsi      # 0xb3dc
callq 0x30c0
leaq 0xb8(%rsp), %rbx
leaq 0x2049(%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 0x9ed8
movq 0xe0(%rsp), %rdi
movq 0xe8(%rsp), %rbx
cmpq %r14, %rdi
je 0x95c0
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x3260
testq %rbx, %rbx
je 0x9636
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x9ed8
movq (%rsp), %rsi
leaq 0xe0(%rsp), %rdi
movl $0x8, %edx
callq 0x33f0
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x9615
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3260
leaq 0x48(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x3c22
leaq 0xe0(%rsp), %rdi
callq 0x3090
jmp 0x966f
movl 0x88(%rsp), %r8d
movl %r8d, %eax
testl %r8d, %r8d
jne 0x9655
xorl %edi, %edi
callq 0x3210
movl 0x88(%rsp), %r8d
leaq 0x48(%rsp), %rdi
movl %eax, (%rdi)
movl 0xb0(%rsp), %edx
movl %edx, %esi
movl $0x3e8, %ecx            # imm = 0x3E8
callq 0x37a0
leaq 0x58(%rsp), %rbx
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x3f08
movl 0x4c(%rsp), %eax
cmpl 0x50(%rsp), %eax
jne 0x97b9
leaq 0x28(%rsp), %rdi
callq 0x8aec
leaq 0xe0(%rsp), %rdi
movq %rbx, %rsi
callq 0x9a8e
leaq 0x28(%rsp), %rdi
callq 0x8b30
movsd %xmm0, 0x40(%rsp)
xorpd %xmm0, %xmm0
movq %rsp, %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0xe0(%rsp), %rdi
callq 0x4894
leaq 0xe0(%rsp), %rdi
movq %rsp, %rsi
callq 0x45d0
leaq 0xe0(%rsp), %rdi
callq 0x5eb6
leaq 0x28(%rsp), %rdi
callq 0x8b30
movsd %xmm0, 0x38(%rsp)
movq 0x58bb(%rip), %rdi      # 0xefc8
leaq 0x2037(%rip), %rsi      # 0xb74b
movl $0xb, %edx
callq 0x32a0
movsd 0x38(%rsp), %xmm1
subsd 0x40(%rsp), %xmm1
xorpd %xmm0, %xmm0
addsd %xmm1, %xmm0
movq 0x588f(%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 0x977e
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
leaq 0xe0(%rsp), %rdi
callq 0x9ce0
leaq 0x28(%rsp), %rdi
callq 0x8b60
leaq 0x48(%rsp), %rdi
callq 0x9de4
leaq 0x88(%rsp), %rdi
callq 0x9e0a
xorl %eax, %eax
addq $0x2e8, %rsp            # imm = 0x2E8
popq %rbx
popq %r14
retq
movq 0x5830(%rip), %rdi      # 0xeff0
callq 0x3110
movq %rax, %rbx
leaq 0x1ef6(%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 0x9839
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x9839
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0x9839
jmp 0x9836
movq %rdx, %r14
movq %rax, %rbx
jmp 0x9874
movq %rdx, %r14
movq %rax, %rbx
jmp 0x9881
jmp 0x9836
jmp 0x9836
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x9de4
leaq 0x88(%rsp), %rdi
callq 0x9e0a
movq %rbx, %rdi
callq 0x33d0
movq %rdx, %r14
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9874
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
leaq 0xe0(%rsp), %rdi
callq 0x9ce0
cmpl $0x1, %r14d
jne 0x99cb
movq %rbx, %rdi
callq 0x30f0
movl (%rax), %eax
cmpl $-0x2, %eax
je 0x9905
cmpl $-0x1, %eax
jne 0x9995
movq 0x5746(%rip), %rdi      # 0xeff0
leaq 0x1ea6(%rip), %rsi      # 0xb757
movl $0x25, %edx
callq 0x32a0
movq 0x572e(%rip), %rdi      # 0xeff0
callq 0x3110
movq 0x5722(%rip), %rdi      # 0xeff0
leaq 0x1ea8(%rip), %rsi      # 0xb77d
movl $0xe, %edx
callq 0x32a0
movl 0x48(%rsp), %esi
movq 0x5706(%rip), %rdi      # 0xeff0
callq 0x3160
movq %rax, %rdi
callq 0x3110
movl $0x54, %edx
leaq 0x1e89(%rip), %rsi      # 0xb78c
jmp 0x9965
movq 0x56e4(%rip), %rdi      # 0xeff0
leaq 0x1ed8(%rip), %rsi      # 0xb7eb
movl $0x23, %edx
callq 0x32a0
movq 0x56cc(%rip), %rdi      # 0xeff0
callq 0x3110
movq 0x56c0(%rip), %rdi      # 0xeff0
leaq 0x1e46(%rip), %rsi      # 0xb77d
movl $0xe, %edx
callq 0x32a0
movl 0x48(%rsp), %esi
movq 0x56a4(%rip), %rdi      # 0xeff0
callq 0x3160
movq %rax, %rdi
callq 0x3110
movl $0x2f, %edx
leaq 0x1eaa(%rip), %rsi      # 0xb80f
movq 0x5684(%rip), %rdi      # 0xeff0
callq 0x32a0
movq 0x5678(%rip), %rdi      # 0xeff0
callq 0x3110
leaq 0x1e5d(%rip), %rdx      # 0xb7e1
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x8dac
jmp 0x99b9
movq 0x5654(%rip), %rdi      # 0xeff0
leaq 0x1e9c(%rip), %rsi      # 0xb83f
movl $0x1a, %edx
callq 0x32a0
movq 0x563c(%rip), %rdi      # 0xeff0
callq 0x3110
callq 0x33a0
jmp 0x978b
movq %rax, %rbx
callq 0x33a0
leaq 0x28(%rsp), %rdi
callq 0x8b60
jmp 0x9839