// File: /workspace/github_cpp_makefile_star2_O2/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, %r13
movl %ecx, %ebx
movl %edx, %r14d
movl %esi, %r15d
leaq 0x18(%rdi), %rax
movq %rax, 0x20(%rsp)
leaq 0x30(%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x48(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x60(%rdi), %rbp
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rdi)
movups %xmm0, 0x40(%rdi)
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movq %rdi, 0x8(%rsp)
movups %xmm0, (%rdi)
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3d328
leaq 0xa0(%rsp), %rdi
movl %r15d, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0x3d328
leaq 0xa0(%rsp), %rbx
movl 0x8(%rbx), %eax
movl %eax, 0x8(%rbp)
movq (%rbx), %rax
movq %rax, (%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xed62
movq %rbx, %rdi
callq 0xb290
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0xa0(%rsp), %rbx
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x2af3c
movq %rbx, %rdi
callq 0xaea6
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0xa0(%rsp), %rbx
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x2af3c
movq %rbx, %rdi
callq 0xaea6
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0xa0(%rsp), %rbx
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x2af3c
movq %rbx, %rdi
callq 0xaea6
movq %r13, 0x70(%r14)
leaq 0x120(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorl %esi, %esi
pushq $0x28
popq %r12
leaq 0x28(%rsp), %r14
leaq 0x80(%rsp), %rbx
leaq 0xf0(%rsp), %r15
movl %esi, %esi
movq 0x8(%r13), %rax
subq (%r13), %rax
cqto
pushq $0x48
popq %rcx
idivq %rcx
cmpq %rsi, %rax
jbe 0x26363
movq %r13, %rdi
movq %rsi, 0x78(%rsp)
callq 0xabe2
leaq 0xa0(%rsp), %rdi
movq %rax, %rsi
callq 0x29ebe
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
andq $0x0, 0x90(%rsp)
movaps %xmm0, 0x60(%rsp)
andq $0x0, 0x70(%rsp)
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
xorl %r13d, %r13d
movl %r13d, %r13d
movq 0xc8(%rsp), %rax
subq 0xc0(%rsp), %rax
cqto
idivq %r12
cmpq %r13, %rax
jbe 0x262fa
leaq 0xc0(%rsp), %rdi
movq %r13, %rsi
callq 0x29efa
movq 0x20(%rax), %rcx
movq %rcx, 0x110(%rsp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
leaq 0x108(%rsp), %rdi
movq %rbp, %rsi
callq 0x3d364
movq %rax, 0x28(%rsp)
movl %edx, 0x30(%rsp)
movq %r14, %rdi
callq 0x3d3d6
movq %rbx, %rdi
testb %al, %al
jne 0x262b1
movl (%rbp), %eax
testl %eax, %eax
je 0x26287
movl 0x28(%rsp), %ecx
jmp 0x262a8
movq 0x8(%rsp), %rcx
movl 0x64(%rcx), %eax
testl %eax, %eax
je 0x26299
movl 0x2c(%rsp), %ecx
jmp 0x262a8
movl 0x68(%rcx), %eax
testl %eax, %eax
je 0x263f4
movl 0x30(%rsp), %ecx
leaq 0x40(%rsp), %rdi
cmpl %ecx, %eax
jne 0x262bb
movq %r15, %rsi
callq 0x29ff6
jmp 0x262f2
addl %ecx, %eax
jne 0x263b2
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x29ff6
movl 0xf4(%rsp), %eax
movl %eax, 0x38(%rsp)
movb $0x1, 0x3c(%rsp)
leaq 0x118(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x2b084
incl %r13d
jmp 0x261fe
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x2a024
movq 0x18(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x2a024
movq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2a024
leaq 0x40(%rsp), %rdi
callq 0xaf14
leaq 0x60(%rsp), %rdi
callq 0xaf14
movq %rbx, %rdi
callq 0xaf14
leaq 0xc0(%rsp), %rdi
callq 0xaf14
movq 0x78(%rsp), %rsi
incl %esi
movq 0x8(%rsp), %rax
movq 0x70(%rax), %r13
jmp 0x26199
movq 0x130(%rsp), %rbx
leaq 0x120(%rsp), %rax
cmpq %rax, %rbx
movq 0x8(%rsp), %rdi
je 0x26393
leaq 0x20(%rbx), %rsi
callq 0x9434
movq %rbx, %rdi
callq 0x4300
movq %rax, %rbx
jmp 0x2636b
leaq 0x118(%rsp), %rdi
callq 0x2a734
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x129c37(%rip), %rdi    # 0x14fff0
leaq 0xd9f6b(%rip), %rsi     # 0x10032b
callq 0x4480
leaq 0xdc1b2(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0xdd247(%rip), %rsi     # 0x103622
movq %rax, %rdi
callq 0x4480
leaq 0xdc194(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
jmp 0x26434
movq 0x129bf5(%rip), %rdi    # 0x14fff0
leaq 0xd9f29(%rip), %rsi     # 0x10032b
callq 0x4480
leaq 0xdc170(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0xdd205(%rip), %rsi     # 0x103622
movq %rax, %rdi
callq 0x4480
leaq 0xdc152(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
pushq $0x1
popq %rdi
callq 0x524c
jmp 0x2643e
movq %rax, %rbx
jmp 0x26492
jmp 0x26445
movq %rax, %rbx
jmp 0x26485
jmp 0x26454
jmp 0x26454
jmp 0x26454
jmp 0x26454
jmp 0x26454
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xaf14
leaq 0x60(%rsp), %rdi
callq 0xaf14
leaq 0x80(%rsp), %rdi
callq 0xaf14
leaq 0xc0(%rsp), %rdi
callq 0xaf14
leaq 0x118(%rsp), %rdi
callq 0x2a734
movq 0x10(%rsp), %rdi
callq 0xaea6
movq 0x18(%rsp), %rdi
callq 0xaea6
movq 0x20(%rsp), %rdi
callq 0xaea6
movq 0x8(%rsp), %rdi
callq 0xb290
movq %rbx, %rdi
callq 0x4780