// File: /workspace/github_cpp_makefile_star2_O1/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, 0x28(%rsp)
cmpq %r14, %rbx
je 0x8505
leaq 0x108(%rsp), %r14
leaq 0xf8(%rbx), %rsi
movq %r14, %rdi
callq 0x9ee2
incl (%rax)
movq (%rbx), %rbx
cmpq 0x28(%rsp), %rbx
jne 0x84ea
movq %r15, 0x80(%rsp)
movq 0x28(%rsp), %rax
movq (%rax), %rbx
cmpq %rax, %rbx
je 0x858c
leaq 0x108(%rsp), %r14
leaq 0x30(%rsp), %r15
leaq 0x8(%rsp), %r13
leaq 0xf8(%rbx), %rsi
movq %r14, %rdi
callq 0x9ee2
cmpl $0x1, (%rax)
jne 0x8582
leaq 0x20(%rbx), %rax
movups 0x10(%rbx), %xmm0
movups %xmm0, 0x8(%rsp)
movq %rax, 0x18(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x8577
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rsi)
movups 0x8(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x18, 0x38(%rsp)
jmp 0x8582
movq %r15, %rdi
movq %r13, %rdx
callq 0xd55c
movq (%rbx), %rbx
cmpq 0x28(%rsp), %rbx
jne 0x852c
movq %r12, 0x78(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rbx
cmpq 0x8(%rax), %rbx
je 0x868d
leaq 0xd8(%rsp), %r13
leaq 0x108(%rsp), %rbp
leaq 0x8(%rsp), %r14
movl $0xf8, %r12d
movq %r13, %rdi
callq 0xd67a
movq %rbx, 0x50(%rsp)
imulq $0xb8, (%rbx), %rax
movq 0x28(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx,%rax), %rbx
movq 0x8(%rcx,%rax), %r15
cmpq %r15, %rbx
je 0x85fe
movq 0x8(%rbx), %rsi
addq %r12, %rsi
movq %r13, %rdi
callq 0xd6a8
addq $0x10, %rbx
jmp 0x85e4
movq 0xf0(%rsp), %r15
leaq 0xe0(%rsp), %rax
cmpq %rax, %r15
je 0x8675
xorl %ebx, %ebx
movl 0x20(%r15), %eax
movl %eax, 0x8(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x9ee2
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 0x8615
cmpl $0x2, %ebx
jb 0x8675
movq 0x50(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x8(%rsp)
leaq 0xa8(%rsp), %rdi
movq %r14, %rsi
callq 0x9f46
movq %rax, %rdi
movq %r13, %rsi
callq 0xa280
movq 0x50(%rsp), %rbx
addq $0x8, %rbx
movq 0x48(%rsp), %rax
cmpq 0x8(%rax), %rbx
jne 0x85be
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x80(%rsp), %r13
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0xabc6
movq 0x28(%rsp), %rbx
leaq 0x13a03(%rip), %rsi     # 0x1c0c2
leaq 0x8(%rsp), %rdi
callq 0x75c0
movq 0x78(%rsp), %r12
leaq 0x138(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x11, %edx
callq 0x7170
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x86fc
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x7300
movq (%r12), %rsi
movq 0x8(%r12), %rdx
leaq 0x138(%rsp), %rdi
callq 0x7350
movq %rax, %r14
leaq 0x1397a(%rip), %rsi     # 0x1c096
movl $0x1, %edx
movq %rax, %rdi
callq 0x7350
movq 0x130(%rsp), %rsi
movq %r14, %rdi
callq 0x7230
movq %rax, %r14
leaq 0x13953(%rip), %rsi     # 0x1c096
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 0xabc6
leaq 0x138af(%rip), %rsi     # 0x1c06b
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 0x880a
movq %rdx, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
jmp 0x8812
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 0x1389c(%rip), %rsi     # 0x1c0d4
callq 0x75c0
movq %r15, 0x8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8860
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x8867
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x8(%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 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x88ac
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x7300
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x88c9
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x7300
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x88e0
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x7300
leaq 0x137f9(%rip), %rsi     # 0x1c0e0
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 0x8a6d
leaq 0x149b3(%rip), %r15     # 0x1d300
leaq 0x138(%rsp), %r12
leaq 0x1373a(%rip), %r13     # 0x1c096
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 0x895c
leaq 0x138(%rsp), %rdi
callq 0x7430
leaq 0xa8(%rsp), %rdi
callq 0xa544
leaq 0xd8(%rsp), %rdi
callq 0xa59c
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8aab
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x7300
movq 0x214ce(%rip), %rax     # 0x29f80
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 0xa5b0
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x8b21
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x7300
jmp 0x8b21
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x8b45
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x7300
jmp 0x8b45
jmp 0x8b42
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x8b8e
movq 0x68(%rsp), %rsi
jmp 0x8b6c
jmp 0x8b8b
jmp 0x8b5a
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x8b8e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x7300
jmp 0x8b8e
jmp 0x8b8b
movq %rax, %rbx
jmp 0x8bcc
jmp 0x8b8b
jmp 0x8b8b
jmp 0x8b8b
jmp 0x8b8b
jmp 0x8b8b
jmp 0x8b8b
jmp 0x8b8b
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0xa544
leaq 0xd8(%rsp), %rdi
callq 0xa59c
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8bbf
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x7300
leaq 0x138(%rsp), %rdi
callq 0x7450
leaq 0x108(%rsp), %rdi
callq 0xa5b0
movq %rbx, %rdi
callq 0x7550