// File: 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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x180, %rsp            # imm = 0x180
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movl %edi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movl %edx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movb $0x0, -0x39(%rbp)
movq 0x28(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0xfff0
movq %rax, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x101a0
testb $0x1, %al
jne 0x113d71
jmp 0x113f05
movq 0x10(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x101d0
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movq 0x18(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x101d0
movl (%rax), %eax
movl %eax, -0x58(%rbp)
movq 0x20(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x101d0
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
movl -0x1c(%rbp), %eax
subl -0x54(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x20(%rbp), %eax
subl -0x58(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x24(%rbp), %eax
subl -0x5c(%rbp), %eax
movl %eax, -0x68(%rbp)
cmpl $0x0, -0x60(%rbp)
jne 0x113dd8
cmpl $0x0, -0x64(%rbp)
jne 0x113dd8
cmpl $0x0, -0x68(%rbp)
je 0x113efe
testb $0x1, -0x39(%rbp)
je 0x113df5
movl -0x60(%rbp), %esi
movl -0x64(%rbp), %edx
movl -0x68(%rbp), %ecx
leaq 0xe9721(%rip), %rdi     # 0x1fd50f
movb $0x0, %al
callq 0x5070
cmpl $0x0, -0x60(%rbp)
je 0x113e1e
movq 0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xfff0
movq %rax, -0x78(%rbp)
movq %rdx, -0x70(%rbp)
leaq -0x78(%rbp), %rdi
movl $0x1, %esi
callq 0x10040
cmpl $0x0, -0x64(%rbp)
je 0x113e4e
movq 0x30(%rbp), %rdi
movl $0x1, %esi
callq 0xfff0
movq %rax, -0x88(%rbp)
movq %rdx, -0x80(%rbp)
leaq -0x88(%rbp), %rdi
movl $0x1, %esi
callq 0x10040
cmpl $0x0, -0x68(%rbp)
je 0x113e81
movq 0x30(%rbp), %rdi
movl $0x2, %esi
callq 0xfff0
movq %rax, -0x98(%rbp)
movq %rdx, -0x90(%rbp)
leaq -0x98(%rbp), %rdi
movl $0x1, %esi
callq 0x10040
movl $0x0, -0x9c(%rbp)
movl $0x0, -0xa0(%rbp)
cmpl $0x3, -0xa0(%rbp)
jge 0x113ef0
movq 0x30(%rbp), %rdi
movslq -0xa0(%rbp), %rsi
callq 0xfff0
movq %rax, -0xb0(%rbp)
movq %rdx, -0xa8(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x101a0
testb $0x1, %al
jne 0x113ece
jmp 0x113edd
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x113edf
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x113e95
movl -0x9c(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x114262
jmp 0x113f00
jmp 0x113f8b
movq 0x28(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0xfff0
movq %rax, -0xc0(%rbp)
movq %rdx, -0xb8(%rbp)
leaq -0xc0(%rbp), %rdi
movl $0x1, %esi
callq 0x10040
movl -0x1c(%rbp), %eax
movl %eax, -0x160(%rbp)
movq 0x10(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x101d0
movl -0x160(%rbp), %ecx
movl %ecx, (%rax)
movl -0x20(%rbp), %eax
movl %eax, -0x15c(%rbp)
movq 0x18(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x101d0
movl -0x15c(%rbp), %ecx
movl %ecx, (%rax)
movl -0x24(%rbp), %eax
movl %eax, -0x158(%rbp)
movq 0x20(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x101d0
movl -0x158(%rbp), %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rdi
callq 0xaf420
movl %eax, -0xc4(%rbp)
movl $0x0, -0xc8(%rbp)
movl $0x0, -0xcc(%rbp)
cmpl $0x3, -0xcc(%rbp)
jge 0x114009
movq 0x30(%rbp), %rdi
movslq -0xcc(%rbp), %rsi
callq 0xfff0
movq %rax, -0xe0(%rbp)
movq %rdx, -0xd8(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x101a0
testb $0x1, %al
jne 0x113fe7
jmp 0x113ff6
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x113ff8
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x113fae
movl $0x0, -0xe4(%rbp)
movl -0xe4(%rbp), %ecx
xorl %eax, %eax
cmpl -0xc4(%rbp), %ecx
movb %al, -0x161(%rbp)
jge 0x114039
cmpl $0x3, -0xc8(%rbp)
setl %al
movb %al, -0x161(%rbp)
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x114048
jmp 0x114259
movq -0x38(%rbp), %rdi
movslq -0xe4(%rbp), %rsi
callq 0xfff0
movq %rax, -0xf8(%rbp)
movq %rdx, -0xf0(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x101a0
xorb $-0x1, %al
testb $0x1, %al
jne 0x11407d
jmp 0x114243
movq -0x30(%rbp), %rdi
movslq -0xe4(%rbp), %rsi
callq 0xaf0e0
movq (%rax), %rcx
movq %rcx, -0x114(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x10c(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x104(%rbp)
movl 0x18(%rax), %eax
movl %eax, -0xfc(%rbp)
movl -0x114(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x11417d
movq -0x38(%rbp), %rdi
movslq -0xe4(%rbp), %rsi
callq 0xfff0
movq %rax, -0x128(%rbp)
movq %rdx, -0x120(%rbp)
leaq -0x128(%rbp), %rdi
movl $0x1, %esi
callq 0x10040
movl -0x1c(%rbp), %eax
addl -0x104(%rbp), %eax
movl %eax, -0x12c(%rbp)
movl -0x20(%rbp), %eax
addl -0x100(%rbp), %eax
movl %eax, -0x130(%rbp)
movl -0x24(%rbp), %eax
addl -0xfc(%rbp), %eax
movl %eax, -0x134(%rbp)
movl -0x110(%rbp), %edi
movl -0x12c(%rbp), %esi
movl -0x130(%rbp), %edx
movl -0x134(%rbp), %ecx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
movq 0x10(%rbp), %r14
movq 0x18(%rbp), %rbx
movq 0x20(%rbp), %r11
movq 0x28(%rbp), %r10
movq 0x30(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x113d10
movl %eax, -0xc8(%rbp)
jmp 0x114241
movl -0x110(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x11423f
movq -0x38(%rbp), %rdi
movslq -0xe4(%rbp), %rsi
callq 0xfff0
movq %rax, -0x148(%rbp)
movq %rdx, -0x140(%rbp)
leaq -0x148(%rbp), %rdi
movl $0x1, %esi
callq 0x10040
movl -0x1c(%rbp), %eax
subl -0x104(%rbp), %eax
movl %eax, -0x14c(%rbp)
movl -0x20(%rbp), %eax
subl -0x100(%rbp), %eax
movl %eax, -0x150(%rbp)
movl -0x24(%rbp), %eax
subl -0xfc(%rbp), %eax
movl %eax, -0x154(%rbp)
movl -0x114(%rbp), %edi
movl -0x14c(%rbp), %esi
movl -0x150(%rbp), %edx
movl -0x154(%rbp), %ecx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
movq 0x10(%rbp), %r14
movq 0x18(%rbp), %rbx
movq 0x20(%rbp), %r11
movq 0x28(%rbp), %r10
movq 0x30(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x113d10
movl %eax, -0xc8(%rbp)
jmp 0x114241
jmp 0x114243
jmp 0x114245
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x114013
movl -0xc8(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
addq $0x180, %rsp            # imm = 0x180
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)