// File: /workspace/github_cpp_makefile_star2_O2/kulpreet[P]lightning-network-graph-analysis/src/include/algos.hpp
// Function: lncentrality::get_centrality(boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, lncentrality::LitVertex, lncentrality::LitEdge, boost::no_property, boost::listS>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void get_centrality(LitGraph &g, string &stem, string &outdir) {
  std::ofstream out;
  std::vector<double> centrality(num_vertices(g));
  graph_traits<LitGraph>::vertex_iterator i, end;

  std::vector<centrality_s> centrality_vector(num_vertices(g));

  brandes_betweenness_centrality(
      g, centrality_map(make_iterator_property_map(
                            centrality.begin(), get(vertex_index, g), double()))
             .vertex_index_map(get(vertex_index, g)));

  relative_betweenness_centrality(
      g, make_iterator_property_map(centrality.begin(), get(vertex_index, g),
                                    double()));

  for (boost::tie(i, end) = vertices(g); i != end; ++i) {
    centrality_s c = {g[*i].name, g[*i].pub_key, centrality[*i]};
    centrality_vector.push_back(c);
    // std::cout << g[*i].name << " :: "
    //           << g[*i].pub_key << " :: "
    //           << centrality[*i] << endl;
  }

  // sort centrality vector
  std::sort(centrality_vector.begin(), centrality_vector.end(),
            compare_by_centrality<centrality_s>());

  out.open(outdir + "/" + stem + ".centrality.csv",
           std::fstream::out | std::fstream::trunc);

  out << "alias,centrality,pub_key" << std::endl;
  for (std::vector<centrality_s>::iterator centrality_iter =
           centrality_vector.begin();
       centrality_iter != centrality_vector.begin() + 50; centrality_iter++) {
    out << "\"" << centrality_iter->name << "\""
        << "," << centrality_iter->centrality << "," << centrality_iter->pub_key
        << std::endl;
  }
  out.close();

  double dominance = central_point_dominance(
      g, make_iterator_property_map(centrality.begin(), get(vertex_index, g),
                                    double()));
  out.open(outdir + "/cpd.csv", std::fstream::out | std::fstream::app);
  out << stem << "," << dominance << std::endl;
  out.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rdx, 0x8(%rsp)
movq %rsi, %r14
movq %rdi, %r15
leaq 0xd8(%rsp), %rdi
callq 0x7500
movq 0x20(%r15), %rax
subq 0x18(%r15), %rax
movl $0xb8, %ebx
cqto
idivq %rbx
leaq 0x28(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq %rax, %rsi
callq 0x8ec8
movq 0x20(%r15), %rax
subq 0x18(%r15), %rax
cqto
idivq %rbx
leaq 0x10(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq %rax, %rsi
callq 0x8f1a
movq 0x28(%rsp), %rax
leaq 0x50(%rsp), %rsi
movq %rax, 0x8(%rsi)
movq %r15, %rdi
callq 0x8f6b
movq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x8f7f
movq %r14, 0x48(%rsp)
movq 0x20(%r15), %rax
subq 0x18(%r15), %rax
movl $0xb8, %ecx
cqto
idivq %rcx
movq %rax, %rbx
pushq $0x38
popq %r14
xorl %r12d, %r12d
leaq 0x50(%rsp), %r13
leaq 0x10(%rsp), %rbp
cmpq %r12, %rbx
je 0x79a0
movq 0x18(%r15), %rax
leaq (%rax,%r14), %rsi
addq $0x20, %rsi
movq %r13, %rdi
callq 0x73f0
movq 0x18(%r15), %rsi
addq %r14, %rsi
leaq 0x70(%rsp), %rdi
callq 0x73f0
movq 0x28(%rsp), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0x90(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x8fe6
movq %r13, %rdi
callq 0x9012
incq %r12
addq $0xb8, %r14
jmp 0x7943
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xb4bb
movq 0x48(%rsp), %r14
leaq 0x116e0(%rip), %rdx     # 0x1909b
leaq 0x98(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x9066
leaq 0xb8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
movq %r14, %rdx
callq 0x9047
leaq 0x116b1(%rip), %rdx     # 0x1909d
leaq 0x50(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x9028
leaq 0xd8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
pushq $0x30
popq %rdx
callq 0x7190
leaq 0x50(%rsp), %rdi
callq 0x7180
leaq 0xb8(%rsp), %rdi
callq 0x7180
leaq 0x98(%rsp), %rdi
callq 0x7180
leaq 0x1166f(%rip), %rsi     # 0x190ad
leaq 0xd8(%rsp), %rdi
callq 0x72e0
movq %rax, %rdi
callq 0x71a0
movq 0x10(%rsp), %rax
leaq 0x129b9(%rip), %r12     # 0x1a418
leaq 0xd8(%rsp), %r13
leaq 0x11658(%rip), %rbp     # 0x190c6
movq %rax, %rbx
addq $0xe10, %rax            # imm = 0xE10
cmpq %rax, %rbx
je 0x7ae2
movq %r13, %rdi
movq %r12, %rsi
callq 0x72e0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x72c0
movq %rax, %rdi
movq %r12, %rsi
callq 0x72e0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x72e0
movsd 0x40(%rbx), %xmm0
movq %rax, %rdi
callq 0x74a0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x72e0
addq $0x20, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x72c0
movq %rax, %rdi
callq 0x71a0
movq 0x10(%rsp), %rax
addq $0x28, %rbx
jmp 0x7a71
leaq 0xd8(%rsp), %rdi
callq 0x7430
movq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x909e
movsd %xmm0, 0x40(%rsp)
leaq 0x115bf(%rip), %rdx     # 0x190c8
leaq 0x50(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x9066
leaq 0xd8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
pushq $0x11
popq %rdx
callq 0x7190
leaq 0x50(%rsp), %rdi
callq 0x7180
leaq 0xd8(%rsp), %rdi
movq %r14, %rsi
callq 0x72c0
leaq 0x11578(%rip), %rsi     # 0x190c6
movq %rax, %rdi
callq 0x72e0
movq %rax, %rdi
movsd 0x40(%rsp), %xmm0
callq 0x74a0
movq %rax, %rdi
callq 0x71a0
leaq 0xd8(%rsp), %rdi
callq 0x7430
leaq 0x10(%rsp), %rdi
callq 0x9114
leaq 0x28(%rsp), %rdi
callq 0x9ef8
leaq 0xd8(%rsp), %rdi
callq 0x7450
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7bf2
jmp 0x7c10
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x7180
jmp 0x7bc2
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x7180
jmp 0x7bd4
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x7bfa
jmp 0x7c10
jmp 0x7c10
movq %rax, %rbx
jmp 0x7c1d
movq %rax, %rbx
jmp 0x7c27
jmp 0x7c10
jmp 0x7c10
jmp 0x7c10
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x7180
jmp 0x7c13
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x9012
jmp 0x7c13
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x9114
leaq 0x28(%rsp), %rdi
callq 0x9ef8
leaq 0xd8(%rsp), %rdi
callq 0x7450
movq %rbx, %rdi
callq 0x7550