// File: Luthaf[P]zeopp/networkio.cc
// Function: writeToVTK(char*, ATOM_NETWORK*)
bool writeToVTK(char *filename, ATOM_NETWORK *cell){
  fstream output;
  output.open(filename, fstream::out);
  if(!output.is_open()){
    cerr << "Error: Failed to open .vtk output file " << filename << endl;
    //cerr << "Exiting ..." << "\n";
    //exit(1);
    return false;
  }
  else{
    cout << "Writing unit cell information to " << filename << "\n";

    //For each corner in abc, get the coords in xyz
    vector<Point> corners; Point p;
    p = cell->abc_to_xyz(0, 0, 0); corners.push_back(p);
    p = cell->abc_to_xyz(0, 0, 1); corners.push_back(p);
    p = cell->abc_to_xyz(0, 1, 0); corners.push_back(p);
    p = cell->abc_to_xyz(0, 1, 1); corners.push_back(p);
    p = cell->abc_to_xyz(1, 0, 0); corners.push_back(p);
    p = cell->abc_to_xyz(1, 0, 1); corners.push_back(p);
    p = cell->abc_to_xyz(1, 1, 0); corners.push_back(p);
    p = cell->abc_to_xyz(1, 1, 1); corners.push_back(p);
    // Write header, information about the cell, and footer
    output << "# vtk DataFile Version 2.0\nvtk format representation of unit cell boundary\nASCII\nDATASET POLYDATA\nPOINTS 8 double\n";
    for(int i=0; i<8; i++) output << corners.at(i)[0] << " " << corners.at(i)[1] << " " << corners.at(i)[2] << "\n";
    output << "LINES 12 36\n2 0 1\n2 0 2\n2 1 3\n2 2 3\n2 4 5\n2 4 6\n2 5 7\n2 6 7\n2 0 4\n2 1 5\n2 2 6\n2 3 7\n";
  }
  output.close();
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3d0, %rsp            # imm = 0x3D0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x228(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x5660
movq -0x340(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x10, %edx
callq 0x54b0
jmp 0x5836d
leaq -0x228(%rbp), %rdi
callq 0x58b0
movb %al, -0x341(%rbp)
jmp 0x58381
movb -0x341(%rbp), %al
testb $0x1, %al
jne 0x58401
jmp 0x5838d
movq 0x21ac5c(%rip), %rdi    # 0x272ff0
leaq 0x19b553(%rip), %rsi    # 0x1f38ee
callq 0x5540
movq %rax, -0x350(%rbp)
jmp 0x583a9
movq -0x350(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x358(%rbp)
jmp 0x583c2
movq -0x358(%rbp), %rdi
movq 0x21abc8(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x583d7
movb $0x0, -0x1(%rbp)
movl $0x1, -0x238(%rbp)
jmp 0x588ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x58904
movq 0x21abb8(%rip), %rdi    # 0x272fc0
leaq 0x19b507(%rip), %rsi    # 0x1f3916
callq 0x5540
movq %rax, -0x360(%rbp)
jmp 0x5841d
movq -0x360(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x368(%rbp)
jmp 0x58436
movq -0x368(%rbp), %rdi
leaq 0x1a11e1(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x5844b
leaq -0x250(%rbp), %rdi
callq 0xed40
leaq -0x270(%rbp), %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xe9c70
jmp 0x5846e
movq -0x18(%rbp), %rsi
leaq -0x288(%rbp), %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x97170
jmp 0x58489
movq -0x278(%rbp), %rax
movq %rax, -0x260(%rbp)
movups -0x288(%rbp), %xmm0
movaps %xmm0, -0x270(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x59bf0
jmp 0x584ba
movq -0x18(%rbp), %rsi
leaq -0x2a0(%rbp), %rdi
xorps %xmm1, %xmm1
movsd 0x199b80(%rip), %xmm2   # 0x1f2050
movaps %xmm1, %xmm0
callq 0x97170
jmp 0x584da
movq -0x290(%rbp), %rax
movq %rax, -0x260(%rbp)
movups -0x2a0(%rbp), %xmm0
movaps %xmm0, -0x270(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x59bf0
jmp 0x5850b
movq -0x18(%rbp), %rsi
leaq -0x2b8(%rbp), %rdi
movsd 0x199b32(%rip), %xmm1   # 0x1f2050
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
callq 0x97170
jmp 0x5852b
movq -0x2a8(%rbp), %rax
movq %rax, -0x260(%rbp)
movups -0x2b8(%rbp), %xmm0
movaps %xmm0, -0x270(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x59bf0
jmp 0x5855c
movq -0x18(%rbp), %rsi
leaq -0x2d0(%rbp), %rdi
xorps %xmm0, %xmm0
movsd 0x199ade(%rip), %xmm2   # 0x1f2050
movaps %xmm2, %xmm1
callq 0x97170
jmp 0x5857c
movq -0x2c0(%rbp), %rax
movq %rax, -0x260(%rbp)
movups -0x2d0(%rbp), %xmm0
movaps %xmm0, -0x270(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x59bf0
jmp 0x585ad
movq -0x18(%rbp), %rsi
leaq -0x2e8(%rbp), %rdi
movsd 0x199a90(%rip), %xmm0   # 0x1f2050
xorps %xmm2, %xmm2
movaps %xmm2, %xmm1
callq 0x97170
jmp 0x585cd
movq -0x2d8(%rbp), %rax
movq %rax, -0x260(%rbp)
movups -0x2e8(%rbp), %xmm0
movaps %xmm0, -0x270(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x59bf0
jmp 0x585fe
movq -0x18(%rbp), %rsi
leaq -0x300(%rbp), %rdi
xorps %xmm1, %xmm1
movsd 0x199a3c(%rip), %xmm2   # 0x1f2050
movaps %xmm2, %xmm0
callq 0x97170
jmp 0x5861e
movq -0x2f0(%rbp), %rax
movq %rax, -0x260(%rbp)
movups -0x300(%rbp), %xmm0
movaps %xmm0, -0x270(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x59bf0
jmp 0x5864f
movq -0x18(%rbp), %rsi
leaq -0x318(%rbp), %rdi
movsd 0x1999ee(%rip), %xmm1   # 0x1f2050
xorps %xmm2, %xmm2
movaps %xmm1, %xmm0
callq 0x97170
jmp 0x5866f
movq -0x308(%rbp), %rax
movq %rax, -0x260(%rbp)
movups -0x318(%rbp), %xmm0
movaps %xmm0, -0x270(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x59bf0
jmp 0x586a0
movq -0x18(%rbp), %rsi
leaq -0x330(%rbp), %rdi
movsd 0x19999d(%rip), %xmm2   # 0x1f2050
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x97170
jmp 0x586c0
movq -0x320(%rbp), %rax
movq %rax, -0x260(%rbp)
movups -0x330(%rbp), %xmm0
movaps %xmm0, -0x270(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x59bf0
jmp 0x586f1
leaq -0x218(%rbp), %rdi
leaq 0x19b239(%rip), %rsi    # 0x1f3938
callq 0x5540
jmp 0x58706
movl $0x0, -0x334(%rbp)
cmpl $0x8, -0x334(%rbp)
jge 0x588ad
leaq -0x218(%rbp), %rax
movq %rax, -0x378(%rbp)
movslq -0x334(%rbp), %rsi
leaq -0x250(%rbp), %rdi
callq 0x59c60
movq %rax, -0x370(%rbp)
jmp 0x58747
movq -0x370(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq %rax, -0x380(%rbp)
jmp 0x5875e
movq -0x378(%rbp), %rdi
movq -0x380(%rbp), %rax
movsd (%rax), %xmm0
callq 0x5980
movq %rax, -0x388(%rbp)
jmp 0x5877e
movq -0x388(%rbp), %rdi
leaq 0x1a3b22(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x390(%rbp)
jmp 0x5879a
movslq -0x334(%rbp), %rsi
leaq -0x250(%rbp), %rdi
callq 0x59c60
movq %rax, -0x398(%rbp)
jmp 0x587b6
movq -0x398(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq %rax, -0x3a0(%rbp)
jmp 0x587d0
movq -0x390(%rbp), %rdi
movq -0x3a0(%rbp), %rax
movsd (%rax), %xmm0
callq 0x5980
movq %rax, -0x3a8(%rbp)
jmp 0x587f0
movq -0x3a8(%rbp), %rdi
leaq 0x1a3ab0(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x3b0(%rbp)
jmp 0x5880c
movslq -0x334(%rbp), %rsi
leaq -0x250(%rbp), %rdi
callq 0x59c60
movq %rax, -0x3b8(%rbp)
jmp 0x58828
movq -0x3b8(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq %rax, -0x3c0(%rbp)
jmp 0x58842
movq -0x3b0(%rbp), %rdi
movq -0x3c0(%rbp), %rax
movsd (%rax), %xmm0
callq 0x5980
movq %rax, -0x3c8(%rbp)
jmp 0x58862
movq -0x3c8(%rbp), %rdi
leaq 0x1a0db5(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x58877
jmp 0x58879
movl -0x334(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x334(%rbp)
jmp 0x58710
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x250(%rbp), %rdi
callq 0xefe0
jmp 0x58904
leaq -0x218(%rbp), %rdi
leaq 0x19b0f0(%rip), %rsi    # 0x1f39ab
callq 0x5540
jmp 0x588c2
leaq -0x250(%rbp), %rdi
callq 0xefe0
leaq -0x228(%rbp), %rdi
callq 0x50a0
jmp 0x588dc
movb $0x1, -0x1(%rbp)
movl $0x1, -0x238(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x5150
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x3d0, %rsp            # imm = 0x3D0
popq %rbp
retq
leaq -0x228(%rbp), %rdi
callq 0x5150
movq -0x230(%rbp), %rdi
callq 0x58f0
nopl (%rax)