// File: /workspace/github_cpp_makefile_star2_O3/kulpreet[P]lightning-network-graph-analysis/src/include/algos.hpp
// Function: lncentrality::find_non_singleton_components(std::vector<unsigned long, std::allocator<unsigned long>>&, 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 find_non_singleton_components(std::vector<Vertex> &art_points, LitGraph &g,
                                   string &stem, string &outdir) {

  // make a map component id to component size
  std::map<int, int> component_sizes;
  std::vector<Vertex>::iterator i;
  std::ofstream out;

  graph_traits<LitGraph>::edge_iterator ei, ei_end;
  graph_traits<LitGraph>::out_edge_iterator out_i, out_end;

  typedef graph_traits<LitGraph>::edge_descriptor Edge;
  std::vector<Edge> bridges;
  std::set<int> component_ids;
  std::map<int, set<int>> interesting_art_points;
  int num_interesting;

  // find the size of components by iterating over all edges.
  for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) {
    component_sizes[g[*ei].component]++;
  }

  // iterate over all edges again and select those edges where
  // component size on both vertices are greater than 1. This and the
  // previous loop can probably be optimised.
  for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) {
    if (component_sizes[g[*ei].component] == 1) {
      bridges.push_back(*ei);
    }
  }

  // iterate over all art points
  for (i = art_points.begin(); i != art_points.end(); i++) {
    // get all the components for all the edges of the art points
    component_ids.clear();
    for (boost::tie(out_i, out_end) = out_edges(*i, g); out_i != out_end;
         ++out_i) {
      component_ids.insert(g[*out_i].component);
    }
    // find the number of components the art point is connecting
    num_interesting =
        std::accumulate(component_ids.begin(), component_ids.end(), 0,
                        [&component_sizes](int a, int cid) {
                          if (component_sizes[cid] > 5) {
                            a = a + 1;
                          }
                          return a;
                        });
    // change the min size of components to consider "interesting"
    if (num_interesting > 1) {
      interesting_art_points[*i] = component_ids;
    }
  }

  // date, #components, #interesting art points. No header output as
  // this is appended to file.
  out.open(outdir + "/key_ap_stats.csv", std::fstream::out | std::fstream::app);
  out << stem << "," << component_sizes.size() << ","
      << interesting_art_points.size() << std::endl;
  out.close();

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

  // Key Articulation Points. Header included.
  out << "alias,num components,degree,pub_key" << std::endl;
  for (std::map<int, set<int>>::iterator x = interesting_art_points.begin();
       x != interesting_art_points.end(); x++) {
    out << "\"" << g[x->first].name << "\""
        << "," << (x->second).size() << "," << degree(x->first, g) << ","
        << g[x->first].pub_key << endl;
  }
  out.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x338, %rsp            # imm = 0x338
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, 0x48(%rsp)
leaq 0x110(%rsp), %rax
movl $0x0, (%rax)
xorl %ebx, %ebx
movq %rbx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rbx, 0x20(%rax)
leaq 0x138(%rsp), %rdi
callq 0x7500
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq %rbx, 0x40(%rsp)
leaq 0xe0(%rsp), %rax
movl %ebx, (%rax)
movq %rbx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rbx, 0x20(%rax)
leaq 0xb0(%rsp), %rax
movl %ebx, (%rax)
movq %rbx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rbx, 0x20(%rax)
movq (%r14), %rbx
movq %r14, 0x8(%rsp)
cmpq %r14, %rbx
movq %r15, 0x80(%rsp)
je 0x851c
leaq 0x108(%rsp), %r14
leaq 0xf8(%rbx), %rsi
movq %r14, %rdi
callq 0x9ee0
incl (%rax)
movq (%rbx), %rbx
cmpq 0x8(%rsp), %rbx
jne 0x84f7
movq 0x8(%rsp), %rax
movq (%rax), %rbx
jmp 0x8521
movq 0x8(%rsp), %rax
cmpq %rax, %rbx
je 0x8598
leaq 0x108(%rsp), %r14
leaq 0x30(%rsp), %r15
leaq 0x10(%rsp), %r13
leaq 0xf8(%rbx), %rsi
movq %r14, %rdi
callq 0x9ee0
cmpl $0x1, (%rax)
jne 0x858e
leaq 0x20(%rbx), %rax
movups 0x10(%rbx), %xmm0
movaps %xmm0, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x8583
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsi)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x18, 0x38(%rsp)
jmp 0x858e
movq %r15, %rdi
movq %r13, %rdx
callq 0xd622
movq (%rbx), %rbx
cmpq 0x8(%rsp), %rbx
jne 0x8538
movq %r12, 0x78(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rbx
cmpq 0x8(%rax), %rbx
je 0x8699
leaq 0xd8(%rsp), %r13
leaq 0x108(%rsp), %rbp
leaq 0x10(%rsp), %r14
movl $0xf8, %r12d
movq %r13, %rdi
callq 0xd740
movq %rbx, 0x50(%rsp)
imulq $0xb8, (%rbx), %rax
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx,%rax), %rbx
movq 0x8(%rcx,%rax), %r15
cmpq %r15, %rbx
je 0x860a
movq 0x8(%rbx), %rsi
addq %r12, %rsi
movq %r13, %rdi
callq 0xd76e
addq $0x10, %rbx
jmp 0x85f0
movq 0xf0(%rsp), %r15
leaq 0xe0(%rsp), %rax
cmpq %rax, %r15
je 0x8681
xorl %ebx, %ebx
movl 0x20(%r15), %eax
movl %eax, 0x10(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x9ee0
xorl %ecx, %ecx
cmpl $0x6, (%rax)
setge %cl
addl %ecx, %ebx
movq %r15, %rdi
callq 0x7360
movq %rax, %r15
leaq 0xe0(%rsp), %rax
cmpq %rax, %r15
jne 0x8621
cmpl $0x2, %ebx
jb 0x8681
movq 0x50(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x10(%rsp)
leaq 0xa8(%rsp), %rdi
movq %r14, %rsi
callq 0x9f46
movq %rax, %rdi
movq %r13, %rsi
callq 0xa27c
movq 0x50(%rsp), %rbx
addq $0x8, %rbx
movq 0x48(%rsp), %rax
cmpq 0x8(%rax), %rbx
jne 0x85ca
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x80(%rsp), %r13
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
callq 0xabd6
movq 0x8(%rsp), %rbx
leaq 0x14a6f(%rip), %rsi     # 0x1d13a
leaq 0x10(%rsp), %rdi
callq 0x75c0
movq 0x78(%rsp), %r12
leaq 0x138(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x11, %edx
callq 0x7170
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x8708
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x7300
movq (%r12), %rsi
movq 0x8(%r12), %rdx
leaq 0x138(%rsp), %rdi
callq 0x7350
movq %rax, %r14
leaq 0x149e6(%rip), %rsi     # 0x1d10e
movl $0x1, %edx
movq %rax, %rdi
callq 0x7350
movq 0x130(%rsp), %rsi
movq %r14, %rdi
callq 0x7230
movq %rax, %r14
leaq 0x149bf(%rip), %rsi     # 0x1d10e
movl $0x1, %edx
movq %rax, %rdi
callq 0x7350
movq 0xd0(%rsp), %rsi
movq %r14, %rdi
callq 0x7230
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x72e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7240
leaq 0x138(%rsp), %rdi
callq 0x7430
leaq 0x68(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0xabd6
leaq 0x1491b(%rip), %rsi     # 0x1d0e3
leaq 0x58(%rsp), %rdi
callq 0x75c0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
leaq 0x58(%rsp), %rdi
callq 0x7100
leaq 0x98(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8816
movq %rdx, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
jmp 0x881e
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq 0x88(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x14908(%rip), %rsi     # 0x1d14c
callq 0x75c0
movq %r15, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x886c
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x8873
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x138(%rsp), %rdi
movl $0x30, %edx
callq 0x7170
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x88b8
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x7300
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x88d5
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x7300
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x88ec
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x7300
leaq 0x14865(%rip), %rsi     # 0x1d158
leaq 0x138(%rsp), %r14
movl $0x23, %edx
movq %r14, %rdi
callq 0x7350
movq 0x138(%rsp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x72e0
movsbl %al, %esi
leaq 0x138(%rsp), %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7240
movq 0xc0(%rsp), %r14
leaq 0xb0(%rsp), %rax
cmpq %rax, %r14
je 0x8a79
leaq 0x15a17(%rip), %r15     # 0x1e370
leaq 0x138(%rsp), %r12
leaq 0x147a6(%rip), %r13     # 0x1d10e
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x7350
movslq 0x20(%r14), %rax
movq 0x18(%rbx), %rcx
imulq $0xb8, %rax, %rax
movq 0x58(%rcx,%rax), %rsi
movq 0x60(%rcx,%rax), %rdx
movq %r12, %rdi
callq 0x7350
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x7350
movl $0x1, %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x7350
movq 0x50(%r14), %rsi
movq %rbp, %rdi
callq 0x7230
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7350
movslq 0x20(%r14), %rax
movq 0x18(%rbx), %rcx
imulq $0xb8, %rax, %rax
movq 0x8(%rcx,%rax), %rsi
subq (%rcx,%rax), %rsi
sarq $0x4, %rsi
movq %rbp, %rdi
callq 0x7230
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7350
movslq 0x20(%r14), %rax
movq 0x18(%rbx), %rcx
imulq $0xb8, %rax, %rax
movq 0x38(%rcx,%rax), %rsi
movq 0x40(%rcx,%rax), %rdx
movq %rbp, %rdi
callq 0x7350
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x72e0
movsbl %al, %esi
movq %rbp, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7240
movq %r14, %rdi
callq 0x7250
movq %rax, %r14
leaq 0xb0(%rsp), %rax
cmpq %rax, %r14
jne 0x8968
leaq 0x138(%rsp), %rdi
callq 0x7430
leaq 0xa8(%rsp), %rdi
callq 0xa53e
leaq 0xd8(%rsp), %rdi
callq 0xa596
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8ab7
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x7300
movq 0x224c2(%rip), %rax     # 0x2af80
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x140(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x138(%rsp,%rcx)
callq 0x72a0
leaq 0x230(%rsp), %rdi
callq 0x7110
leaq 0x108(%rsp), %rdi
callq 0xa5aa
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x8b2d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x7300
jmp 0x8b2d
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x8b51
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x7300
jmp 0x8b51
jmp 0x8b4e
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x8b9a
movq 0x68(%rsp), %rsi
jmp 0x8b78
jmp 0x8b97
jmp 0x8b66
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x8b9a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x7300
jmp 0x8b9a
jmp 0x8b97
movq %rax, %rbx
jmp 0x8bd8
jmp 0x8b97
jmp 0x8b97
jmp 0x8b97
jmp 0x8b97
jmp 0x8b97
jmp 0x8b97
jmp 0x8b97
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0xa53e
leaq 0xd8(%rsp), %rdi
callq 0xa596
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8bcb
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x7300
leaq 0x138(%rsp), %rdi
callq 0x7450
leaq 0x108(%rsp), %rdi
callq 0xa5aa
movq %rbx, %rdi
callq 0x7550