// File: 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
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
movq %rdi, %rax
movq %rax, -0x218(%rbp)
callq 0xd0d0
movq -0x1f8(%rbp), %rdi
addq $0x18, %rdi
movq %rdi, -0x210(%rbp)
callq 0x644b0
movq -0x1f8(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x208(%rbp)
callq 0x644b0
movq -0x1f8(%rbp), %rdi
addq $0x48, %rdi
movq %rdi, -0x200(%rbp)
callq 0x644b0
movq -0x1f8(%rbp), %rdi
addq $0x60, %rdi
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x94010
jmp 0x5d663
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
leaq -0x38(%rbp), %rdi
callq 0x94010
jmp 0x5d677
movq -0x218(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, 0x60(%rax)
movl -0x30(%rbp), %ecx
movl %ecx, 0x68(%rax)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0x50(%rbp), %rdi
callq 0xd0d0
movq -0x218(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x22ed0
leaq -0x50(%rbp), %rdi
callq 0xec80
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0x68(%rbp), %rdi
callq 0x644b0
movq -0x218(%rbp), %rdi
addq $0x18, %rdi
leaq -0x68(%rbp), %rsi
callq 0x64720
leaq -0x68(%rbp), %rdi
callq 0x110b0
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0x80(%rbp), %rdi
callq 0x644b0
movq -0x218(%rbp), %rdi
addq $0x30, %rdi
leaq -0x80(%rbp), %rsi
callq 0x64720
leaq -0x80(%rbp), %rdi
callq 0x110b0
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0x98(%rbp), %rdi
callq 0x644b0
movq -0x218(%rbp), %rdi
addq $0x48, %rdi
leaq -0x98(%rbp), %rsi
callq 0x64720
leaq -0x98(%rbp), %rdi
callq 0x110b0
movq -0x218(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rcx, 0x70(%rax)
leaq -0xc8(%rbp), %rdi
callq 0x64750
movl $0x0, -0xcc(%rbp)
movq -0x218(%rbp), %rax
movl -0xcc(%rbp), %ecx
movq %rcx, -0x220(%rbp)
movq 0x70(%rax), %rdi
callq 0x10100
movq %rax, %rcx
movq -0x220(%rbp), %rax
cmpq %rcx, %rax
jae 0x5dc9a
movq -0x218(%rbp), %rax
movq 0x70(%rax), %rdi
movl -0xcc(%rbp), %eax
movl %eax, %esi
callq 0x10130
movq %rax, -0x228(%rbp)
jmp 0x5d7e2
movq -0x228(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x64400
jmp 0x5d7f7
leaq -0x130(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0x130(%rbp), %rdi
callq 0x64770
leaq -0x148(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0x148(%rbp), %rdi
callq 0x64770
leaq -0x160(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0x160(%rbp), %rdi
callq 0x64770
movl $0x0, -0x164(%rbp)
movl -0x164(%rbp), %eax
movq %rax, -0x230(%rbp)
leaq -0x118(%rbp), %rdi
addq $0x20, %rdi
callq 0x2a9e0
movq %rax, %rcx
movq -0x230(%rbp), %rax
cmpq %rcx, %rax
jae 0x5dc0b
leaq -0xf8(%rbp), %rdi
movl -0x164(%rbp), %eax
movl %eax, %esi
callq 0x64470
movq %rax, -0x238(%rbp)
jmp 0x5d8ab
movq -0x218(%rbp), %rsi
movq -0x238(%rbp), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x170(%rbp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, -0x180(%rbp)
movaps %xmm0, -0x190(%rbp)
leaq -0x178(%rbp), %rdi
addq $0x60, %rsi
callq 0x940f0
movl %edx, -0x244(%rbp)
movq %rax, -0x240(%rbp)
jmp 0x5d8f8
movl -0x244(%rbp), %eax
movq -0x240(%rbp), %rcx
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1a8(%rbp)
movl -0x1a8(%rbp), %eax
movl %eax, -0x198(%rbp)
movq -0x1b0(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x94270
movb %al, -0x245(%rbp)
jmp 0x5d940
movb -0x245(%rbp), %al
testb $0x1, %al
jne 0x5dbde
jmp 0x5d950
movq -0x218(%rbp), %rax
cmpl $0x0, 0x60(%rax)
je 0x5d9e5
movq -0x218(%rbp), %rax
movl 0x60(%rax), %eax
movl %eax, -0x1b4(%rbp)
movl -0x1a0(%rbp), %eax
movl %eax, -0x1b8(%rbp)
jmp 0x5dab5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5dd2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5dd22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x11230
leaq -0x148(%rbp), %rdi
callq 0x11230
leaq -0x130(%rbp), %rdi
callq 0x11230
leaq -0x118(%rbp), %rdi
callq 0x100e0
jmp 0x5dd22
movq -0x218(%rbp), %rax
cmpl $0x0, 0x64(%rax)
je 0x5da13
movq -0x218(%rbp), %rax
movl 0x64(%rax), %eax
movl %eax, -0x1b4(%rbp)
movl -0x19c(%rbp), %eax
movl %eax, -0x1b8(%rbp)
jmp 0x5dab3
movq -0x218(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x5da3e
movq -0x218(%rbp), %rax
movl 0x68(%rax), %eax
movl %eax, -0x1b4(%rbp)
movl -0x198(%rbp), %eax
movl %eax, -0x1b8(%rbp)
jmp 0x5dab1
movq 0x2155ab(%rip), %rdi    # 0x272ff0
leaq 0x198967(%rip), %rsi    # 0x1f63b3
callq 0x5540
movq %rax, -0x250(%rbp)
jmp 0x5da5a
movq -0x250(%rbp), %rdi
leaq 0x19bbbd(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, -0x258(%rbp)
jmp 0x5da76
movq -0x258(%rbp), %rdi
leaq 0x19d896(%rip), %rsi    # 0x1fb31a
callq 0x5540
movq %rax, -0x260(%rbp)
jmp 0x5da92
movq -0x260(%rbp), %rdi
leaq 0x19bb85(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x5daa7
movl $0x1, %edi
callq 0x67c0
jmp 0x5dab3
jmp 0x5dab5
movl -0x1b4(%rbp), %eax
cmpl -0x1b8(%rbp), %eax
jne 0x5dadd
leaq -0x160(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x64790
jmp 0x5dad8
jmp 0x5dbdc
movl -0x1b4(%rbp), %eax
imull $0xffffffff, -0x1b8(%rbp), %ecx # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x5db67
leaq -0x148(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x64790
jmp 0x5db06
leaq -0x18c(%rbp), %rsi
movb $0x1, -0x1c1(%rbp)
leaq -0x1c0(%rbp), %rdi
leaq -0x1c1(%rbp), %rdx
callq 0x64840
jmp 0x5db29
leaq -0xc8(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x64800
movb %dl, -0x269(%rbp)
movq %rax, -0x268(%rbp)
jmp 0x5db4b
movb -0x269(%rbp), %al
movq -0x268(%rbp), %rcx
movq %rcx, -0x1d8(%rbp)
movb %al, -0x1d0(%rbp)
jmp 0x5dbda
movq 0x215482(%rip), %rdi    # 0x272ff0
leaq 0x19883e(%rip), %rsi    # 0x1f63b3
callq 0x5540
movq %rax, -0x278(%rbp)
jmp 0x5db83
movq -0x278(%rbp), %rdi
leaq 0x19ba94(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, -0x280(%rbp)
jmp 0x5db9f
movq -0x280(%rbp), %rdi
leaq 0x19d76d(%rip), %rsi    # 0x1fb31a
callq 0x5540
movq %rax, -0x288(%rbp)
jmp 0x5dbbb
movq -0x288(%rbp), %rdi
leaq 0x19ba5c(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x5dbd0
movl $0x1, %edi
callq 0x67c0
jmp 0x5dbdc
jmp 0x5dbf5
leaq -0x130(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x64790
jmp 0x5dbf3
jmp 0x5dbf5
jmp 0x5dbf7
movl -0x164(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
jmp 0x5d85e
movq -0x218(%rbp), %rdi
addq $0x18, %rdi
leaq -0x130(%rbp), %rsi
callq 0x64870
jmp 0x5dc24
movq -0x218(%rbp), %rdi
addq $0x30, %rdi
leaq -0x148(%rbp), %rsi
callq 0x64870
jmp 0x5dc3d
movq -0x218(%rbp), %rdi
addq $0x48, %rdi
leaq -0x160(%rbp), %rsi
callq 0x64870
jmp 0x5dc56
leaq -0x160(%rbp), %rdi
callq 0x11230
leaq -0x148(%rbp), %rdi
callq 0x11230
leaq -0x130(%rbp), %rdi
callq 0x11230
leaq -0x118(%rbp), %rdi
callq 0x100e0
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x5d791
leaq -0xc8(%rbp), %rdi
callq 0x648e0
movq %rax, -0x1e0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x64940
movq %rax, -0x1e8(%rbp)
leaq -0x1e0(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x64910
testb $0x1, %al
jne 0x5dcd9
jmp 0x5dd0d
leaq -0x1e0(%rbp), %rdi
callq 0x64970
movq -0x218(%rbp), %rdi
movq %rax, %rsi
callq 0xd1b0
jmp 0x5dcf6
leaq -0x1e0(%rbp), %rdi
xorl %esi, %esi
callq 0x64990
movq %rax, -0x1f0(%rbp)
jmp 0x5dcad
leaq -0xc8(%rbp), %rdi
callq 0x649d0
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
leaq -0xc8(%rbp), %rdi
callq 0x649d0
movq -0x200(%rbp), %rdi
callq 0x110b0
movq -0x208(%rbp), %rdi
callq 0x110b0
movq -0x210(%rbp), %rdi
callq 0x110b0
movq -0x1f8(%rbp), %rdi
callq 0xec80
movq -0x28(%rbp), %rdi
callq 0x58f0
nopw (%rax,%rax)