// File: 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
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x45b0
movq -0x1b8(%rbp), %rax
movq -0x10(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0xa450
leaq -0x40(%rbp), %rdi
callq 0xa8a0
leaq -0x70(%rbp), %rdi
callq 0xa8a0
leaq -0x90(%rbp), %rdi
callq 0xaae0
jmp 0x715b
movl $0x0, -0xa0(%rbp)
movq -0x1b8(%rbp), %rcx
movl -0xa0(%rbp), %eax
cmpl 0x4(%rcx), %eax
jae 0x72db
callq 0xa8c0
movq -0x1b8(%rbp), %rax
movsd %xmm0, -0xa8(%rbp)
movl (%rax), %eax
movl %eax, -0xac(%rbp)
movl $0x0, -0xb0(%rbp)
movq -0x1b8(%rbp), %rcx
movl -0xb0(%rbp), %eax
cmpl (%rcx), %eax
jae 0x7265
movq -0x1b8(%rbp), %rdi
addq $0xb0, %rdi
movl -0xb0(%rbp), %eax
movl %eax, %esi
callq 0x4330
movq %rax, %rdi
movl -0xa0(%rbp), %eax
movl %eax, %esi
callq 0x43e0
movsd (%rax), %xmm1
movsd -0xa8(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x724f
movq -0x1b8(%rbp), %rdi
addq $0xb0, %rdi
movl -0xb0(%rbp), %eax
movl %eax, %esi
callq 0x4330
movq %rax, %rdi
movl -0xa0(%rbp), %eax
movl %eax, %esi
callq 0x43e0
movsd (%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
movl -0xb0(%rbp), %eax
movl %eax, -0xac(%rbp)
jmp 0x724f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x774a
jmp 0x7251
movl -0xb0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb0(%rbp)
jmp 0x71a1
movl -0xac(%rbp), %eax
movl %eax, -0xb8(%rbp)
movl -0xa0(%rbp), %eax
movl %eax, -0xb4(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0xaba0
jmp 0x7299
leaq -0x90(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xab40
jmp 0x72ae
jmp 0x72b0
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x7165
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x773e
jmp 0x72dd
leaq -0x90(%rbp), %rdi
callq 0xabd0
movb %al, -0x1b9(%rbp)
jmp 0x72f1
movb -0x1b9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x7302
jmp 0x7448
leaq -0x90(%rbp), %rdi
callq 0xabf0
movq %rax, -0x1c8(%rbp)
jmp 0x7317
movq -0x1c8(%rbp), %rax
movups (%rax), %xmm0
movaps %xmm0, -0xe0(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xac10
jmp 0x7336
movl -0xe0(%rbp), %eax
movl %eax, -0xec(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0xec(%rbp), %rsi
callq 0xa900
movq %rax, -0x1d0(%rbp)
jmp 0x735b
movq -0x1d0(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xa940
movq %rax, -0xf8(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xa8d0
testb $0x1, %al
jne 0x7395
jmp 0x7443
movl -0xe0(%rbp), %eax
movl %eax, -0xfc(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0xfc(%rbp), %rsi
callq 0xac70
movb %dl, -0x1d9(%rbp)
movq %rax, -0x1d8(%rbp)
jmp 0x73c0
movb -0x1d9(%rbp), %al
movq -0x1d8(%rbp), %rcx
movq %rcx, -0x110(%rbp)
movb %al, -0x108(%rbp)
movl -0xdc(%rbp), %eax
movl %eax, -0x114(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x114(%rbp), %rsi
callq 0xac70
movb %dl, -0x1e9(%rbp)
movq %rax, -0x1e8(%rbp)
jmp 0x7405
movb -0x1e9(%rbp), %al
movq -0x1e8(%rbp), %rcx
movq %rcx, -0x128(%rbp)
movb %al, -0x120(%rbp)
movl -0xdc(%rbp), %eax
movl %eax, -0x1f0(%rbp)
movq -0x10(%rbp), %rdi
movslq -0xe0(%rbp), %rsi
callq 0xa4e0
movl -0x1f0(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x72dd
movl $0x0, -0x12c(%rbp)
movq -0x1b8(%rbp), %rcx
movl -0x12c(%rbp), %eax
cmpl 0x4(%rcx), %eax
jae 0x7664
leaq -0x70(%rbp), %rdi
leaq -0x12c(%rbp), %rsi
callq 0xa900
movq %rax, -0x1f8(%rbp)
jmp 0x7481
movq -0x1f8(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xa940
movq %rax, -0x140(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0xa8d0
testb $0x1, %al
jne 0x74bb
jmp 0x764e
callq 0xa8c0
movq -0x1b8(%rbp), %rax
movsd %xmm0, -0x148(%rbp)
movl (%rax), %eax
movl %eax, -0x14c(%rbp)
movl $0x0, -0x150(%rbp)
movq -0x1b8(%rbp), %rcx
movl -0x150(%rbp), %eax
cmpl (%rcx), %eax
jae 0x75f0
movq -0x1b8(%rbp), %rdi
addq $0xb0, %rdi
movl -0x150(%rbp), %eax
movl %eax, %esi
callq 0x4330
movq %rax, %rdi
movl -0x12c(%rbp), %eax
movl %eax, %esi
callq 0x43e0
movsd (%rax), %xmm1
movsd -0x148(%rbp), %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
movb %al, -0x1f9(%rbp)
jbe 0x758b
leaq -0x40(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0xa900
movq %rax, -0x208(%rbp)
jmp 0x7554
movq -0x208(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xa940
movq %rax, -0x160(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0xa8d0
movb %al, -0x1f9(%rbp)
movb -0x1f9(%rbp), %al
testb $0x1, %al
jne 0x7597
jmp 0x75da
movq -0x1b8(%rbp), %rdi
addq $0xb0, %rdi
movl -0x150(%rbp), %eax
movl %eax, %esi
callq 0x4330
movq %rax, %rdi
movl -0x12c(%rbp), %eax
movl %eax, %esi
callq 0x43e0
movsd (%rax), %xmm0
movsd %xmm0, -0x148(%rbp)
movl -0x150(%rbp), %eax
movl %eax, -0x14c(%rbp)
jmp 0x75dc
movl -0x150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x150(%rbp)
jmp 0x74e1
movl -0x12c(%rbp), %eax
movl %eax, -0x218(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14c(%rbp), %eax
movl %eax, %esi
callq 0xa4e0
movl -0x218(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x40(%rbp), %rdi
leaq -0x14c(%rbp), %rsi
callq 0xa970
movb %dl, -0x211(%rbp)
movq %rax, -0x210(%rbp)
jmp 0x7634
movb -0x211(%rbp), %al
movq -0x210(%rbp), %rcx
movq %rcx, -0x170(%rbp)
movb %al, -0x168(%rbp)
jmp 0x7650
movl -0x12c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
jmp 0x7452
movq -0x10(%rbp), %rdi
callq 0x65c0
movq %rax, -0x1a8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6410
movq %rax, -0x1b0(%rbp)
movq -0x1a8(%rbp), %rsi
movq -0x1b0(%rbp), %rdx
leaq -0x1a0(%rbp), %rdi
callq 0xa9c0
jmp 0x76a0
leaq -0x1a0(%rbp), %rdi
callq 0xaa40
movq -0x1b8(%rbp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
jne 0x76bc
jmp 0x76db
leaq 0x12a40(%rip), %rdi     # 0x1a103
leaq 0x129fd(%rip), %rsi     # 0x1a0c7
movl $0xaa, %edx
leaq 0x12a6e(%rip), %rcx     # 0x1a144
callq 0x3190
movq -0x1b8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xaa60
jmp 0x76ed
leaq -0x1a0(%rbp), %rdi
callq 0xaac0
leaq -0x90(%rbp), %rdi
callq 0xacc0
leaq -0x70(%rbp), %rdi
callq 0xaac0
leaq -0x40(%rbp), %rdi
callq 0xaac0
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0xaac0
leaq -0x90(%rbp), %rdi
callq 0xacc0
leaq -0x70(%rbp), %rdi
callq 0xaac0
leaq -0x40(%rbp), %rdi
callq 0xaac0
movq -0x98(%rbp), %rdi
callq 0x3490
nopl (%rax,%rax)