// File: Luthaf[P]zeopp/networkio.cc
// Function: writeToNt2(char*, VORONOI_NETWORK*, double)
bool writeToNt2(char *filename, VORONOI_NETWORK *vornet, double minRad){
  fstream output;
  output.open(filename, fstream::out);
  if(!output.is_open()){
    cerr << "Error: Failed to open .net2 output file " << filename << "\n";
    //cerr << "Exiting ..." << "\n";
    //exit(1);
    return false;
  }
  else{
    cout << "Writing Voronoi network information to " << filename << "\n";

    // Write Voronoi node information
    output << "Vertex table:" << "\n";
    vector<VOR_NODE> ::iterator niter = vornet->nodes.begin();
    int i = 0;
    while(niter != vornet->nodes.end()){
      if(niter->rad_stat_sphere > minRad){
	output << i << " " << niter-> x << " " << niter-> y << " "
	       << niter-> z << " " << niter->rad_stat_sphere;

	//Write Voronoi node/atom pairing information in i j k....z format
	output << " ";
	for(unsigned int j = 0; j < niter->atomIDs.size(); j++){
	  output << niter->atomIDs.at(j);
	  if(j < niter->atomIDs.size()-1)
	    output << " ";
	}
	output <<  "\n";
      }
      i++;
      niter++;
    }

    // Write Voronoi edge information
    output << "\n" << "Edge table:" << "\n";
    vector<VOR_EDGE> ::iterator eiter = vornet->edges.begin();
    while(eiter != vornet->edges.end()){
      if(eiter->rad_moving_sphere > minRad){
	output << eiter->from << " -> " << eiter->to << " " << eiter->rad_moving_sphere
	       << " " << eiter->delta_uc_x << " " << eiter->delta_uc_y << " "
	       << eiter->delta_uc_z << " " << eiter->length << "\n";
      }
      eiter++;
    }
  }
  output.close();
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3a0, %rsp            # imm = 0x3A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
leaq -0x230(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x5660
movq -0x288(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x10, %edx
callq 0x54b0
jmp 0x56782
leaq -0x230(%rbp), %rdi
callq 0x58b0
movb %al, -0x289(%rbp)
jmp 0x56796
movb -0x289(%rbp), %al
testb $0x1, %al
jne 0x56826
jmp 0x567a6
movq 0x21c843(%rip), %rdi    # 0x272ff0
leaq 0x19d09e(%rip), %rsi    # 0x1f3852
callq 0x5540
movq %rax, -0x298(%rbp)
jmp 0x567c2
movq -0x298(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x2a0(%rbp)
jmp 0x567db
movq -0x2a0(%rbp), %rdi
leaq 0x1a2e3c(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x567f0
movb $0x0, -0x1(%rbp)
movl $0x1, -0x240(%rbp)
jmp 0x56e21
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x5150
jmp 0x56e3b
movq 0x21c793(%rip), %rdi    # 0x272fc0
leaq 0x19d047(%rip), %rsi    # 0x1f387b
callq 0x5540
movq %rax, -0x2a8(%rbp)
jmp 0x56842
movq -0x2a8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x2b0(%rbp)
jmp 0x5685b
movq -0x2b0(%rbp), %rdi
leaq 0x1a2dbc(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x56870
leaq -0x220(%rbp), %rdi
leaq 0x19d025(%rip), %rsi    # 0x1f38a3
callq 0x5540
movq %rax, -0x2b8(%rbp)
jmp 0x5688c
movq -0x2b8(%rbp), %rdi
leaq 0x1a2d8b(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x568a1
movq -0x18(%rbp), %rdi
addq $0x48, %rdi
callq 0x25230
movq %rax, -0x248(%rbp)
movl $0x0, -0x24c(%rbp)
movq -0x18(%rbp), %rdi
addq $0x48, %rdi
callq 0x250b0
movq %rax, -0x258(%rbp)
leaq -0x248(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x599b0
testb $0x1, %al
jne 0x568ef
jmp 0x56b70
leaq -0x248(%rbp), %rdi
callq 0x599f0
movsd 0x18(%rax), %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x56b47
leaq -0x220(%rbp), %rdi
movl -0x24c(%rbp), %esi
callq 0x58d0
movq %rax, -0x2c0(%rbp)
jmp 0x56926
movq -0x2c0(%rbp), %rdi
leaq 0x1a597a(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x2c8(%rbp)
jmp 0x56942
leaq -0x248(%rbp), %rdi
callq 0x599f0
movq -0x2c8(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x5980
movq %rax, -0x2d0(%rbp)
jmp 0x56967
movq -0x2d0(%rbp), %rdi
leaq 0x1a5939(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x2d8(%rbp)
jmp 0x56983
leaq -0x248(%rbp), %rdi
callq 0x599f0
movq -0x2d8(%rbp), %rdi
movsd 0x8(%rax), %xmm0
callq 0x5980
movq %rax, -0x2e0(%rbp)
jmp 0x569a9
movq -0x2e0(%rbp), %rdi
leaq 0x1a58f7(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x2e8(%rbp)
jmp 0x569c5
leaq -0x248(%rbp), %rdi
callq 0x599f0
movq -0x2e8(%rbp), %rdi
movsd 0x10(%rax), %xmm0
callq 0x5980
movq %rax, -0x2f0(%rbp)
jmp 0x569eb
movq -0x2f0(%rbp), %rdi
leaq 0x1a58b5(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x2f8(%rbp)
jmp 0x56a07
leaq -0x248(%rbp), %rdi
callq 0x599f0
movq -0x2f8(%rbp), %rdi
movsd 0x18(%rax), %xmm0
callq 0x5980
jmp 0x56a26
leaq -0x220(%rbp), %rdi
leaq 0x1a587a(%rip), %rsi    # 0x1fc2ae
callq 0x5540
jmp 0x56a3b
movl $0x0, -0x25c(%rbp)
movl -0x25c(%rbp), %eax
movq %rax, -0x300(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x599f0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x10090
movq %rax, %rcx
movq -0x300(%rbp), %rax
cmpq %rcx, %rax
jae 0x56b30
leaq -0x220(%rbp), %rax
movq %rax, -0x310(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x599f0
movq %rax, %rdi
addq $0x20, %rdi
movl -0x25c(%rbp), %eax
movl %eax, %esi
callq 0x101d0
movq %rax, -0x308(%rbp)
jmp 0x56ab4
movq -0x310(%rbp), %rdi
movq -0x308(%rbp), %rax
movl (%rax), %esi
callq 0x58d0
jmp 0x56acb
movl -0x25c(%rbp), %eax
movq %rax, -0x318(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x599f0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x10090
movq %rax, %rcx
movq -0x318(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x56b1a
leaq -0x220(%rbp), %rdi
leaq 0x1a579d(%rip), %rsi    # 0x1fc2ae
callq 0x5540
jmp 0x56b18
jmp 0x56b1a
jmp 0x56b1c
movl -0x25c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x25c(%rbp)
jmp 0x56a45
leaq -0x220(%rbp), %rdi
leaq 0x1a2ae7(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x56b45
jmp 0x56b47
movl -0x24c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24c(%rbp)
leaq -0x248(%rbp), %rdi
xorl %esi, %esi
callq 0x59a10
movq %rax, -0x268(%rbp)
jmp 0x568bf
leaq -0x220(%rbp), %rdi
leaq 0x1a2aa7(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, -0x320(%rbp)
jmp 0x56b8c
movq -0x320(%rbp), %rdi
leaq 0x19cd17(%rip), %rsi    # 0x1f38b1
callq 0x5540
movq %rax, -0x328(%rbp)
jmp 0x56ba8
movq -0x328(%rbp), %rdi
leaq 0x1a2a6f(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x56bbd
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
callq 0x263c0
movq %rax, -0x270(%rbp)
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
callq 0x26230
movq %rax, -0x278(%rbp)
leaq -0x270(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x59a50
testb $0x1, %al
jne 0x56c01
jmp 0x56e03
leaq -0x270(%rbp), %rdi
callq 0x59a90
movsd 0x8(%rax), %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x56de9
leaq -0x220(%rbp), %rax
movq %rax, -0x338(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x59a90
movq -0x338(%rbp), %rdi
movl (%rax), %esi
callq 0x58d0
movq %rax, -0x330(%rbp)
jmp 0x56c4e
movq -0x330(%rbp), %rdi
leaq 0x19cc61(%rip), %rsi    # 0x1f38bd
callq 0x5540
movq %rax, -0x340(%rbp)
jmp 0x56c6a
leaq -0x270(%rbp), %rdi
callq 0x59a90
movq -0x340(%rbp), %rdi
movl 0x4(%rax), %esi
callq 0x58d0
movq %rax, -0x348(%rbp)
jmp 0x56c8e
movq -0x348(%rbp), %rdi
leaq 0x1a5612(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x350(%rbp)
jmp 0x56caa
leaq -0x270(%rbp), %rdi
callq 0x59a90
movq -0x350(%rbp), %rdi
movsd 0x8(%rax), %xmm0
callq 0x5980
movq %rax, -0x358(%rbp)
jmp 0x56cd0
movq -0x358(%rbp), %rdi
leaq 0x1a55d0(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x360(%rbp)
jmp 0x56cec
leaq -0x270(%rbp), %rdi
callq 0x59a90
movq -0x360(%rbp), %rdi
movl 0x10(%rax), %esi
callq 0x58d0
movq %rax, -0x368(%rbp)
jmp 0x56d10
movq -0x368(%rbp), %rdi
leaq 0x1a5590(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x370(%rbp)
jmp 0x56d2c
leaq -0x270(%rbp), %rdi
callq 0x59a90
movq -0x370(%rbp), %rdi
movl 0x14(%rax), %esi
callq 0x58d0
movq %rax, -0x378(%rbp)
jmp 0x56d50
movq -0x378(%rbp), %rdi
leaq 0x1a5550(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x380(%rbp)
jmp 0x56d6c
leaq -0x270(%rbp), %rdi
callq 0x59a90
movq -0x380(%rbp), %rdi
movl 0x18(%rax), %esi
callq 0x58d0
movq %rax, -0x388(%rbp)
jmp 0x56d90
movq -0x388(%rbp), %rdi
leaq 0x1a5510(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x390(%rbp)
jmp 0x56dac
leaq -0x270(%rbp), %rdi
callq 0x59a90
movq -0x390(%rbp), %rdi
movsd 0x20(%rax), %xmm0
callq 0x5980
movq %rax, -0x398(%rbp)
jmp 0x56dd2
movq -0x398(%rbp), %rdi
leaq 0x1a2845(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x56de7
jmp 0x56de9
leaq -0x270(%rbp), %rdi
xorl %esi, %esi
callq 0x59ab0
movq %rax, -0x280(%rbp)
jmp 0x56bd1
jmp 0x56e05
leaq -0x230(%rbp), %rdi
callq 0x50a0
jmp 0x56e13
movb $0x1, -0x1(%rbp)
movl $0x1, -0x240(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x5150
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x3a0, %rsp            # imm = 0x3A0
popq %rbp
retq
movq -0x238(%rbp), %rdi
callq 0x58f0
nopw (%rax,%rax)