// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/networkanalysis.cc
// Function: TRAVERSAL_NETWORK::TRAVERSAL_NETWORK(int, int, int, DIJKSTRA_NETWORK*)
TRAVERSAL_NETWORK::TRAVERSAL_NETWORK(int dx, int dy, int dz, DIJKSTRA_NETWORK * dnetwork){
  direction = DELTA_POS(dx,dy,dz);
  sourceNodeIDs = vector<int> ();
  regConnections = vector< vector<CONN> > ();
  connectToSource = vector< vector<CONN> > ();
  connectToSink = vector< vector<CONN> > ();
  dnet = dnetwork;
    
  map<int,bool> sourceIDs;
  
  // Iterate over all nodes
  for(unsigned int i = 0; i < dnet->nodes.size(); i++){
    DIJKSTRA_NODE currentNode = dnet->nodes.at(i);
    vector<CONN> regConns = vector <CONN> ();
    vector<CONN> srcConns = vector <CONN> ();
    vector<CONN> drainConns = vector<CONN> ();
    
    // Iterate over all connections
    for(unsigned int j = 0; j < currentNode.connections.size(); j++){
      CONN currentConn = currentNode.connections.at(j);
      DELTA_POS component = currentConn.deltaPos*direction;
      
      int directionComp;
      int otherComp;
      
      if(!component.isZero()){
	if(direction.x != 0){
	  directionComp = direction.x;
	  otherComp = component.x;
	}
	else if (direction.y != 0){
	  directionComp = direction.y;
	  otherComp = component.y;
	}
	else if (direction.z != 0){
	  directionComp = direction.z;
	  otherComp = component.z;
	}
	else{
	  cerr << "Invalid argument reached when building TRAVERSAL_NETWORK. Please contact the source code provider with your input" 
	       << "\n" << "Exiting..." << "\n";
	  exit(1);
	}
	
	if(directionComp == otherComp){
	  //Connection is a drain connection and receiver is a drain node
	  drainConns.push_back(currentConn);
	}
	else if (directionComp == -1*otherComp){
	  //Connection is source connection and receiver is a source node
	  srcConns.push_back(currentConn);
	  sourceIDs.insert(pair<int,bool> (currentConn.to,true));
	}
	else{
	  // There's a problem with the logic
	  cerr << "Invalid argument reached when building TRAVERSAL_NETWORK. Please contact the source code provider with your input" 
	       << "\n" << "Exiting..." << "\n";
	  exit(1);
	}
      }
      else{
	// Connection is a drain connection
	regConns.push_back(currentConn);
      }
    }      
    
    // Store connections according to type
      regConnections.push_back(regConns);
      connectToSource.push_back(srcConns);
      connectToSink.push_back(drainConns);
  }
  
  //Copy from map to id list to prevent duplicate id's
  map<int,bool>::iterator iter = sourceIDs.begin();
  while(iter != sourceIDs.end()){
    sourceNodeIDs.push_back(iter->first);
    iter++;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %r8, %r14
movl %ecx, %ebp
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, %rbx
leaq 0x18(%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x30(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x48(%rdi), %rax
movq %rax, 0x8(%rsp)
leaq 0x60(%rdi), %r13
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rdi)
movups %xmm0, 0x40(%rdi)
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x506b0
leaq 0xc0(%rsp), %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %ebp, %ecx
callq 0x506b0
movl 0xc8(%rsp), %eax
movl %eax, 0x8(%r13)
movq 0xc0(%rsp), %rax
movq %rax, (%r13)
movq (%rbx), %rdi
movq 0x10(%rbx), %rsi
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
testq %rdi, %rdi
je 0x317d2
subq %rdi, %rsi
callq 0x4470
movq 0x28(%rbx), %rax
movups 0x18(%rbx), %xmm0
xorl %ebp, %ebp
movq 0x18(%rsp), %rcx
movq %rbp, 0x10(%rcx)
xorps %xmm1, %xmm1
movups %xmm1, (%rcx)
leaq 0xc0(%rsp), %r15
movaps %xmm0, (%r15)
movq %rax, 0x10(%r15)
leaq 0x110(%rsp), %r12
movaps %xmm1, (%r12)
movq %rbp, 0x10(%r12)
movq %r15, %rdi
callq 0xf162
movq %r12, %rdi
callq 0xf162
movq 0x40(%rbx), %rax
movups 0x30(%rbx), %xmm0
movq 0x10(%rsp), %rcx
movq %rbp, 0x10(%rcx)
xorps %xmm1, %xmm1
movups %xmm1, (%rcx)
movaps %xmm0, (%r15)
movq %rax, 0x10(%r15)
movaps %xmm1, (%r12)
movq %rbp, 0x10(%r12)
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
callq 0xf162
leaq 0x110(%rsp), %r12
movq %r12, %rdi
callq 0xf162
movq 0x58(%rbx), %rax
movups 0x48(%rbx), %xmm0
movq 0x8(%rsp), %rcx
movq %rbp, 0x10(%rcx)
xorps %xmm1, %xmm1
movups %xmm1, (%rcx)
movaps %xmm0, (%r15)
movq %rax, 0x10(%r15)
movaps %xmm1, (%r12)
movq %rbp, 0x10(%r12)
leaq 0xc0(%rsp), %rdi
callq 0xf162
leaq 0x110(%rsp), %rdi
callq 0xf162
movq %rbx, (%rsp)
movq %r14, 0x70(%rbx)
leaq 0x118(%rsp), %rax
movl $0x0, (%rax)
movq %rbp, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rbp, 0x20(%rax)
movq (%r14), %rbx
movq 0x8(%r14), %rdx
cmpq %rbx, %rdx
je 0x31c8b
leaq 0xe0(%rsp), %rdi
leaq 0xa8(%rsp), %r14
movabsq $-0x71c71c71c71c71c7, %rbp # imm = 0x8E38E38E38E38E39
xorl %esi, %esi
xorl %r15d, %r15d
movq %r15, 0x108(%rsp)
subq %rbx, %rdx
sarq $0x3, %rdx
imulq %rbp, %rdx
cmpq %rsi, %rdx
jbe 0x31d6c
movq %r14, %r15
movq %rbp, %r12
leaq (%rsi,%rsi,8), %r14
leaq (%rbx,%r14,8), %rsi
addq $0x20, %rsi
movups -0x20(%rsi), %xmm0
movups -0x10(%rsi), %xmm1
movaps %xmm1, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movq %rdi, %rbp
callq 0x37e9e
leaq (%rbx,%r14,8), %rax
movb 0x40(%rax), %cl
movb %cl, 0x20(%rbp)
movq 0x38(%rax), %rax
movq %rax, 0x18(%rbp)
xorl %eax, %eax
movq %rax, 0x80(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movq %rax, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq %rax, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq 0xe0(%rsp), %rax
cmpq %rax, 0xe8(%rsp)
movq %r15, %r14
movq %r12, %rbp
leaq 0x70(%rsp), %r15
leaq 0x50(%rsp), %r12
je 0x31b77
movl $0x1, %ebx
xorl %ecx, %ecx
leaq (%rcx,%rcx,4), %rcx
movq 0x20(%rax,%rcx,8), %rdx
movq %rdx, 0xb0(%rsp)
movups (%rax,%rcx,8), %xmm0
movups 0x10(%rax,%rcx,8), %xmm1
movaps %xmm1, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x506ec
movq %rax, 0x20(%rsp)
movl %edx, 0x28(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x5075e
testb %al, %al
je 0x31a3d
movq 0x78(%rsp), %rsi
cmpq 0x80(%rsp), %rsi
je 0x31a4b
movq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsi)
movaps 0x90(%rsp), %xmm0
movaps 0xa0(%rsp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x28, %rsi
movq %rsi, 0x78(%rsp)
jmp 0x31b45
movl (%r13), %eax
testl %eax, %eax
je 0x31a53
movl 0x20(%rsp), %ecx
jmp 0x31a73
movq %r15, %rdi
jmp 0x31afb
movq (%rsp), %rcx
movl 0x64(%rcx), %eax
testl %eax, %eax
je 0x31a64
movl 0x24(%rsp), %ecx
jmp 0x31a73
movl 0x68(%rcx), %eax
testl %eax, %eax
je 0x31d07
movl 0x28(%rsp), %ecx
cmpl %ecx, %eax
jne 0x31ab4
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x31af6
movq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsi)
movaps 0x90(%rsp), %xmm0
movaps 0xa0(%rsp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x28, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x31b45
addl %ecx, %eax
jne 0x31caa
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x31b0a
movq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsi)
movaps 0x90(%rsp), %xmm0
movaps 0xa0(%rsp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x28, %rsi
movq %rsi, 0x58(%rsp)
jmp 0x31b1a
leaq 0x30(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x392d4
jmp 0x31b45
movq %r12, %rdi
leaq 0x90(%rsp), %rdx
callq 0x392d4
movl 0x94(%rsp), %eax
movl %eax, 0xb8(%rsp)
movb $0x1, 0xbc(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x39400
movl %ebx, %ecx
movq 0xe0(%rsp), %rax
movq 0xe8(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rsi, %rdx
incl %ebx
cmpq %rcx, %rdx
ja 0x319b1
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x37e72
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x37e72
movq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x37e72
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
movq (%rsp), %rbx
je 0x31bbb
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x31bd2
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x31bec
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
movq 0x108(%rsp), %r15
je 0x31c11
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
incl %r15d
movq 0x70(%rbx), %rax
movq (%rax), %rbx
movq 0x8(%rax), %rdx
movq %rdx, %rax
subq %rbx, %rax
sarq $0x3, %rax
imulq %rbp, %rax
movq %r15, %rsi
cmpq %r15, %rax
leaq 0xe0(%rsp), %rdi
ja 0x318fe
movq 0x128(%rsp), %r14
leaq 0x118(%rsp), %rbx
cmpq %rbx, %r14
je 0x31c8b
leaq 0x20(%r14), %rdx
movq (%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x31c76
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x31c7b
callq 0xf864
movq %r14, %rdi
callq 0x42d0
movq %rax, %r14
cmpq %rbx, %rax
jne 0x31c56
leaq 0x110(%rsp), %rdi
callq 0x38ad6
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x16333f(%rip), %rdi    # 0x194ff0
leaq 0x11f6e3(%rip), %rsi    # 0x15139b
movl $0x71, %edx
callq 0x44e0
movq 0x163327(%rip), %rdi    # 0x194ff0
leaq 0x12194e(%rip), %rsi    # 0x15361e
movl $0x1, %edx
callq 0x44e0
movq 0x16330f(%rip), %rdi    # 0x194ff0
leaq 0x1229e2(%rip), %rsi    # 0x1546ca
movl $0xa, %edx
callq 0x44e0
movq 0x1632f7(%rip), %rdi    # 0x194ff0
leaq 0x12191e(%rip), %rsi    # 0x15361e
callq 0x4440
jmp 0x31d62
movq 0x1632e2(%rip), %rdi    # 0x194ff0
leaq 0x11f686(%rip), %rsi    # 0x15139b
movl $0x71, %edx
callq 0x44e0
movq 0x1632ca(%rip), %rdi    # 0x194ff0
leaq 0x1218f1(%rip), %rsi    # 0x15361e
movl $0x1, %edx
callq 0x44e0
movq 0x1632b2(%rip), %rdi    # 0x194ff0
leaq 0x122985(%rip), %rsi    # 0x1546ca
movl $0xa, %edx
callq 0x44e0
movq 0x16329a(%rip), %rdi    # 0x194ff0
leaq 0x1218c1(%rip), %rsi    # 0x15361e
callq 0x4440
movl $0x1, %edi
callq 0x72bc
leaq 0x11b982(%rip), %rdi    # 0x14d6f5
xorl %eax, %eax
callq 0x4630
jmp 0x31d7c
movq %rax, %r14
jmp 0x31e12
jmp 0x31d88
jmp 0x31d88
movq %rax, %r14
movq (%rsp), %rbx
jmp 0x31e05
jmp 0x31d99
jmp 0x31d99
jmp 0x31d99
jmp 0x31d99
movq %rax, %r14
movq (%rsp), %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x31db7
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x31dce
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x31de8
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x31e05
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x110(%rsp), %rdi
callq 0x38ad6
movq 0x8(%rsp), %rdi
callq 0xf162
movq 0x10(%rsp), %rdi
callq 0xf162
movq 0x18(%rsp), %rdi
callq 0xf162
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x31e44
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x4470
movq %r14, %rdi
callq 0x4780