// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/net.cc
// Function: recursive_test_dimensionality(int, int, int, int, std::vector<CONNECTION, std::allocator<CONNECTION>>*, 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<bool, std::allocator<bool>>*, std::vector<bool, std::allocator<bool>>*)
int recursive_test_dimensionality(int this_v, int a, int b, int c, vector<CONNECTION> *two_way_connections, vector<bool> *edge_traversed, vector<int> *vertex_visit_a, vector<int> *vertex_visit_b, vector<int> *vertex_visit_c, vector<bool> *vertex_visited, vector<bool> *is_periodic) {
  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);
    int period_a = a-old_a;
    int period_b = b-old_b;
    int period_c = c-old_c;
    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)\n", period_a, period_b, period_c);
      //update periodicity
      if(period_a!=0) is_periodic->at(0) = true;
      if(period_b!=0) is_periodic->at(1) = true;
      if(period_c!=0) is_periodic->at(2) = true;
      int dimensionality = 0;
      for(int i=0; i<3; i++) {
        if(is_periodic->at(i)) dimensionality++;
      }
      return dimensionality; //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;
  }
  //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 - if we find three-dimensionality during this run, terminate early
  int num_c = two_way_connections->size();
  int dimensionality = 0;
  for(int i=0; i<3; i++) {
    if(is_periodic->at(i)) dimensionality++;
  }
  for(int i=0; i<num_c && dimensionality<3; 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;
        dimensionality = recursive_test_dimensionality(con.v2, new_a, new_b, new_c, two_way_connections, edge_traversed, vertex_visit_a, vertex_visit_b, vertex_visit_c, vertex_visited, is_periodic);
      } 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;
        dimensionality = recursive_test_dimensionality(con.v1, new_a, new_b, new_c, two_way_connections, edge_traversed, vertex_visit_a, vertex_visit_b, vertex_visit_c, vertex_visited, is_periodic);
      }
    }
  }
  return dimensionality;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movl %ecx, %r13d
movl %edx, %ebp
movl %esi, %ebx
movq 0x88(%rsp), %r15
movq 0x70(%rsp), %r12
movl %edi, 0x2c(%rsp)
movslq %edi, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0xaba4
testq %rdx, (%rax)
movl %ebx, 0xc(%rsp)
je 0x77f22
movq %r12, %rdi
movq %r14, %rsi
callq 0xac00
movl (%rax), %r15d
movq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0xac00
movl (%rax), %r12d
movq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0xac00
movl %ebx, %ecx
movl (%rax), %ebx
movl %r15d, %eax
xorl %ecx, %eax
movl %r12d, %ecx
xorl %ebp, %ecx
orl %eax, %ecx
movl %ebx, %eax
xorl %r13d, %eax
orl %ecx, %eax
je 0x77f5f
cmpl 0xc(%rsp), %r15d
je 0x77ec3
movq 0x90(%rsp), %rdi
xorl %esi, %esi
callq 0xaba4
orq %rdx, (%rax)
cmpl %ebp, %r12d
je 0x77edb
pushq $0x1
popq %rsi
movq 0x90(%rsp), %rdi
callq 0xaba4
orq %rdx, (%rax)
cmpl %r13d, %ebx
je 0x77ef3
pushq $0x2
popq %rsi
movq 0x90(%rsp), %rdi
callq 0xaba4
orq %rdx, (%rax)
xorl %ebx, %ebx
xorl %r13d, %r13d
cmpq $0x3, %rbx
je 0x780b5
movq 0x90(%rsp), %rdi
movq %rbx, %rsi
callq 0xaba4
andq (%rax), %rdx
cmpq $0x1, %rdx
sbbl $-0x1, %r13d
incq %rbx
jmp 0x77ef8
movq %r15, %rdi
movq %r14, %rsi
callq 0xaba4
orq %rdx, (%rax)
movq %r12, %rdi
movq %r14, %rsi
callq 0xac00
movl %ebx, (%rax)
movq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0xac00
movl %ebp, (%rax)
movq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0xac00
movl %r13d, (%rax)
movl %ebp, 0x10(%rsp)
movl %r13d, 0x14(%rsp)
movq 0x18(%rsp), %r15
movq 0x8(%r15), %rax
subq (%r15), %rax
pushq $0x1c
popq %rcx
cqto
idivq %rcx
movq %rax, %rbx
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpq $0x3, %r14
je 0x77fab
movq 0x90(%rsp), %rdi
movq %r14, %rsi
callq 0xaba4
andq (%rax), %rdx
cmpq $0x1, %rdx
sbbl $-0x1, %r13d
incq %r14
jmp 0x77f85
movslq %ebx, %rax
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
cmpq 0x30(%rsp), %r14
jge 0x780b5
cmpl $0x2, %r13d
jg 0x780b5
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0xaba4
testq %rdx, (%rax)
jne 0x780a8
movq %r15, %rdi
movq %r14, %rsi
callq 0x4b9ca
movl (%rax), %r15d
movl 0x4(%rax), %edx
movl 0x10(%rax), %r12d
movl 0x14(%rax), %ebx
movl 0x18(%rax), %ebp
movl 0x2c(%rsp), %eax
cmpl %eax, %r15d
jne 0x78040
movq 0x20(%rsp), %r15
movl %edx, %r13d
movq %r15, %rdi
movq %r14, %rsi
callq 0xaba4
orq %rdx, (%rax)
addl 0xc(%rsp), %r12d
addl 0x10(%rsp), %ebx
addl 0x14(%rsp), %ebp
subq $0x8, %rsp
movl %r13d, %edi
movl %r12d, %esi
movl %ebx, %edx
movl %ebp, %ecx
movq 0x20(%rsp), %r8
movq %r15, %r9
jmp 0x78079
cmpl %eax, %edx
jne 0x780a8
movq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0xaba4
orq %rdx, (%rax)
movl 0xc(%rsp), %esi
subl %r12d, %esi
movl 0x10(%rsp), %edx
subl %ebx, %edx
movl 0x14(%rsp), %ecx
subl %ebp, %ecx
subq $0x8, %rsp
movl %r15d, %edi
movq 0x20(%rsp), %r8
movq %r13, %r9
pushq 0x98(%rsp)
pushq 0x98(%rsp)
pushq 0x98(%rsp)
pushq 0x98(%rsp)
pushq 0x98(%rsp)
callq 0x77e14
addq $0x30, %rsp
movl %eax, %r13d
incq %r14
movq 0x18(%rsp), %r15
jmp 0x77fb6
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq