// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rsi, %rbx
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movabsq $0x4049000000000000, %rax # imm = 0x4049000000000000
leaq 0x58(%rsp), %rsi
movq %rax, (%rsi)
movq %rax, 0x8(%rsi)
movsd 0x2990(%rip), %xmm0     # 0xd190
movq %rbx, %rdi
callq 0x641c
xorps %xmm0, %xmm0
testb %al, %al
je 0xa93a
leaq 0x30(%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 0x28(%rsp), %rdi
callq 0x814c
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0xa91c
movl $0x1, %ebp
xorl %r13d, %r13d
leaq 0x28(%rsp), %r14
leaq 0x4(%rsp), %r15
leaq (%rax,%r13,4), %rsi
movq %r14, %rdi
callq 0x7506
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)
movq 0x38(%rsp), %rcx
movq %r12, %rax
testq %rcx, %rcx
je 0xa8b4
movl 0x4(%rsp), %edx
movq %r12, %rax
xorl %esi, %esi
cmpl %edx, 0x20(%rcx)
setl %sil
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0xa89d
movq %r12, %rcx
cmpq %r12, %rax
je 0xa8ca
movl 0x4(%rsp), %ecx
cmpl 0x20(%rax), %ecx
cmovlq %r12, %rax
movq %rax, %rcx
incl %ebp
cmpq %r12, %rcx
jne 0xa8f6
movq %r14, %rdi
movq %r15, %rsi
callq 0x7506
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 0xa889
jmp 0xa96c
incq %r13
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r13, %rcx
ja 0xa865
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
jmp 0xa924
movsd 0x1d7c(%rip), %xmm0     # 0xc6a0
movsd %xmm0, 0x8(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x5086
movsd 0x8(%rsp), %xmm0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa95d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
movsd %xmm0, 0x8(%rsp)
callq 0x31e0
movsd 0x8(%rsp), %xmm0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28eb(%rip), %rdi      # 0xd25e
leaq 0x2850(%rip), %rsi      # 0xd1ca
leaq 0x2935(%rip), %rcx      # 0xd2b6
movl $0xbe, %edx
callq 0x3100
jmp 0xa994
movq %rax, %rbx
jmp 0xa9a1
jmp 0xa994
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x5086
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa9b8
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x31e0
movq %rbx, %rdi
callq 0x3360