// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/net.cc
// Function: recursive_find_loops(int, int, int, int, XYZ, std::vector<CONNECTION, std::allocator<CONNECTION>>*, std::vector<MOLECULE, std::allocator<MOLECULE>>*, std::vector<bool, std::allocator<bool>>*, std::vector<int, std::allocator<int>>*, std::vector<int, std::allocator<int>>*, std::vector<int, std::allocator<int>>*, std::vector<XYZ, std::allocator<XYZ>>*, std::vector<bool, std::allocator<bool>>*, std::vector<int, std::allocator<int>>*, std::vector<int, std::allocator<int>>*, std::vector<int, std::allocator<int>>*, std::vector<XYZ, std::allocator<XYZ>>*, std::vector<int, std::allocator<int>>*, std::vector<XYZ, std::allocator<XYZ>>*, int)
bool recursive_find_loops(int this_v, int a, int b, int c, XYZ xyz, vector<CONNECTION> *two_way_connections, vector<MOLECULE> *assembled_molecules, vector<bool> *edge_traversed, vector<int> *vertex_visit_a, vector<int> *vertex_visit_b, vector<int> *vertex_visit_c, vector<XYZ> *vertex_visit_xyz, vector<bool> *vertex_visited, vector<int> *loops_a, vector<int> *loops_b, vector<int> *loops_c, vector<XYZ> *loops_xyz, vector<int> *unit_cell_vector_IDs, vector<XYZ> *unit_cell_vectors, int dimensionality) {
  bool verbose = false;
  //visit this vertex
  if(vertex_visited->at(this_v)) {
    //previously visited this vertex - have we made a loop?
    int old_a = vertex_visit_a->at(this_v);
    int old_b = vertex_visit_b->at(this_v);
    int old_c = vertex_visit_c->at(this_v);
    XYZ old_xyz = vertex_visit_xyz->at(this_v);
    int period_a = a-old_a;
    int period_b = b-old_b;
    int period_c = c-old_c;
    XYZ period_xyz = xyz-old_xyz;
    if(period_a!=0 || period_b!=0 || period_c!=0) { //it's a loop!
if(verbose) printf("DEBUG: a loop was found with periodicity (%d %d %d) and shift %.3f %.3f %.3f\n", period_a, period_b, period_c, period_xyz.x, period_xyz.y, period_xyz.z);
      bool found_all_uc_vectors = false;
      //is this new loop unique?
      if(loop_is_unique(period_a, period_b, period_c, loops_a, loops_b, loops_c)) {
if(verbose) printf("DEBUG: new loop is unique, testing for unit cell vector assignment ... \n");
        //does this new loop allow us to define a unit cell vector?
        found_all_uc_vectors = try_unit_cell_vector_assign(period_a, period_b, period_c, period_xyz, loops_a, loops_b, loops_c, loops_xyz, unit_cell_vector_IDs, unit_cell_vectors, dimensionality);
        //push loop
if(verbose) printf("DEBUG: ... pushing the new loop\n");
        loops_a->push_back(period_a);
        loops_b->push_back(period_b);
        loops_c->push_back(period_c);
        loops_xyz->push_back(period_xyz);
      } else {
if(verbose) printf("DEBUG: new loop is a duplicate\n");
      }
      return found_all_uc_vectors; //quit the recursive method here - we have a loop, time to try and find some other loops
    } else {
      //else do nothing - it's not a loop, so just proceed with journey from this vertex
    }
  } else {
    //haven't previously visited this vertex; visit it
    vertex_visited->at(this_v) = true;
    vertex_visit_a->at(this_v) = a;
    vertex_visit_b->at(this_v) = b;
    vertex_visit_c->at(this_v) = c;
    vertex_visit_xyz->at(this_v) = xyz;
  }
  //at this point, we have either completed a loop, or visited a vertex that did not complete a loop; only if a loop was found do we quit out - else proceed to recursively traverse other connections
  bool found_all_uc_vectors = false; //if we find them all during this run, terminate early
  int num_c = two_way_connections->size();
  for(int i=0; i<num_c && !found_all_uc_vectors; i++) {
    if(!edge_traversed->at(i)) {
      //only traverse new edges
      CONNECTION con = two_way_connections->at(i);
      if(con.v1==this_v) {
        //traverse this edge
        edge_traversed->at(i) = true;
        //don't visit the vertex - that will happen in next call
        int new_a = a+con.a;
        int new_b = b+con.b;
        int new_c = c+con.c;
        int a_edge_index = con.e1;
        int b_edge_index = con.e2;
        int a_vertex_index = con.v1;
        int b_vertex_index = con.v2;
        MOLECULE a_mol = assembled_molecules->at(a_vertex_index);
        int a_site_index = a_mol.permutation.at(a_edge_index);
        int a_atom_index = a_mol.sites.at(a_site_index);
        XYZ a_site = a_mol.atoms_xyz.at(a_atom_index);
        MOLECULE b_mol = assembled_molecules->at(b_vertex_index);
        int b_site_index = b_mol.permutation.at(b_edge_index);
        int b_atom_index = b_mol.sites.at(b_site_index);
        XYZ b_site = b_mol.atoms_xyz.at(b_atom_index);
        XYZ shift = b_site-a_site;
        XYZ new_xyz = xyz-shift;
        found_all_uc_vectors = recursive_find_loops(con.v2, new_a, new_b, new_c, new_xyz, two_way_connections, assembled_molecules, edge_traversed, vertex_visit_a, vertex_visit_b, vertex_visit_c, vertex_visit_xyz, vertex_visited, loops_a, loops_b, loops_c, loops_xyz, unit_cell_vector_IDs, unit_cell_vectors, dimensionality);
      } else if(con.v2==this_v) {
        //traverse this edge, pointing the other way
        edge_traversed->at(i) = true;
        //don't visit the vertex - that will happen in next call
        int new_a = a-con.a;
        int new_b = b-con.b;
        int new_c = c-con.c;
        int a_edge_index = con.e1;
        int b_edge_index = con.e2;
        int a_vertex_index = con.v1;
        int b_vertex_index = con.v2;
        MOLECULE a_mol = assembled_molecules->at(a_vertex_index);
        int a_site_index = a_mol.permutation.at(a_edge_index);
        int a_atom_index = a_mol.sites.at(a_site_index);
        XYZ a_site = a_mol.atoms_xyz.at(a_atom_index);
        MOLECULE b_mol = assembled_molecules->at(b_vertex_index);
        int b_site_index = b_mol.permutation.at(b_edge_index);
        int b_atom_index = b_mol.sites.at(b_site_index);
        XYZ b_site = b_mol.atoms_xyz.at(b_atom_index);
        XYZ shift = b_site-a_site;
        XYZ new_xyz = xyz+shift;
        found_all_uc_vectors = recursive_find_loops(con.v1, new_a, new_b, new_c, new_xyz, two_way_connections, assembled_molecules, edge_traversed, vertex_visit_a, vertex_visit_b, vertex_visit_c, vertex_visit_xyz, vertex_visited, loops_a, loops_b, loops_c, loops_xyz, unit_cell_vector_IDs, unit_cell_vectors, dimensionality);
      }
    }
  }
  return found_all_uc_vectors;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %r9, 0x90(%rsp)
movq %r8, 0xa0(%rsp)
movl %ecx, 0x80(%rsp)
movl %edx, %ebp
movl %esi, %r14d
movq 0x2f0(%rsp), %r15
movq 0x2d8(%rsp), %r13
movq 0x2d0(%rsp), %r12
movl %edi, 0xb4(%rsp)
movslq %edi, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0xaba4
testq %rdx, (%rax)
movl %ebp, 0x8c(%rsp)
movl %r14d, 0x88(%rsp)
movq %rbx, 0xb8(%rsp)
je 0x76d99
movq %r12, %rdi
movq %rbx, %rsi
callq 0xac00
movl %r14d, %ebp
movl (%rax), %r15d
movq %r13, %rdi
movq %rbx, %rsi
callq 0xac00
movl (%rax), %r12d
movq 0x2e0(%rsp), %rdi
movq %rbx, %rsi
callq 0xac00
movl (%rax), %r13d
movq 0x2e8(%rsp), %rdi
movq %rbx, %rsi
callq 0x4b6d6
movups (%rax), %xmm0
leaq 0x1d0(%rsp), %rdx
movaps %xmm0, (%rdx)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rdx)
movl 0x80(%rsp), %r14d
subl %r15d, %ebp
movl %ebp, 0xa8(%rsp)
movl %ebp, 0xe0(%rsp)
movl 0x8c(%rsp), %ebp
movl %ebp, %eax
subl %r12d, %eax
movl %eax, 0x84(%rsp)
movl %eax, 0xc0(%rsp)
movl %r14d, %ebx
subl %r13d, %ebx
movl %ebx, 0x110(%rsp)
leaq 0x128(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
callq 0x642ae
xorl 0x88(%rsp), %r15d
xorl %ebp, %r12d
orl %r15d, %r12d
xorl %r14d, %r13d
orl %r12d, %r13d
je 0x76e01
movl 0xa8(%rsp), %r14d
movl %r14d, %edi
movl 0x84(%rsp), %ebp
movl %ebp, %esi
movl %ebx, %edx
movq 0x2f8(%rsp), %r12
movq %r12, %rcx
movq 0x300(%rsp), %r15
movq %r15, %r8
movq 0x308(%rsp), %r13
movq %r13, %r9
callq 0x7736b
testb %al, %al
je 0x77308
movq %r13, %r9
movq %r15, %r8
leaq 0x128(%rsp), %r15
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movl 0x328(%rsp), %eax
movl %eax, 0x30(%rsp)
movq 0x320(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x318(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r12, %r13
movq 0x310(%rsp), %r12
movq %r12, 0x18(%rsp)
movl %r14d, %edi
movl %ebp, %esi
movl %ebx, %edx
movq %r13, %rcx
movq %r8, %rbp
movq %r9, %r14
callq 0x77656
movl %eax, %ebx
leaq 0xe0(%rsp), %rsi
movq %r13, %rdi
callq 0x9434
leaq 0xc0(%rsp), %rsi
movq %rbp, %rdi
callq 0x9434
leaq 0x110(%rsp), %rsi
movq %r14, %rdi
callq 0x9434
movq %r12, %rdi
movq %r15, %rsi
callq 0x4beaa
jmp 0x7730a
movq %r15, %rdi
movq %rbx, %rsi
callq 0xaba4
orq %rdx, (%rax)
movq %r12, %rdi
movq %rbx, %rsi
callq 0xac00
movl %r14d, (%rax)
movq %r13, %rdi
movq %rbx, %rsi
callq 0xac00
movl %ebp, (%rax)
movq 0x2e0(%rsp), %rdi
movq %rbx, %rsi
callq 0xac00
movl 0x80(%rsp), %ecx
movl %ecx, (%rax)
movq 0x2e8(%rsp), %rdi
movq %rbx, %rsi
callq 0x4b6d6
leaq 0x2b0(%rsp), %rcx
movups (%rcx), %xmm0
movups %xmm0, (%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq 0xa0(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
pushq $0x1c
popq %rcx
cqto
idivq %rcx
cltq
movq %rax, 0xa8(%rsp)
xorl %r15d, %r15d
xorl %ebx, %ebx
cmpq 0xa8(%rsp), %r15
jge 0x7730a
testb $0x1, %bl
jne 0x7730a
movq 0x2c8(%rsp), %rdi
movq %r15, %rsi
callq 0xaba4
testq %rdx, (%rax)
je 0x76e5a
xorl %ebx, %ebx
jmp 0x77300
movq 0xa0(%rsp), %rdi
movq %r15, %rsi
callq 0x4b9ca
movslq (%rax), %r13
movslq 0x4(%rax), %r14
movslq 0x8(%rax), %r12
movslq 0xc(%rax), %rbx
movl 0x10(%rax), %ebp
movl 0x14(%rax), %ecx
movl %ecx, 0x9c(%rsp)
movl 0x18(%rax), %eax
movl %eax, 0x84(%rsp)
movl 0xb4(%rsp), %eax
cmpl %eax, %r13d
jne 0x770c0
movq 0x2c8(%rsp), %rdi
movq %r15, %rsi
callq 0xaba4
orq %rdx, (%rax)
movq 0x90(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0x4b9e8
leaq 0x1d0(%rsp), %rdi
movq %rax, %rsi
callq 0x4ba0a
leaq 0x248(%rsp), %rdi
movq %r12, %rsi
callq 0xac00
movslq (%rax), %rsi
leaq 0x218(%rsp), %rdi
callq 0xac00
movq 0x2f8(%rsp), %r12
movq 0x2e8(%rsp), %r13
movslq (%rax), %rsi
leaq 0x1d0(%rsp), %rdi
callq 0x4b6d6
movq 0x10(%rax), %rcx
movq %rcx, 0xf0(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0xe0(%rsp)
movq 0x90(%rsp), %rdi
movq %r14, %rsi
callq 0x4b9e8
leaq 0x128(%rsp), %rdi
movq %rax, %rsi
callq 0x4ba0a
leaq 0x1a0(%rsp), %rdi
movq %rbx, %rsi
callq 0xac00
movslq (%rax), %rsi
leaq 0x170(%rsp), %rdi
callq 0xac00
movslq (%rax), %rsi
leaq 0x128(%rsp), %rdi
callq 0x4b6d6
movq 0x10(%rax), %rcx
movq %rcx, 0xd0(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0xc0(%rsp)
leaq 0x110(%rsp), %rbx
movq %rbx, %rdi
leaq 0xc0(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x642ae
leaq 0xf8(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
movq %rbx, %rdx
callq 0x642ae
addl 0x88(%rsp), %ebp
movl 0x9c(%rsp), %edx
addl 0x8c(%rsp), %edx
movl 0x84(%rsp), %ecx
addl 0x80(%rsp), %ecx
movq 0x108(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xf8(%rsp), %xmm0
movups %xmm0, (%rsp)
movl 0x328(%rsp), %eax
movl %eax, 0x78(%rsp)
movq 0x320(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x318(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x310(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x308(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x300(%rsp), %rax
movq %rax, 0x50(%rsp)
movq %r12, 0x48(%rsp)
movq 0x2f0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %r13, 0x38(%rsp)
movq 0x2e0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x2d8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x2d0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x2c8(%rsp), %rax
movq %rax, 0x18(%rsp)
movl %r14d, %edi
movl %ebp, %esi
movq 0xa0(%rsp), %r8
movq 0x90(%rsp), %r9
callq 0x76b69
jmp 0x772e4
cmpl %eax, %r14d
jne 0x76e53
movq 0x2c8(%rsp), %rdi
movq %r15, %rsi
callq 0xaba4
orq %rdx, (%rax)
movq 0x90(%rsp), %rdi
movq %r13, %rsi
callq 0x4b9e8
leaq 0x1d0(%rsp), %rdi
movq %rax, %rsi
callq 0x4ba0a
leaq 0x248(%rsp), %rdi
movq %r12, %rsi
callq 0xac00
movslq (%rax), %rsi
leaq 0x218(%rsp), %rdi
callq 0xac00
movslq (%rax), %rsi
leaq 0x1d0(%rsp), %rdi
callq 0x4b6d6
movq 0x2f8(%rsp), %r14
movq 0x2e0(%rsp), %r12
movq 0x10(%rax), %rcx
movq %rcx, 0xf0(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0xe0(%rsp)
movq 0x90(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0x4b9e8
leaq 0x128(%rsp), %rdi
movq %rax, %rsi
callq 0x4ba0a
leaq 0x1a0(%rsp), %rdi
movq %rbx, %rsi
callq 0xac00
movslq (%rax), %rsi
leaq 0x170(%rsp), %rdi
callq 0xac00
movslq (%rax), %rsi
leaq 0x128(%rsp), %rdi
callq 0x4b6d6
movq 0x10(%rax), %rcx
movq %rcx, 0xd0(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0xc0(%rsp)
leaq 0x110(%rsp), %rbx
movq %rbx, %rdi
leaq 0xc0(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x642ae
leaq 0xf8(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
movq %rbx, %rdx
callq 0x642d2
movl 0x88(%rsp), %esi
subl %ebp, %esi
movl 0x8c(%rsp), %edx
subl 0x9c(%rsp), %edx
movl 0x80(%rsp), %ecx
subl 0x84(%rsp), %ecx
movq 0x108(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xf8(%rsp), %xmm0
movups %xmm0, (%rsp)
movl 0x328(%rsp), %eax
movl %eax, 0x78(%rsp)
movq 0x320(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x318(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x310(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x308(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x300(%rsp), %rax
movq %rax, 0x50(%rsp)
movq %r14, 0x48(%rsp)
movq 0x2f0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x2e8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %r12, 0x30(%rsp)
movq 0x2d8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x2d0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x2c8(%rsp), %rax
movq %rax, 0x18(%rsp)
movl %r13d, %edi
movq 0xa0(%rsp), %r8
movq 0x90(%rsp), %r9
callq 0x76b69
movl %eax, %ebx
leaq 0x128(%rsp), %rdi
callq 0x4bb60
leaq 0x1d0(%rsp), %rdi
callq 0x4bb60
incq %r15
jmp 0x76e27
xorl %ebx, %ebx
andb $0x1, %bl
movl %ebx, %eax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x77341
jmp 0x77341
jmp 0x77341
jmp 0x77346
jmp 0x77346
jmp 0x77346
jmp 0x77346
jmp 0x77341
jmp 0x77341
jmp 0x77341
jmp 0x77346
jmp 0x77341
jmp 0x77346
jmp 0x77346
jmp 0x77346
jmp 0x77346
movq %rax, %rbx
jmp 0x77356
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x4bb60
leaq 0x1d0(%rsp), %rdi
callq 0x4bb60
movq %rbx, %rdi
callq 0x4780