// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rax
cmpq %rax, 0x8(%rsi)
je 0x48b8
movq %rax, 0x8(%r14)
movl (%rbx), %esi
movq %r14, %rdi
callq 0x6c3c
leaq 0x90(%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 0x60(%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, 0x9(%rsp)
movapd %xmm0, (%rsp)
cmpl %eax, 0x4(%rbx)
je 0x4b62
xorl %r13d, %r13d
movq %rsp, %r15
leaq 0x28(%rsp), %r12
movl (%rbx), %eax
testq %rax, %rax
je 0x495b
movq 0xb0(%rbx), %rcx
xorl %esi, %esi
movl %eax, %edx
movsd 0x677d(%rip), %xmm0     # 0xb0b0
movapd %xmm0, %xmm1
movq (%rcx), %rdi
movsd (%rdi,%r13,8), %xmm0
ucomisd %xmm0, %xmm1
cmoval %esi, %edx
minsd %xmm1, %xmm0
incq %rsi
addq $0x18, %rcx
cmpq %rsi, %rax
jne 0x4933
movl %edx, %eax
jmp 0x4965
movsd 0x674d(%rip), %xmm0     # 0xb0b0
xorl %eax, %eax
movq %r13, %rcx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x28(%rsp)
movsd %xmm0, 0x30(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x6e02
incq %r13
movl 0x4(%rbx), %eax
cmpq %rax, %r13
jb 0x4919
movq (%rsp), %rcx
cmpq 0x8(%rsp), %rcx
je 0x4a3b
leaq 0x28(%rsp), %r13
movl (%rcx), %r15d
movl 0x4(%rcx), %r12d
movq %rsp, %rdi
callq 0x6ec0
movq 0x98(%rsp), %rsi
testq %rsi, %rsi
je 0x49f8
movq %rbp, %rdi
movq %rdi, %rax
movq %rsi, %rcx
movl 0x20(%rsi), %edx
xorl %esi, %esi
cmpl %r15d, %edx
setb %sil
movq %rcx, %rdi
cmovbq %rax, %rdi
movq 0x10(%rcx,%rsi,8), %rsi
testq %rsi, %rsi
jne 0x49c3
cmpq %rbp, %rdi
je 0x49f8
cmpl %r15d, %edx
cmovbq %rax, %rcx
cmpl 0x20(%rcx), %r15d
jae 0x4a29
movl %r15d, 0x28(%rsp)
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
callq 0x7ed8
movl %r12d, 0x28(%rsp)
leaq 0x58(%rsp), %rdi
movq %r13, %rsi
callq 0x7ed8
movslq %r15d, %rax
movq (%r14), %rcx
movl %r12d, (%rcx,%rax,4)
movq (%rsp), %rcx
cmpq 0x8(%rsp), %rcx
jne 0x49a4
movl 0x4(%rbx), %eax
testl %eax, %eax
leaq 0x60(%rsp), %r15
je 0x4b62
xorl %r13d, %r13d
leaq 0x28(%rsp), %r12
movq 0x68(%rsp), %r8
testq %r8, %r8
je 0x4a9a
movq %r15, %rdi
movq %rdi, %rcx
movq %r8, %rdx
movl 0x20(%r8), %esi
xorl %r8d, %r8d
cmpq %rsi, %r13
movq %rdx, %rdi
cmovaq %rcx, %rdi
seta %r8b
movq 0x10(%rdx,%r8,8), %r8
testq %r8, %r8
jne 0x4a5d
cmpq %r15, %rdi
je 0x4a9a
cmpq %rsi, %r13
cmovaq %rcx, %rdx
movl 0x20(%rdx), %ecx
cmpq %rcx, %r13
jae 0x4b54
movl (%rbx), %eax
movl %eax, 0x28(%rsp)
testq %rax, %rax
je 0x4b38
movq 0xb0(%rbx), %rcx
movq 0x98(%rsp), %rdx
movl %eax, %edi
xorl %esi, %esi
movsd 0x65ec(%rip), %xmm0     # 0xb0b0
leaq (%rsi,%rsi,2), %r8
movq (%rcx,%r8,8), %r8
movsd (%r8,%r13,8), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4b27
testq %rdx, %rdx
je 0x4b1d
movq %rdx, %r9
movq %rbp, %r11
movq %r11, %r8
movq %r9, %r15
movl 0x20(%r9), %r10d
xorl %r9d, %r9d
cmpq %r10, %rsi
movq %r15, %r11
cmovaq %r8, %r11
seta %r9b
movq 0x10(%r15,%r9,8), %r9
testq %r9, %r9
jne 0x4ae3
cmpq %rbp, %r11
je 0x4b1d
cmpq %r10, %rsi
cmovaq %r8, %r15
movl 0x20(%r15), %r8d
cmpq %r8, %rsi
jae 0x4b27
movl %esi, 0x28(%rsp)
movl %esi, %edi
movapd %xmm1, %xmm0
incq %rsi
cmpq %rax, %rsi
jne 0x4ac4
movl %edi, %eax
leaq 0x60(%rsp), %r15
jmp 0x4b3a
xorl %eax, %eax
movq (%r14), %rcx
movl %r13d, (%rcx,%rax,4)
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
callq 0x79e4
movl 0x4(%rbx), %eax
incq %r13
movl %eax, %ecx
cmpq %rcx, %r13
jb 0x4a50
movq (%r14), %rsi
movq 0x8(%r14), %rdx
leaq 0x28(%rsp), %rdi
callq 0x6d86
movl (%rbx), %eax
cmpq %rax, 0x50(%rsp)
jne 0x4bc5
leaq 0x28(%rsp), %rdi
callq 0x71d4
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x4b9c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
leaq 0x58(%rsp), %rdi
callq 0x71d4
leaq 0x88(%rsp), %rdi
callq 0x71d4
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6587(%rip), %rdi      # 0xb153
leaq 0x6544(%rip), %rsi      # 0xb117
leaq 0x65ba(%rip), %rcx      # 0xb194
movl $0xaa, %edx
callq 0x3150
jmp 0x4bee
jmp 0x4bee
jmp 0x4bee
jmp 0x4bee
jmp 0x4bee
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x4c07
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
leaq 0x58(%rsp), %rdi
callq 0x71d4
leaq 0x88(%rsp), %rdi
callq 0x71d4
movq %rbx, %rdi
callq 0x33d0