// File: xukmin[P]rase/routing-metric-calculators.cc
// Function: SortSensorsByUsage(SensorNetwork const&, std::vector<int, std::allocator<int>>*)
void SortSensorsByUsage(const SensorNetwork& network,
                        std::vector<int>* sorted_sensors) {
  std::vector<SensorUsage> usages(network.num_sensors());
  for (int i = 0; i < usages.size(); i++) {
    usages[i].sensor = i;
    usages[i].usage = 1;  // Every sensor is used by itself.
  }

  for (int i = 0; i < network.num_sensors(); i++) {
    int parent = network.GetParent(i);
    while (parent >= 0) {
      usages[parent].usage++;
      parent = network.GetParent(parent);
    }
  }

  std::sort(usages.begin(), usages.end(), std::greater<SensorUsage>());

  sorted_sensors->resize(usages.size());
  for (int i = 0; i < usages.size(); i++) {
    (*sorted_sensors)[i] = usages[i].sensor;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0xe7c0
cltq
movq %rax, -0x70(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0x68(%rbp)
callq 0x1ad60
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0x28(%rbp), %rdi
callq 0x1ad80
jmp 0x19402
leaq -0x29(%rbp), %rdi
callq 0x1adf0
movl $0x0, -0x40(%rbp)
movslq -0x40(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x1ae10
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x19480
movl -0x40(%rbp), %eax
movl %eax, -0x7c(%rbp)
movslq -0x40(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x1ae30
movl -0x7c(%rbp), %ecx
movl %ecx, (%rax)
movslq -0x40(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x1ae30
movl $0x1, 0x4(%rax)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x19412
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x1adf0
jmp 0x195f9
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x8(%rbp), %rdi
callq 0xe7c0
movl %eax, -0x80(%rbp)
jmp 0x1949e
movl -0x84(%rbp), %eax
movl -0x80(%rbp), %ecx
cmpl %ecx, %eax
jge 0x19530
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0xeb20
movl %eax, -0x88(%rbp)
jmp 0x194c3
movl -0x88(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jl 0x19520
movslq -0x48(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x1ae30
movl 0x4(%rax), %ecx
incl %ecx
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0xeb20
movl %eax, -0x8c(%rbp)
jmp 0x194fb
movl -0x8c(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x194cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x1af80
jmp 0x195f9
jmp 0x19522
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x19487
leaq -0x28(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x1ae90
movq -0x98(%rbp), %rdi
movq %rax, -0x50(%rbp)
callq 0x1aec0
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x1ae50
jmp 0x19563
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x1ae10
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x1aef0
jmp 0x19588
movl $0x0, -0x60(%rbp)
movslq -0x60(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x1ae10
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
jae 0x195e7
movslq -0x60(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x1ae30
movl (%rax), %eax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x60(%rbp), %rsi
callq 0xe570
movl -0xac(%rbp), %ecx
movl %ecx, (%rax)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1958f
leaq -0x28(%rbp), %rdi
callq 0x1af80
addq $0xb0, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x33d0
nopw %cs:(%rax,%rax)