// File: /workspace/github_cpp_makefile_star2_O3/xukmin[P]rase/routing-metric-calculators.cc
// Function: DataAggregationCalculator::CalculateMetric(SensorNetwork const&)
double DataAggregationCalculator::CalculateMetric(const SensorNetwork& network) {
  // TODO: Make it an argument.
  static const double sensing_range = 15.0;
  std::vector<int> triggered;
  Position position(50.0, 50.0);  // FIXME: pass in region to the calculator.
  if (!network.FindSensorsWithinRange(position, sensing_range, &triggered)) {
    // No sensor will ever be triggered by the event.
    return 0.0;
  }

  std::set<int> visited;
  visited.insert(0);

  int num_transmissions = 1;
  for (int i = 0; i < triggered.size(); i++) {
    visited.insert(triggered[i]);
    num_transmissions++;
    int parent = network.GetParent(triggered[i]);
    while (visited.find(parent) == visited.end()) {
      visited.insert(parent);
      num_transmissions++;
      parent = network.GetParent(parent);
      assert(parent >= 0);
    }
  }

  return num_transmissions;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movaps 0x29e3(%rip), %xmm0     # 0xd1f0
leaq 0x60(%rsp), %rsi
movaps %xmm0, (%rsi)
movsd 0x29e3(%rip), %xmm0     # 0xd200
movq %rbx, %rdi
callq 0x63d4
xorps %xmm0, %xmm0
testb %al, %al
je 0xa950
leaq 0x38(%rsp), %r12
xorl %eax, %eax
movl %eax, (%r12)
movq %rax, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
movq %rax, 0x20(%r12)
leaq 0x4(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x30(%rsp), %rdi
callq 0x81f6
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0xa932
movl $0x1, %ebp
xorl %r13d, %r13d
leaq 0x30(%rsp), %r14
leaq 0x4(%rsp), %r15
leaq (%rax,%r13,4), %rsi
movq %r14, %rdi
callq 0x75b8
movq 0x10(%rsp), %rax
movslq (%rax,%r13,4), %rax
movq (%rbx), %rcx
leaq (%rax,%rax,8), %rax
movl 0x44(%rcx,%rax,8), %eax
movl %eax, 0x4(%rsp)
incl %ebp
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xa8e7
movq %r12, %r8
movq %r8, %rcx
movq %rdi, %rdx
movl 0x20(%rdi), %esi
xorl %edi, %edi
cmpl %eax, %esi
setl %dil
movq %rdx, %r8
cmovlq %rcx, %r8
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0xa8b5
cmpq %r12, %r8
je 0xa8e7
cmpl %eax, %esi
cmovlq %rcx, %rdx
cmpl 0x20(%rdx), %eax
jge 0xa90c
movq %r14, %rdi
movq %r15, %rsi
callq 0x75b8
movslq 0x4(%rsp), %rax
movq (%rbx), %rcx
leaq (%rax,%rax,8), %rax
movl 0x44(%rcx,%rax,8), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
jns 0xa8a6
jmp 0xa982
incq %r13
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r13, %rcx
ja 0xa882
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
jmp 0xa93a
movsd 0x1dc6(%rip), %xmm0     # 0xc700
movsd %xmm0, 0x8(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x503c
movsd 0x8(%rsp), %xmm0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa973
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
movsd %xmm0, 0x8(%rsp)
callq 0x31e0
movsd 0x8(%rsp), %xmm0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2945(%rip), %rdi      # 0xd2ce
leaq 0x28aa(%rip), %rsi      # 0xd23a
leaq 0x298f(%rip), %rcx      # 0xd326
movl $0xbe, %edx
callq 0x3100
jmp 0xa9aa
movq %rax, %rbx
jmp 0xa9b7
jmp 0xa9aa
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x503c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa9ce
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x31e0
movq %rbx, %rdi
callq 0x3360