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

    // Write information about the unit cell
    output << "\t\t\t\t" << cell->a << "  " << cell->b << "  " << cell->c << "\n";
    output << "\t\t" << cell->alpha<<"  "<< cell->beta <<"  " << cell->gamma <<"  SPGR =  1 P 1\t\t OPT = 1" << "\n";
    output << cell->numAtoms << "   0 " << "\n";
    output << "0 " << cell->name << "\t" << ": " << cell->name << "\n";
    output.setf(ios::fixed, ios::floatfield);
    int i;
    ATOM atm;

    // Write information about each atom
    for(i = 0; i<cell->numAtoms; i++){
      atm = cell->atoms.at(i);
      output << " " << i+1 << " " << cell->atoms.at(i).type << " " << atm.a_coord << " "
	     << atm.b_coord << " " << atm.c_coord << "  0  0  0  0  0  0  0  0  " << atm.charge <<  "\n";
    }
    output.close();
    return true;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x420, %rsp            # imm = 0x420
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x228(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0x5660
movq -0x2e0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x10, %edx
callq 0x54b0
jmp 0x5442d
leaq -0x228(%rbp), %rdi
callq 0x58b0
movb %al, -0x2e1(%rbp)
jmp 0x54441
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x544c1
jmp 0x5444d
movq 0x21eb9c(%rip), %rdi    # 0x272ff0
leaq 0x19f11f(%rip), %rsi    # 0x1f357a
callq 0x5540
movq %rax, -0x2f0(%rbp)
jmp 0x54469
movq -0x2f0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x2f8(%rbp)
jmp 0x54482
movq -0x2f8(%rbp), %rdi
movq 0x21eb08(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x54497
movb $0x0, -0x1(%rbp)
movl $0x1, -0x238(%rbp)
jmp 0x54a19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x54a33
movq 0x21eaf8(%rip), %rdi    # 0x272fc0
leaq 0x19f0d4(%rip), %rsi    # 0x1f35a3
callq 0x5540
movq %rax, -0x300(%rbp)
jmp 0x544dd
movq -0x300(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x308(%rbp)
jmp 0x544f6
movq -0x308(%rbp), %rdi
leaq 0x1a5121(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x5450b
leaq -0x218(%rbp), %rdi
leaq 0x19f0af(%rip), %rsi    # 0x1f35c8
callq 0x5540
movq %rax, -0x310(%rbp)
jmp 0x54527
movq -0x310(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x8(%rax), %xmm0
callq 0x5980
movq %rax, -0x318(%rbp)
jmp 0x54545
movq -0x318(%rbp), %rdi
leaq 0x19df35(%rip), %rsi    # 0x1f2488
callq 0x5540
movq %rax, -0x320(%rbp)
jmp 0x54561
movq -0x320(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x10(%rax), %xmm0
callq 0x5980
movq %rax, -0x328(%rbp)
jmp 0x5457f
movq -0x328(%rbp), %rdi
leaq 0x19defb(%rip), %rsi    # 0x1f2488
callq 0x5540
movq %rax, -0x330(%rbp)
jmp 0x5459b
movq -0x330(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x18(%rax), %xmm0
callq 0x5980
movq %rax, -0x338(%rbp)
jmp 0x545b9
movq -0x338(%rbp), %rdi
leaq 0x1a505e(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x545ce
leaq -0x218(%rbp), %rdi
leaq 0x19efee(%rip), %rsi    # 0x1f35ca
callq 0x5540
movq %rax, -0x340(%rbp)
jmp 0x545ea
movq -0x340(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x20(%rax), %xmm0
callq 0x5980
movq %rax, -0x348(%rbp)
jmp 0x54608
movq -0x348(%rbp), %rdi
leaq 0x19de72(%rip), %rsi    # 0x1f2488
callq 0x5540
movq %rax, -0x350(%rbp)
jmp 0x54624
movq -0x350(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x28(%rax), %xmm0
callq 0x5980
movq %rax, -0x358(%rbp)
jmp 0x54642
movq -0x358(%rbp), %rdi
leaq 0x19de38(%rip), %rsi    # 0x1f2488
callq 0x5540
movq %rax, -0x360(%rbp)
jmp 0x5465e
movq -0x360(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x30(%rax), %xmm0
callq 0x5980
movq %rax, -0x368(%rbp)
jmp 0x5467c
movq -0x368(%rbp), %rdi
leaq 0x19ef43(%rip), %rsi    # 0x1f35cd
callq 0x5540
movq %rax, -0x370(%rbp)
jmp 0x54698
movq -0x370(%rbp), %rdi
leaq 0x1a4f7f(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x546ad
leaq -0x218(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x110(%rax), %esi
callq 0x58d0
movq %rax, -0x378(%rbp)
jmp 0x546cc
movq -0x378(%rbp), %rdi
leaq 0x19ef0d(%rip), %rsi    # 0x1f35e7
callq 0x5540
movq %rax, -0x380(%rbp)
jmp 0x546e8
movq -0x380(%rbp), %rdi
leaq 0x1a4f2f(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x546fd
leaq -0x218(%rbp), %rdi
leaq 0x19eedf(%rip), %rsi    # 0x1f35ea
callq 0x5540
movq %rax, -0x388(%rbp)
jmp 0x54719
movq -0x388(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x320, %rsi            # imm = 0x320
callq 0x5480
movq %rax, -0x390(%rbp)
jmp 0x54739
movq -0x390(%rbp), %rdi
leaq 0x19ee84(%rip), %rsi    # 0x1f35cb
callq 0x5540
movq %rax, -0x398(%rbp)
jmp 0x54755
movq -0x398(%rbp), %rdi
leaq 0x1a30ce(%rip), %rsi    # 0x1f7831
callq 0x5540
movq %rax, -0x3a0(%rbp)
jmp 0x54771
movq -0x3a0(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x320, %rsi            # imm = 0x320
callq 0x5480
movq %rax, -0x3a8(%rbp)
jmp 0x54791
movq -0x3a8(%rbp), %rdi
leaq 0x1a4e86(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x547a6
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
movl $0x4, %esi
movl $0x104, %edx            # imm = 0x104
callq 0xf8d0
jmp 0x547ca
leaq -0x2d8(%rbp), %rdi
callq 0x954b0
jmp 0x547d8
movl $0x0, -0x23c(%rbp)
movl -0x23c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x110(%rcx), %eax
jge 0x549f1
movq -0x18(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x23c(%rbp), %rsi
callq 0xf090
movq %rax, -0x3b0(%rbp)
jmp 0x54818
movq -0x3b0(%rbp), %rsi
leaq -0x2d8(%rbp), %rdi
callq 0x595e0
jmp 0x5482d
leaq -0x218(%rbp), %rdi
leaq 0x1a7a73(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x3b8(%rbp)
jmp 0x54849
movq -0x3b8(%rbp), %rdi
movl -0x23c(%rbp), %esi
incl %esi
callq 0x58d0
movq %rax, -0x3c0(%rbp)
jmp 0x54866
movq -0x3c0(%rbp), %rdi
leaq 0x1a7a3a(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x3c8(%rbp)
jmp 0x54882
movq -0x18(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
movslq -0x23c(%rbp), %rsi
callq 0xf090
movq %rax, -0x3d0(%rbp)
jmp 0x548a2
movq -0x3c8(%rbp), %rdi
movq -0x3d0(%rbp), %rsi
addq $0x40, %rsi
callq 0x5480
movq %rax, -0x3d8(%rbp)
jmp 0x548c2
movq -0x3d8(%rbp), %rdi
leaq 0x1a79de(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x3e0(%rbp)
jmp 0x548de
movq -0x3e0(%rbp), %rdi
movsd -0x2c0(%rbp), %xmm0
callq 0x5980
movq %rax, -0x3e8(%rbp)
jmp 0x548fb
movq -0x3e8(%rbp), %rdi
leaq 0x1a79a5(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x3f0(%rbp)
jmp 0x54917
movq -0x3f0(%rbp), %rdi
movsd -0x2b8(%rbp), %xmm0
callq 0x5980
movq %rax, -0x3f8(%rbp)
jmp 0x54934
movq -0x3f8(%rbp), %rdi
leaq 0x1a796c(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x400(%rbp)
jmp 0x54950
movq -0x400(%rbp), %rdi
movsd -0x2b0(%rbp), %xmm0
callq 0x5980
movq %rax, -0x408(%rbp)
jmp 0x5496d
movq -0x408(%rbp), %rdi
leaq 0x19ec72(%rip), %rsi    # 0x1f35ed
callq 0x5540
movq %rax, -0x410(%rbp)
jmp 0x54989
movq -0x410(%rbp), %rdi
movsd -0x250(%rbp), %xmm0
callq 0x5980
movq %rax, -0x418(%rbp)
jmp 0x549a6
movq -0x418(%rbp), %rdi
leaq 0x1a4c71(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x549bb
jmp 0x549bd
movl -0x23c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x23c(%rbp)
jmp 0x547e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0xf200
jmp 0x54a33
leaq -0x228(%rbp), %rdi
callq 0x50a0
jmp 0x549ff
movb $0x1, -0x1(%rbp)
movl $0x1, -0x238(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0xf200
leaq -0x228(%rbp), %rdi
callq 0x5150
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x420, %rsp            # imm = 0x420
popq %rbp
retq
leaq -0x228(%rbp), %rdi
callq 0x5150
movq -0x230(%rbp), %rdi
callq 0x58f0
nopl (%rax,%rax)