// File: /workspace/github_cpp_makefile_star2_O1/iu-vail[P]iprimal/iPrimal.cpp
// Function: Primal::GreedyApprox2(std::vector<unsigned int, std::allocator<unsigned int>>&)
void
Primal::GreedyApprox2(vector<uint>& _asgn){

  _asgn.clear();
  _asgn.resize(row_size);
  set<uint> mem_rows;
  set<uint> mem_cols;
  priority_queue<
                pair<cell, double>,
                vector<pair<cell,double> >,
                less_comp<cell>
		> col_mins;

  //column-wise searching, push the smallest of each col in priority queue
  for(uint j=0; j<col_size; j++){
    double min_val = std::numeric_limits<double>::infinity(); 
    uint min_row = row_size;
    for(uint i=0; i<row_size; i++){
      if(orig_matrix[i][j] < min_val){
	min_val = orig_matrix[i][j];
	min_row = i;	
      }
    }
    cell c;
    c.row_idx = min_row;
    c.col_idx = j;
    col_mins.push(pair<cell, double>(c, min_val));
  }

  //assign those global minimals (conflicted) first
  while(!col_mins.empty()){
    pair<cell, double> p = col_mins.top();
    col_mins.pop();
    if(mem_rows.find(p.first.row_idx) == mem_rows.end()){
      mem_rows.insert(p.first.row_idx);
      mem_cols.insert(p.first.col_idx);
      _asgn[p.first.row_idx] = p.first.col_idx;
    }
  }

  //then assign other un-assigned
  //column-wise searching
  for(uint j=0; j<col_size; j++){
    if(mem_cols.find(j) == mem_cols.end()){
      double min_val = std::numeric_limits<double>::infinity(); 
      uint min_row = row_size;
      for(uint i=0; i<row_size; i++){
        if(orig_matrix[i][j] < min_val &&
      		mem_rows.find(i) == mem_rows.end()){
	  min_val = orig_matrix[i][j];
	  min_row = i;	
        }
      }
      _asgn[min_row] = j;
      mem_rows.insert(min_row);
    }//if
  }//for

  //double check if the assignment is meaningful
  set<uint> test(_asgn.begin(), _asgn.end());
  assert(test.size()==row_size);
  _cout("Approximate assignment: "<<endl);
  DisplayVec<uint>(_asgn);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %rcx
movq %rdi, %rbx
movq (%rsi), %rax
cmpq %rax, 0x8(%rsi)
je 0x4890
movq %rax, 0x8(%rcx)
movl (%rbx), %esi
movq %rcx, 0x8(%rsp)
movq %rcx, %rdi
callq 0x6c22
leaq 0x70(%rsp), %rbp
xorl %eax, %eax
movl %eax, (%rbp)
movq %rax, 0x8(%rbp)
movq %rbp, 0x10(%rbp)
movq %rbp, 0x18(%rbp)
movq %rax, 0x20(%rbp)
leaq 0xa0(%rsp), %rcx
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x19(%rsp)
movapd %xmm0, 0x10(%rsp)
cmpl %eax, 0x4(%rbx)
je 0x4970
xorl %r13d, %r13d
leaq 0x10(%rsp), %r15
leaq 0x38(%rsp), %r12
movl (%rbx), %eax
testq %rax, %rax
je 0x4939
movq 0xb0(%rbx), %rdx
xorl %esi, %esi
movl %eax, %ecx
movsd 0x679d(%rip), %xmm1     # 0xb0b0
movq (%rdx), %rdi
movsd (%rdi,%r13,8), %xmm0
ucomisd %xmm0, %xmm1
minsd %xmm1, %xmm0
cmoval %esi, %ecx
incq %rsi
addq $0x18, %rdx
movapd %xmm0, %xmm1
cmpq %rsi, %rax
jne 0x4913
jmp 0x4943
movsd 0x676f(%rip), %xmm0     # 0xb0b0
movl %eax, %ecx
movq %r13, %rax
shlq $0x20, %rax
movl %ecx, %ecx
orq %rax, %rcx
movq %rcx, 0x38(%rsp)
movsd %xmm0, 0x40(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x6de0
incq %r13
movl 0x4(%rbx), %eax
cmpq %rax, %r13
jb 0x48f9
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
je 0x4a24
leaq 0x38(%rsp), %r15
movq %r15, %r14
movl (%rax), %r13d
movl 0x4(%rax), %r12d
leaq 0x10(%rsp), %rdi
callq 0x6eaa
movq 0x78(%rsp), %rcx
movq %rbp, %rax
testq %rcx, %rcx
je 0x49c0
movq %rbp, %rax
xorl %edx, %edx
cmpl %r13d, 0x20(%rcx)
setb %dl
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x49a9
movq %rbp, %rcx
cmpq %rbp, %rax
movq %r14, %r15
je 0x49d6
cmpl 0x20(%rax), %r13d
cmovbq %rbp, %rax
movq %rax, %rcx
cmpq %rbp, %rcx
jne 0x4a14
movl %r13d, 0x38(%rsp)
leaq 0x68(%rsp), %rdi
movq %r15, %rsi
callq 0x7c5c
movl %r12d, 0x38(%rsp)
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x7c5c
movslq %r13d, %rax
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movl %r12d, (%rcx,%rax,4)
movq %r14, %r15
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
jne 0x4985
cmpl $0x0, 0x4(%rbx)
leaq 0xa0(%rsp), %r14
je 0x4b42
xorl %r13d, %r13d
leaq 0x68(%rsp), %r15
leaq 0x38(%rsp), %r12
movq 0xa8(%rsp), %rcx
movq %r14, %rax
testq %rcx, %rcx
je 0x4a70
movq %r14, %rax
movl 0x20(%rcx), %edx
xorl %esi, %esi
cmpq %rdx, %r13
cmovbeq %rcx, %rax
seta %sil
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x4a56
movq %r14, %rcx
cmpq %r14, %rax
je 0x4a85
movl 0x20(%rax), %ecx
cmpq %rcx, %r13
cmovbq %r14, %rax
movq %rax, %rcx
cmpq %r14, %rcx
jne 0x4b33
movl (%rbx), %eax
movl %eax, 0x38(%rsp)
testq %rax, %rax
je 0x4b18
movq 0xb0(%rbx), %rcx
movq 0x78(%rsp), %rdx
xorl %esi, %esi
movsd 0x6601(%rip), %xmm0     # 0xb0b0
leaq (%rsi,%rsi,2), %rdi
movq (%rcx,%rdi,8), %rdi
movsd (%rdi,%r13,8), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4b10
movq %rbp, %rdi
testq %rdx, %rdx
je 0x4aed
movq %rdx, %r8
movq %rbp, %rdi
movl 0x20(%r8), %r9d
xorl %r10d, %r10d
cmpq %r9, %rsi
cmovbeq %r8, %rdi
seta %r10b
movq 0x10(%r8,%r10,8), %r8
testq %r8, %r8
jne 0x4ad1
movq %rbp, %r8
cmpq %rbp, %rdi
je 0x4b03
movl 0x20(%rdi), %r8d
cmpq %r8, %rsi
cmovbq %rbp, %rdi
movq %rdi, %r8
cmpq %rbp, %r8
jne 0x4b10
movl %esi, 0x38(%rsp)
movapd %xmm1, %xmm0
incq %rsi
cmpq %rax, %rsi
jne 0x4aaf
movl 0x38(%rsp), %eax
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movl %r13d, (%rcx,%rax,4)
movq %r15, %rdi
movq %r12, %rsi
callq 0x7760
incq %r13
movl 0x4(%rbx), %eax
cmpq %rax, %r13
jb 0x4a43
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq 0x38(%rsp), %rdi
callq 0x6d5e
movl (%rbx), %eax
cmpq %rax, 0x60(%rsp)
jne 0x4bab
leaq 0x38(%rsp), %rdi
callq 0x71ba
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4b82
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
leaq 0x98(%rsp), %rdi
callq 0x71ba
leaq 0x68(%rsp), %rdi
callq 0x71ba
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6581(%rip), %rdi      # 0xb133
leaq 0x653e(%rip), %rsi      # 0xb0f7
leaq 0x65b4(%rip), %rcx      # 0xb174
movl $0xaa, %edx
callq 0x3150
jmp 0x4bd4
jmp 0x4bd4
jmp 0x4bd4
jmp 0x4bd4
jmp 0x4bd4
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4bee
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
leaq 0x98(%rsp), %rdi
callq 0x71ba
leaq 0x68(%rsp), %rdi
callq 0x71ba
movq %rbx, %rdi
callq 0x33d0
nop